-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(account-settings): share
<ValidationErrors />
(#2908)
* Share common Authenticator utils * ValidationErrors unit test * Remove extra function layer * defaultPasswordValidator unit test * Update password validator usage * Remove `.only` and fix equality assertions * return null from validator, and add unit test * Test against null instead of [] * Revert defaultPasswordValidator change * Remove stale export
- Loading branch information
Showing
5 changed files
with
99 additions
and
7 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
10 changes: 7 additions & 3 deletions
10
...Authenticator/shared/ValidationErrors.tsx → ...rc/components/shared/ValidationErrors.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
30 changes: 30 additions & 0 deletions
30
packages/react/src/components/shared/__tests__/ValidationErrors.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,30 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { ValidationErrors } from '../ValidationErrors'; | ||
|
||
describe('ValidationErrors', () => { | ||
it('renders errors as expected', async () => { | ||
const { container } = render( | ||
<ValidationErrors errors={['mock error 1', 'mock error 2']} /> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
expect(await screen.findByText('mock error 1')).toBeDefined(); | ||
expect(await screen.findByText('mock error 2')).toBeDefined(); | ||
}); | ||
|
||
it('renders nothing if there are no errors', async () => { | ||
const { container } = render(<ValidationErrors errors={[]} />); | ||
expect(container).toMatchInlineSnapshot(`<div />`); | ||
}); | ||
|
||
it('renders dataAttr as expected', () => { | ||
const dataAttr = 'data-amplify-sign-up-errors'; | ||
const { container } = render( | ||
<ValidationErrors | ||
dataAttr={dataAttr} | ||
errors={['mock error 1', 'mock error 2']} | ||
/> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/react/src/components/shared/__tests__/__snapshots__/ValidationErrors.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,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ValidationErrors renders dataAttr as expected 1`] = ` | ||
<div> | ||
<div | ||
data-amplify-sign-up-errors="true" | ||
> | ||
<p | ||
class="amplify-text amplify-text--error" | ||
data-variation="error" | ||
role="alert" | ||
> | ||
mock error 1 | ||
</p> | ||
<p | ||
class="amplify-text amplify-text--error" | ||
data-variation="error" | ||
role="alert" | ||
> | ||
mock error 2 | ||
</p> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`ValidationErrors renders errors as expected 1`] = ` | ||
<div> | ||
<div> | ||
<p | ||
class="amplify-text amplify-text--error" | ||
data-variation="error" | ||
role="alert" | ||
> | ||
mock error 1 | ||
</p> | ||
<p | ||
class="amplify-text amplify-text--error" | ||
data-variation="error" | ||
role="alert" | ||
> | ||
mock error 2 | ||
</p> | ||
</div> | ||
</div> | ||
`; |
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 @@ | ||
export { ValidationErrors } from './ValidationErrors'; |