Skip to content

Test case for issue 19 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/move.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,64 @@ describe('move', () => {
})
})

it('should move fields with different shapes', () => {
// implementation of changeValue taken directly from Final Form
const changeValue = (state, name, mutate) => {
const before = getIn(state.formState.values, name)
const after = mutate(before)
state.formState.values = setIn(state.formState.values, name, after) || {}
}
const state = {
formState: {
values: {
foo: [{ dog: 'apple dog', cat: 'apple cat' }, { dog: 'banana dog' }]
}
},
fields: {
'foo[0].dog': {
name: 'foo[0].dog',
touched: true,
error: 'Error A Dog'
},
'foo[0].cat': {
name: 'foo[0].cat',
touched: false,
error: 'Error A Cat'
},
'foo[1].dog': {
name: 'foo[1].dog',
touched: true,
error: 'Error B Dog'
}
}
}
move(['foo', 0, 1], state, { changeValue })
expect(state).toEqual({
formState: {
values: {
foo: [{ dog: 'banana dog' }, { dog: 'apple dog', cat: 'apple cat' }]
}
},
fields: {
'foo[0].dog': {
name: 'foo[0].dog',
touched: true,
error: 'Error B Dog'
},
'foo[1].dog': {
name: 'foo[1].dog',
touched: true,
error: 'Error A Dog'
},
'foo[1].cat': {
name: 'foo[1].cat',
touched: false,
error: 'Error A Cat'
}
}
})
})

it('should preserve functions in field state', () => {
// implementation of changeValue taken directly from Final Form
const changeValue = (state, name, mutate) => {
Expand Down