Skip to content

[tests]: verify independent subview sub-record changes propagate needsSaved and persist#8255

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

[tests]: verify independent subview sub-record changes propagate needsSaved and persist#8255
rijulpoudel wants to merge 3 commits into
mainfrom
issue-8250

Conversation

@rijulpoudel

@rijulpoudel rijulpoudel commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8250

Summary by CodeRabbit

  • Tests
    • Added coverage for change propagation in parent/child record views.
    • Verified that editing related items marks the parent as needing save and that saving clears the pending state.
    • Confirmed that changes to nested related records are preserved after saving.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Two new test suites were added to resourceApi.test.ts to verify that changes to independent collection sub-records (additions, direct edits, and dependent sub-record edits) propagate needsSaved to the parent resource, and that saving persists in-memory changes while clearing the flag.

Changes

Independent resource save propagation tests

Layer / File(s) Summary
Propagation and persistence tests
specifyweb/frontend/js_src/lib/components/DataModel/__tests__/resourceApi.test.ts
Adds AJAX mocks, a helper creating a parent Accession connected to an IndependentCollection, and tests confirming needsSaved propagates from independent additions and edits, clears on save(), and modified values persist in memory.

Possibly related issues

🚥 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 matches the test-focused change about independent subview changes propagating needsSaved and persisting after save.
Linked Issues check ✅ Passed The added tests address issue #8250 by verifying needsSaved propagation and persistence after saving an independent resource sub-record.
Out of Scope Changes check ✅ Passed The PR appears limited to tests in the targeted file and stays within the linked issue's scope.
Automatic Tests ✅ Passed Yes—PR adds automated Jest tests for independent collection change propagation and save behavior in resourceApi.test.ts.
Testing Instructions ✅ Passed The new tests clearly target resourceApi independent-collection saving and cover the affected Accession, CollectionObject, and Determination paths.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-8250

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.

@rijulpoudel rijulpoudel requested a review from CarolineDenis July 3, 2026 18:56

@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 (1)
specifyweb/frontend/js_src/lib/components/DataModel/__tests__/resourceApi.test.ts (1)

480-499: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate setup logic between the first test and the setupParentWithIndependentCollection helper.

The inline setup in the first test (parentResource creation, relationship lookup, IndependentCollection construction, fetch, and storeIndependent wiring) is nearly identical to setupParentWithIndependentCollection defined later. Consider lifting this helper to module/file scope and reusing it across all three tests to avoid drift if the wiring logic changes.

♻️ Suggested consolidation
+async function setupParentWithIndependentCollection() {
+  const parentResource = new tables.Accession.Resource({ id: accessionId });
+  const collectionObjectRel =
+    tables.CollectionObject.strictGetRelationship('accession')!;
+  const independentCollection =
+    new tables.CollectionObject.IndependentCollection({
+      related: parentResource,
+      field: collectionObjectRel,
+    }) as Collection<CollectionObject>;
+  await independentCollection.fetch();
+  (parentResource as any).storeIndependent(
+    collectionObjectRel.getReverse(),
+    independentCollection
+  );
+  return { parentResource, independentCollection };
+}
+
 describe('independent resource change propagation', () => {
   ...
   test('needsSaved propagates from independent collection to parent', async () => {
-    const parentResource = new tables.Accession.Resource({ id: accessionId });
+    const { parentResource, independentCollection } =
+      await setupParentWithIndependentCollection();
     expect(parentResource.needsSaved).toBe(false);
-    ...
-    const newCollectionObject = new tables.CollectionObject.Resource({ id: 998 });
+    const newCollectionObject = new tables.CollectionObject.Resource({ id: 998 });
     independentCollection.add(newCollectionObject);

Also applies to: 527-543

🤖 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/DataModel/__tests__/resourceApi.test.ts`
around lines 480 - 499, The first test repeats the same
parent/independent-collection wiring that is already encapsulated in
setupParentWithIndependentCollection, so consolidate this duplicated setup into
the shared helper instead of inlining it in the test. Move or reuse the helper
at module scope, and have the tests call it for parentResource creation,
relationship lookup, IndependentCollection construction/fetch, and
storeIndependent wiring so all three tests share the same setup path and stay in
sync.
🤖 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/DataModel/__tests__/resourceApi.test.ts`:
- Around line 480-499: The first test repeats the same
parent/independent-collection wiring that is already encapsulated in
setupParentWithIndependentCollection, so consolidate this duplicated setup into
the shared helper instead of inlining it in the test. Move or reuse the helper
at module scope, and have the tests call it for parentResource creation,
relationship lookup, IndependentCollection construction/fetch, and
storeIndependent wiring so all three tests share the same setup path and stay in
sync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 76481cc9-d980-45cc-b2c5-585b5178570c

📥 Commits

Reviewing files that changed from the base of the PR and between f3d4fec and a6e4744.

📒 Files selected for processing (1)
  • specifyweb/frontend/js_src/lib/components/DataModel/__tests__/resourceApi.test.ts

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.

[tests]: verify sub-record of independent resource propagates needsSaved and persists after save

1 participant