Skip to content

[test]: Import multiple image file types into a WorkBench data set#8352

Open
rijulpoudel wants to merge 3 commits into
mainfrom
issue-8347
Open

[test]: Import multiple image file types into a WorkBench data set#8352
rijulpoudel wants to merge 3 commits into
mainfrom
issue-8347

Conversation

@rijulpoudel

@rijulpoudel rijulpoudel commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8347

Summary by CodeRabbit

  • Tests
    • Added automated coverage for importing multiple image attachments.
    • Verified support for mixed image file types and correct filename display.
    • Confirmed uploaded attachments trigger the expected requests and show a dataset-created confirmation.

@github-actions

Copy link
Copy Markdown

Warning

One or more dependencies are approaching or past End-of-Life.
Please plan upgrades accordingly.

STATUS=WARNING
NODE_VERSION=20
NODE_CYCLE=20
EOL_DATE=2026-04-30
DAYS_REMAINING=-85

--- Node.js ---
Version: 20
EOL: 2026-04-30
Status: WARNING

STATUS=OK
PYTHON_VERSION=3.12
PYTHON_CYCLE=3.12
EOL_DATE=2028-10-31
DAYS_REMAINING=830

--- Python ---
Version: 3.12
EOL: 2028-10-31
Status: OK

STATUS=WARNING
DJANGO_VERSION=4.2
DJANGO_CYCLE=4.2
EOL_DATE=2026-04-07
DAYS_REMAINING=-108

--- Django ---
Version: 4.2
EOL: 2026-04-07
Status: WARNING


@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

WorkBench attachment import tests

Layer / File(s) Summary
Test harness and import API mocks
specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx
Configures routing and mocks attachment uploads, dataset requests, attachment creation, and per-test state reset.
Selection rendering and import flows
specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx
Tests rendering for multiple image filenames and verifies upload, API calls, and completion navigation during import.
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: testing import of multiple image file types into a WorkBench data set.
Linked Issues check ✅ Passed The new test suite covers selecting multiple files, mixed image file types, and importing attachments as requested by #8347.
Out of Scope Changes check ✅ Passed The PR stays within scope by adding tests only and does not introduce unrelated code changes.
Automatic Tests ✅ Passed The PR adds a new Jest/RTL test file with three flows covering attachment import behavior and file selection.
Testing Instructions ✅ Passed The new tests clearly cover WbImportAttachmentsView flows: file selection/preview and the full import path through attachmentHelpers.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-8347

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx (2)

157-219: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider 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 mocks Attachments.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 win

Extract 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1669426 and a1e79de.

📒 Files selected for processing (1)
  • specifyweb/frontend/js_src/lib/components/WbImportAttachments/__tests__/WbImportAttachments.test.tsx

@rijulpoudel rijulpoudel added this to the 7.12.1 milestone Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋Back Log

Development

Successfully merging this pull request may close these issues.

[test]: Import multiple image file types into a WorkBench data set

1 participant