-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: outlined input error border width #2975
Changes from all commits
65a4050
f8a35f1
88f8027
2c49d31
eb04b16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet } from 'react-native'; | ||
import { render } from 'react-native-testing-library'; | ||
import { fireEvent, render } from 'react-native-testing-library'; | ||
import TextInput from '../TextInput/TextInput'; | ||
import { red500 } from '../../styles/colors'; | ||
|
||
|
@@ -108,3 +108,43 @@ it('correctly applies height to multiline Outline TextInput', () => { | |
|
||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('correctly applies error state Outline TextInput', () => { | ||
const { getByTestId } = render( | ||
<TextInput | ||
mode="outlined" | ||
label="Outline Input with error" | ||
placeholder="Type Something" | ||
value={'Some test value'} | ||
error | ||
/> | ||
); | ||
|
||
const outline = getByTestId('text-input-outline'); | ||
expect(outline.props.style).toEqual( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lukewalczak @brunohkbx I've added |
||
expect.arrayContaining([expect.objectContaining({ borderWidth: 1 })]) | ||
); | ||
}); | ||
|
||
it('correctly applies focused state Outline TextInput', () => { | ||
const { getByTestId } = render( | ||
<TextInput | ||
mode="outlined" | ||
label="Outline Input with error" | ||
placeholder="Type Something" | ||
value={'Some test value'} | ||
error | ||
/> | ||
); | ||
|
||
const outline = getByTestId('text-input-outline'); | ||
expect(outline.props.style).toEqual( | ||
expect.arrayContaining([expect.objectContaining({ borderWidth: 1 })]) | ||
); | ||
|
||
fireEvent(getByTestId('text-input-outlined'), 'focus'); | ||
|
||
expect(outline.props.style).toEqual( | ||
expect.arrayContaining([expect.objectContaining({ borderWidth: 2 })]) | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @enagorny, could you please add snapshot testing that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added snapshot test for outlined text input with error. Also added it to TextInputExample.
But I can't find a way how to properly set text input focused using react-native-testing-library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukewalczak @enagorny what do you guys think about adding a testID in the
Outline
and then instead of a snapshot we can usetesting-library
to assert whether it has the right borderWidth?Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brunohkbx, sounds good! @enagorny could you please adjust it to the suggestion above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukewalczak I'll try it.
Just thinking that adding testId might be out of scope of this PR. As it should be implemented for both text inputs and be documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see it is suggested to add testId to outline only. Not the TextInput itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and still I can't test focused state 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @enagorny, you can test focused state by:
testID
intoTextInputOutlined
egtext-input-outlined
fireEvent
usage: