-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import createGetFormInitialValues from '../getFormInitialValues' | ||
import plain from '../../structure/plain' | ||
import plainExpectations from '../../structure/plain/expectations' | ||
import immutable from '../../structure/immutable' | ||
import immutableExpectations from '../../structure/immutable/expectations' | ||
import addExpectations from '../../__tests__/addExpectations' | ||
|
||
const describeGetFormInitialValues = (name, structure, expect) => { | ||
const getFormInitialValues = createGetFormInitialValues(structure) | ||
|
||
const { fromJS, getIn } = structure | ||
|
||
describe(name, () => { | ||
it('should return a function', () => { | ||
expect(getFormInitialValues('foo')).toBeA('function') | ||
}) | ||
|
||
it('should get the initial form values from state', () => { | ||
expect(getFormInitialValues('foo')(fromJS({ | ||
form: { | ||
foo: { | ||
initial: { | ||
dog: 'Snoopy', | ||
cat: 'Garfield' | ||
} | ||
} | ||
} | ||
}))).toEqualMap({ | ||
dog: 'Snoopy', | ||
cat: 'Garfield' | ||
}) | ||
}) | ||
|
||
it('should use getFormState if provided', () => { | ||
expect(getFormInitialValues('foo', state => getIn(state, 'someOtherSlice'))(fromJS({ | ||
someOtherSlice: { | ||
foo: { | ||
initial: { | ||
dog: 'Snoopy', | ||
cat: 'Garfield' | ||
} | ||
} | ||
} | ||
}))).toEqualMap({ | ||
dog: 'Snoopy', | ||
cat: 'Garfield' | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
describeGetFormInitialValues('getFormInitialValues.plain', plain, addExpectations(plainExpectations)) | ||
describeGetFormInitialValues('getFormInitialValues.immutable', immutable, addExpectations(immutableExpectations)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const createGetFormInitialValues = ({ getIn }) => | ||
(form, getFormState = state => getIn(state, 'form')) => | ||
state => getIn(getFormState(state), `${form}.initial`) | ||
|
||
export default createGetFormInitialValues |