-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
62 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,13 @@ const withFormikMock = withContext({ formik: PropTypes.object }, () => ({ | |
formik: { | ||
setFieldValue, | ||
setFieldTouched, | ||
values: { email: "[email protected]" } | ||
values: { | ||
email: "[email protected]", | ||
user: { | ||
username: "bam-dev", | ||
password: 'goodchallenge', | ||
} | ||
} | ||
} | ||
})); | ||
const Input = compose(withFormikMock, makeReactNativeField)(TextInput); | ||
|
@@ -28,6 +34,13 @@ describe("makeReactNativeField", () => { | |
expect(otherInput.find(TextInput).props().value).toEqual(undefined); | ||
}); | ||
|
||
it('sets the input value for nested key name', () => { | ||
const emailInput = mount(<Input name="user.username" />); | ||
expect(emailInput.find(TextInput).props().value).toEqual("bam-dev"); | ||
const otherInput = mount(<Input name="user.other" />); | ||
expect(otherInput.find(TextInput).props().value).toEqual(undefined); | ||
}); | ||
|
||
it("handles input value change", () => { | ||
const wrapper = mount(<Input name="email" />); | ||
wrapper | ||
|
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,13 @@ | ||
export const selectValue = (values, name) => { | ||
if (!name.includes('.')) { | ||
return values[name]; | ||
} else { | ||
const nestedKeys = name.split('.'); | ||
selectedValue = values[nestedKeys[0]]; | ||
for (let i = 1; i < nestedKeys.length; i += 1) { | ||
selectedValue = selectedValue[nestedKeys[i]]; | ||
} | ||
|
||
return selectedValue; | ||
} | ||
}; |
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