Rewrite the instance-poking presentational tests with React Testing Library#315
Rewrite the instance-poking presentational tests with React Testing Library#315jonathangreen wants to merge 1 commit into
Conversation
|
Claude finished @jonathangreen's task in 3m 58s —— View job Claude Code Review
SummaryThis is a careful, high-quality tranche of the enzyme→RTL migration. The hard part — re-expressing each DetailsMinor:
|
Greptile SummaryThis PR rewrites legacy Enzyme component tests as React Testing Library tests. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (6): Last reviewed commit: "Rewrite the instance-poking presentation..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #315 +/- ##
==========================================
+ Coverage 90.19% 90.47% +0.27%
==========================================
Files 205 205
Lines 7610 7610
Branches 1664 1664
==========================================
+ Hits 6864 6885 +21
+ Misses 437 423 -14
+ Partials 309 302 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
314c5da to
2e7091e
Compare
2e7091e to
1bb0927
Compare
d45ae2c to
3739c04
Compare
1bb0927 to
618357e
Compare
## Description Adds one shared FormData test shim at `tests/jest/testUtils/formDataShim.ts`, plus its spec test. The unit jsdom environment installs undici's `FormData`, which throws on `new FormData(formElement)`. The reusable-components `Form` builds FormData that way on submit, so any test that asserts a submitted payload needs a stand-in. Previously each migration branch carried its own inline copy; this consolidates them into one. The shim mirrors the browser's `new FormData(form)` **successful-controls** rules: - named, non-disabled controls only; - checkboxes/radios contribute only when checked; - submit/reset/button/image/file inputs excluded; - every selected option of a `<select multiple>` included. It also exposes the standard read/write/iterate surface (`get`/`getAll`/`has`/`append`/`set`/`delete`/`forEach`/`keys`/`values`/`entries`/iterator). `installFormDataShim()` swaps it in around a suite (`beforeAll`) and restores the real `FormData` afterward (`afterAll`). `formDataShim.test.ts` (8 cases) pins the successful-controls behavior — disabled omitted, checkbox only when checked, radio group, submit excluded, multi-select expansion, and the read/write API — so the fidelity can't silently regress. ## Motivation and Context Part of the mocha/chai/enzyme → jest/RTL migration. Extracting the shim into its own small, self-tested base PR lets #314, #315, and #316 depend on one implementation via `installFormDataShim()` instead of duplicating (and independently drifting) a local shim in each — while keeping this base stable so those stacked PRs don't churn. ## How Has This Been Tested? `npx jest --selectProjects=unit --testPathPattern formDataShim` — 8/8 green. ## Checklist: - [x] I have updated the documentation accordingly. - [x] All new and existing tests passed.
…ibrary 22 more enzyme suites, the ones that reached into class internals with instance()/setState()/state(): the announcement/color/table widgets, the complaint and troubleshooting views, the library/book/list edit forms, the diagnostics and reset-adobe panels, and ContextProvider. Each internal poke becomes an observable assertion. instance() reads of computed values (Announcement.format, ClassificationsTable.readableType, ContextProvider methods) are driven through the real inputs and asserted on the rendered DOM. setState()/instance()-method calls become the user action that causes them — a checkbox click, a Save click, a tab click — and the assertion moves to the DOM that reflects the new state. Ref-based getValue() APIs (Autocomplete, ColorPicker) are exercised through a real ref, since production calls them that way. ContextProvider is rewritten around a capturing consumer child that reads the legacy context the component provides, rather than the component instance — pathFor/prepareCollectionUrl/prepareBookUrl are tested through that context, and the legacy `global.jsdom.reconfigure` origin trick (no equivalent in the unit env) is dropped: those helpers strip only the origin, so the real jsdom origin yields the same encoded output. Connected panels (Complaints, PatronAuthServices, SitewideAnnouncements, Classifications, BookDetailsEditor, CustomListsForBook, ResetAdobeId, SelfTestsTabContainer's category) render their connected default export with fetch stubbed and awaited, so mapStateToProps/mapDispatchToProps stay covered — the wave-2 lesson, applied up front. The gate still caught two gaps: a Complaints type-format fallback (added a non-matching-type case) and SelfTests's own connect wiring, which only the SelfTestsTabContainer full-mount covered — so SelfTestsTabContainer is deferred (original retained) until SelfTests is migrated connected in the final wave. Coverage rises to 94.68% (+38 lines over baseline), no previously-covered line lost. 36 legacy suites remain: the HARD-heavy set, the ten that must merge into existing tests/jest files, and the three deferred containers.
618357e to
ec398ca
Compare
Description
Rewrites 22 enzyme suites that reached into class internals with
instance()/setState()/state(): the announcement/color/table widgets, the complaint and troubleshooting views, the library/book/list edit forms, the diagnostics and reset-adobe panels, andContextProvider.Each internal poke becomes an observable assertion:
instance()reads of computed values (Announcement.format,ClassificationsTable.readableType,ContextProvidermethods) are driven through real inputs and asserted on the rendered DOM.setState()/instance-method calls become the user action that causes them — a checkbox click, a Save click, a tab click — with the assertion on the DOM that reflects the new state.getValue()APIs (Autocomplete,ColorPicker) are exercised through a real ref, since production calls them that way.ContextProvideris rewritten around a capturing consumer child that reads the legacy context the component provides (pathFor/prepareCollectionUrl/prepareBookUrl), rather than the component instance. The legacyglobal.jsdom.reconfigureorigin trick is dropped — those helpers strip only the origin, so the real jsdom origin yields the same encoded output.Connected panels (
Complaints,PatronAuthServices,SitewideAnnouncements,Classifications,BookDetailsEditor,CustomListsForBook,ResetAdobeId,SelfTests's category) render their connected default export with fetch stubbed and awaited, somapStateToProps/mapDispatchToPropsstay covered. The coverage gate caught two gaps: aComplaintstype-format fallback (added a non-matching-type case) andSelfTests's own connect wiring, which only theSelfTestsTabContainerfull-mount covered — soSelfTestsTabContaineris deferred (original retained) untilSelfTestsis migrated to render its connected export.userEventusage follows theconst user = userEvent.setup()convention acrosstests/jest/.Motivation and Context
Part of the mocha/chai/enzyme → jest/RTL migration. This tranche clears the suites that poked class internals — the ones whose translation is least mechanical, since each
instance()/setState()has to be re-expressed as a user action and a DOM assertion.How Has This Been Tested?
npm test— full suite green. Coverage rises to 94.68% (+38 lines over baseline), no previously-covered line lost.Checklist: