Repository navigation
test and refactor current push/pull button behaviour - #7042
Conversation
08dfc61 to
96444b2
Compare
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
0a722f3 to
68ae4ae
Compare
1ca467f to
577cfef
Compare
|
I've archived the tests I used in here over in this branch as a reference to complement the notes below about my component testing adventures. What did I do?This PR was a chance to explore testing React components while I refactor a component, because this scenario felt like a good fit for it, rather than other scenarios that I've been contemplating. Why this area?This component felt like a good fit for testing for a few reasons:
What worked?It was helpful to use these tests as a regression suite while I was refactoring. What I did was build up a number of cases that I knew the component needed to support, and run these tests to store a snapshot of the rendered DOM: desktop/app/test/component/push-pull-button-test.tsx Lines 139 to 149 in 5b5fe30 This was a bit exploratory, and required looking over the internals to understand what it was looking for, because of the large number of props this component supports. I think unifying this logic outside of the component, and returning a union type prop of the possible states, would be the next iteration on the API here. Once I had this set of tests, I could contemplate changes to the code. When I was originally refactoring this component I went through this sort of repetitive process:
Chipping away at the code eventually got me to what is currently in this PR - having one place where the conditions are checked and each scenario becomes a standalone function. What didn't work?I wouldn't recommend this approach for other situations:
I also had a shot at enabling code coverage for these "component tests" but it clashed with the unit test coverage and made CodeCov submit disappointed comments into this draft PR about my coverage failing. If we want to go down this path, we'd need to better organize the unit tests to appease Codecov. Would I do it again?Yes. The other case I've been exploring is how we can verify React components that currently use APIs which will be removed in the next major version of React, to ensure we can effectively migrate to the new APIs without breaking functionality. |
577cfef to
ba0f86c
Compare
ba0f86c to
1e099c5
Compare
Overview
Closes #6985
Description
yarn teststepPushPullButtonto cover majority of output casesPushPullButton.renderto be more maintainable--force-with-leaseafter rebasing #6981 once mergedNotes
Diff details aside, the size of the component in the production bundle increased 18% (from 3048 characters to 3615 characters, so still less than 4KB) for the component, which is mostly because we no longer have a central
React.createElementinsiderender().You can see the human-readable before-vs-after (with whitespace and indenting) output in this gist: https://gist.github.com/shiftkey/a3b4ddb7c7e3537e28127279cd5969c7
Release notes
Notes: no-notes