-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(field): making description show up (#3675)
- Loading branch information
1 parent
fed85d4
commit c3918d9
Showing
4 changed files
with
109 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@aws-amplify/ui-react": patch | ||
--- | ||
|
||
fix(field): making description show up |
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
69 changes: 69 additions & 0 deletions
69
packages/react/src/primitives/Field/__tests__/Field.test.tsx
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,69 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import { Field } from '../Field'; | ||
import { ComponentClassNames } from '../../shared/constants'; | ||
|
||
describe('Field component', () => { | ||
it('should match snapshot', () => { | ||
const { container } = render( | ||
<Field | ||
label="label" | ||
descriptiveText="some description" | ||
errorMessage="error" | ||
hasError | ||
> | ||
<div>hi</div> | ||
</Field> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render a label', () => { | ||
const { getByText } = render(<Field label="label" />); | ||
const descriptionElement = getByText('label'); | ||
expect(descriptionElement).toHaveClass(ComponentClassNames.Label); | ||
}); | ||
|
||
it('should render descriptive text', () => { | ||
const { getByText } = render( | ||
<Field label="label" descriptiveText="description" /> | ||
); | ||
const descriptionElement = getByText('description'); | ||
expect(descriptionElement).toHaveClass( | ||
ComponentClassNames.FieldDescription | ||
); | ||
}); | ||
|
||
it('should render error message', () => { | ||
const { getByText } = render( | ||
<Field label="label" errorMessage="error" hasError /> | ||
); | ||
const descriptionElement = getByText('error'); | ||
expect(descriptionElement).toHaveClass( | ||
ComponentClassNames.FieldErrorMessage | ||
); | ||
}); | ||
|
||
it('should render if it has a "labelHidden" prop is `true`, as long as there\'s descriptiveText', () => { | ||
const { getByText } = render( | ||
<Field label="label" descriptiveText="some description" labelHidden /> | ||
); | ||
const descriptionElement = getByText('some description'); | ||
expect(descriptionElement).toHaveClass(ComponentClassNames.VisuallyHidden); | ||
}); | ||
|
||
it('should not be hidden if it has a "labelHidden" prop is `false`', () => { | ||
const { getByText } = render( | ||
<Field | ||
label="label" | ||
descriptiveText="some description" | ||
labelHidden={false} | ||
/> | ||
); | ||
const descriptionElement = getByText('some description'); | ||
expect(descriptionElement).not.toHaveClass( | ||
ComponentClassNames.VisuallyHidden | ||
); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/react/src/primitives/Field/__tests__/__snapshots__/Field.test.tsx.snap
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,29 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Field component should match snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="amplify-flex amplify-field" | ||
> | ||
<label | ||
class="amplify-label" | ||
> | ||
label | ||
</label> | ||
<p | ||
class="amplify-text amplify-field__description" | ||
data-testid="qa-field-description" | ||
> | ||
some description | ||
</p> | ||
<div> | ||
hi | ||
</div> | ||
<p | ||
class="amplify-text amplify-field__error-message" | ||
> | ||
error | ||
</p> | ||
</div> | ||
</div> | ||
`; |