Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Commit

Permalink
Fixing actions.reset behavior for dynamically added fields. Fixes #798,
Browse files Browse the repository at this point in the history
fixes #791
  • Loading branch information
davidkpiano committed Jun 3, 2017
1 parent 7bf2efb commit dc26cf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/create-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export function updateFieldState(existingFieldState, updatedFieldState) {

export default function createFieldState(model, value, customInitialFieldState) {
return {
initialValue: value,
...initialFieldState,
...customInitialFieldState,
model,
value,
initialValue: value,
};
}

Expand Down
21 changes: 21 additions & 0 deletions test/form-reducer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,25 @@ describe('formReducer()', () => {
assert.equal(touchedState.bar.initialValue, 'initial');
});
});

describe('form reset after dynamically adding fields', () => {
const initialState = { filters: {} };
const reducer = formReducer('test', initialState);
const firstState = reducer(undefined, { type: 'any' });
const addedState = reducer(firstState, actions.change('test.filters.one', true));

it('form initial value should not change when adding fields', () => {
assert.deepEqual(addedState.filters.$form.initialValue, {});
assert.deepEqual(addedState.filters.$form.value, { one: true });
assert.isDefined(addedState.filters.one);
});

it('form should reset completely to its initial value', () => {
const resetState = reducer(addedState, actions.reset('test.filters'));

assert.deepEqual(resetState.filters.$form.initialValue, {});
assert.deepEqual(resetState.filters.$form.value, {});
assert.isUndefined(resetState.filters.one);
});
});
});

0 comments on commit dc26cf1

Please sign in to comment.