Skip to content

Add regression test for #49 (remove mutator after move)#107

Open
erikras-richard-agent wants to merge 1 commit intofinal-form:masterfrom
erikras-richard-agent:test-regression-49
Open

Add regression test for #49 (remove mutator after move)#107
erikras-richard-agent wants to merge 1 commit intofinal-form:masterfrom
erikras-richard-agent:test-regression-49

Conversation

@erikras-richard-agent
Copy link
Copy Markdown
Contributor

@erikras-richard-agent erikras-richard-agent commented Mar 21, 2026

Adds regression test coverage for issue #49 where the remove mutator would remove the wrong field from the screen after items were reordered with the move mutator.

The bug was fixed in commit f69ab19 (Nov 2020) by using copyField which clears lastFieldState to force React component re-renders.

This test ensures the fix continues to work by:

  1. Creating two customers [0, 1]
  2. Moving them to [1, 0]
  3. Removing index 1 (original item 0)
  4. Verifying the correct item was removed and field state is correct

Summary by CodeRabbit

  • Tests
    • Added regression test to validate the correct behavior of move and remove operations on array fields in form state.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 21, 2026

📝 Walkthrough

Walkthrough

A new regression test file validates the interaction between move and remove operations on arrays in final-form-arrays. The test verifies that array reordering followed by element removal correctly updates both array values and field state entries, including cleanup of all nested field references.

Changes

Cohort / File(s) Summary
Regression Test for Move/Remove Interaction
src/remove.move-bug-49.test.ts
New Jest test that validates correct field state management when move is called on an array followed by remove, ensuring array contents, field entries, and nested field references are properly updated and cleaned.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • erikras

Poem

🐰 A test hops in to check the way,
That move and remove dance and play!
Fields swap and shrink with careful care,
Array entries vanish in thin air. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: adding a regression test for issue #49 related to the remove mutator after move operations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/remove.move-bug-49.test.ts`:
- Around line 61-65: The test currently only checks existence for nested fields
'customers[0].id' and 'customers[0].name' which can hide stale values; update
the assertions for state.fields['customers[0].id'] and
state.fields['customers[0].name'] to assert their .value equals the expected
primitives (e.g., 2 for id and 'Customer `#2`' for name) instead of using
toBeDefined(), keeping the existing check for state.fields['customers[0]'].value
object as-is to ensure both the composite and nested field values are validated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 331a17d6-ed05-4af0-b3ce-a7b9c05477ce

📥 Commits

Reviewing files that changed from the base of the PR and between ed07005 and 033620a.

📒 Files selected for processing (1)
  • src/remove.move-bug-49.test.ts

Comment on lines +61 to +65
// Field state should reflect the remaining customer at index 0
expect(state.fields['customers[0]']).toBeDefined()
expect(state.fields['customers[0]'].value).toEqual({ id: 2, name: 'Customer #2' })
expect(state.fields['customers[0].id']).toBeDefined()
expect(state.fields['customers[0].name']).toBeDefined()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Assert nested surviving field values, not just existence.

At Line 64 and Line 65, toBeDefined() can still pass with stale nested values. Add value assertions to harden the regression test.

Suggested test-strengthening diff
     expect(state.fields['customers[0].id']).toBeDefined()
     expect(state.fields['customers[0].name']).toBeDefined()
+    expect(state.fields['customers[0].id'].value).toBe(2)
+    expect(state.fields['customers[0].name'].value).toBe('Customer `#2`')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Field state should reflect the remaining customer at index 0
expect(state.fields['customers[0]']).toBeDefined()
expect(state.fields['customers[0]'].value).toEqual({ id: 2, name: 'Customer #2' })
expect(state.fields['customers[0].id']).toBeDefined()
expect(state.fields['customers[0].name']).toBeDefined()
// Field state should reflect the remaining customer at index 0
expect(state.fields['customers[0]']).toBeDefined()
expect(state.fields['customers[0]'].value).toEqual({ id: 2, name: 'Customer `#2`' })
expect(state.fields['customers[0].id']).toBeDefined()
expect(state.fields['customers[0].name']).toBeDefined()
expect(state.fields['customers[0].id'].value).toBe(2)
expect(state.fields['customers[0].name'].value).toBe('Customer `#2`')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/remove.move-bug-49.test.ts` around lines 61 - 65, The test currently only
checks existence for nested fields 'customers[0].id' and 'customers[0].name'
which can hide stale values; update the assertions for
state.fields['customers[0].id'] and state.fields['customers[0].name'] to assert
their .value equals the expected primitives (e.g., 2 for id and 'Customer `#2`'
for name) instead of using toBeDefined(), keeping the existing check for
state.fields['customers[0]'].value object as-is to ensure both the composite and
nested field values are validated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant