-
-
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.
Add a selector to get touched and visited props from state (#2859)
* added a selector (getFormMeta) which retrieves the form.{$name}.fields slice from state * added documentation for getFormMeta selector
- Loading branch information
Showing
8 changed files
with
108 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,85 @@ | ||
import createGetFormMeta from '../getFormMeta' | ||
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 describeGetFormMeta = (name, structure, expect) => { | ||
const getFormMeta = createGetFormMeta(structure) | ||
|
||
const {fromJS, getIn} = structure | ||
|
||
describe(name, () => { | ||
it('should return a function', () => { | ||
expect(createGetFormMeta('foo')).toBeA('function') | ||
}) | ||
|
||
it('should get the form values from state', () => { | ||
expect(getFormMeta('foo')(fromJS({ | ||
form: { | ||
foo: { | ||
fields: { | ||
dog: { | ||
visited: true, | ||
touched: false | ||
}, | ||
cat: { | ||
visited: false, | ||
touched: true | ||
} | ||
} | ||
} | ||
} | ||
}))).toEqualMap({ | ||
dog: { | ||
visited: true, | ||
touched: false | ||
}, | ||
cat: { | ||
visited: false, | ||
touched: true | ||
} | ||
}) | ||
}) | ||
|
||
it('should return undefined if there are no fields', () => { | ||
expect(getFormMeta('foo')(fromJS({ | ||
form: { | ||
foo: {} | ||
} | ||
}))).toEqual(undefined) | ||
}) | ||
|
||
it('should use getFormState if provided', () => { | ||
expect(getFormMeta('foo', state => getIn(state, 'someOtherSlice'))(fromJS({ | ||
someOtherSlice: { | ||
foo: { | ||
fields: { | ||
dog: { | ||
visited: true, | ||
touched: false | ||
}, | ||
cat: { | ||
visited: false, | ||
touched: true | ||
} | ||
} | ||
} | ||
} | ||
}))).toEqualMap({ | ||
dog: { | ||
visited: true, | ||
touched: false | ||
}, | ||
cat: { | ||
visited: false, | ||
touched: true | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
describeGetFormMeta('getFormMeta.plain', plain, addExpectations(plainExpectations)) | ||
describeGetFormMeta('getFormMeta.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 createGetFormMeta = ({ getIn }) => | ||
(form, getFormState = state => getIn(state, 'form')) => | ||
state => getIn(getFormState(state), `${form}.fields`) | ||
|
||
export default createGetFormMeta |