[tests]: verify independent subview sub-record changes propagate needsSaved and persist#8255
[tests]: verify independent subview sub-record changes propagate needsSaved and persist#8255rijulpoudel wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughTwo 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 ChangesIndependent resource save propagation tests
Possibly related issues
🚥 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 (1)
specifyweb/frontend/js_src/lib/components/DataModel/__tests__/resourceApi.test.ts (1)
480-499: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate setup logic between the first test and the
setupParentWithIndependentCollectionhelper.The inline setup in the first test (parentResource creation, relationship lookup,
IndependentCollectionconstruction, fetch, andstoreIndependentwiring) is nearly identical tosetupParentWithIndependentCollectiondefined 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
📒 Files selected for processing (1)
specifyweb/frontend/js_src/lib/components/DataModel/__tests__/resourceApi.test.ts
Fixes #8250
Summary by CodeRabbit