[test]: Import multiple image file types into a WorkBench data set#8352
[test]: Import multiple image file types into a WorkBench data set#8352rijulpoudel wants to merge 3 commits into
Conversation
|
Warning One or more dependencies are approaching or past End-of-Life. |
📝 WalkthroughWalkthroughChangesWorkBench attachment import tests
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx (2)
157-219: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider a failure-path test for the import flow.
All three tests exercise the happy path only. Given
uploadFile/dataset creation are chained network calls, a test that mocksAttachments.uploadFile(or one of the ajax overrides) to reject and asserts the UI surfaces an error instead of silently navigating would strengthen coverage of this critical import flow.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx` around lines 157 - 219, Extend the WbImportAttachmentsView import-flow tests with a failure-path case by making Attachments.uploadFile or a dataset-request mock reject, then assert that the UI displays the error and does not navigate to the WorkBench data-set route. Keep the existing successful import assertions unchanged.
71-88: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract shared mount + file-input lookup into a helper.
The mount-with-router +
querySelector('input[type="file"]')+ null-check block is duplicated near-verbatim across all three tests. A small helper (e.g.renderWbImportAttachments()returning{ container, getByRole, findByText, user, input }) would cut this boilerplate and keep future edits (e.g. router setup changes) in one place.♻️ Sketch of a shared helper
+function renderWbImportAttachments({ withRoutes = false } = {}) { + const { container, getByRole, findByText, user } = mount( + <Router.MemoryRouter + initialEntries={['/']} + future={{ v7_relativeSplatPath: true, v7_startTransition: true }} + > + {withRoutes ? ( + <UnloadProtectsContext.Provider value={[]}> + <Router.Routes> + <Router.Route + path="/" + element={ + <SetMenuContext.Provider value={jest.fn()}> + <WbImportAttachmentsView /> + </SetMenuContext.Provider> + } + /> + <Router.Route + path="/specify/workbench/plan/:dataSetId/" + element={<div>WorkBench data set created</div>} + /> + </Router.Routes> + </UnloadProtectsContext.Provider> + ) : ( + <SetMenuContext.Provider value={jest.fn()}> + <WbImportAttachmentsView /> + </SetMenuContext.Provider> + )} + </Router.MemoryRouter> + ); + const input = container.querySelector<HTMLInputElement>('input[type="file"]'); + if (input === null) { + throw new Error('Unable to find the attachment file picker'); + } + return { container, getByRole, findByText, user, input }; +}Also applies to: 110-127, 162-193
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx` around lines 71 - 88, Extract the duplicated Router.MemoryRouter mount and file-input lookup from the three tests into a shared helper, such as renderWbImportAttachments. Have the helper provide the existing test utilities and validated input element, then update each test near WbImportAttachmentsView to use it while preserving their current assertions and behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx`:
- Around line 157-219: Extend the WbImportAttachmentsView import-flow tests with
a failure-path case by making Attachments.uploadFile or a dataset-request mock
reject, then assert that the UI displays the error and does not navigate to the
WorkBench data-set route. Keep the existing successful import assertions
unchanged.
- Around line 71-88: Extract the duplicated Router.MemoryRouter mount and
file-input lookup from the three tests into a shared helper, such as
renderWbImportAttachments. Have the helper provide the existing test utilities
and validated input element, then update each test near WbImportAttachmentsView
to use it while preserving their current assertions and behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 59d90721-e259-4208-ae66-847da29982b9
📒 Files selected for processing (1)
specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx
Fixes #8347
Summary by CodeRabbit