-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(authenticator): Check first radio button from unverified user att…
…ributes so that default value is selected (#5399)
- Loading branch information
Showing
8 changed files
with
134 additions
and
22 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,7 @@ | ||
--- | ||
"@aws-amplify/ui-react": patch | ||
"@aws-amplify/ui-vue": patch | ||
"@aws-amplify/ui-angular": patch | ||
--- | ||
|
||
fix(authenticator): Check first radio button from unverified user attributes so that default value is selected |
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
68 changes: 68 additions & 0 deletions
68
packages/react/src/components/Authenticator/VerifyUser/__tests__/VerifyUser.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,68 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { useAuthenticator, UseAuthenticator } from '@aws-amplify/ui-react-core'; | ||
|
||
import { VerifyUser } from '..'; | ||
|
||
jest.mock('@aws-amplify/ui-react-core'); | ||
|
||
jest.mock('../../hooks/useFormHandlers', () => ({ | ||
useFormHandlers: () => ({ handleChange: jest.fn(), handleSubmit: jest.fn() }), | ||
})); | ||
|
||
jest.mock('../../hooks/useCustomComponents', () => ({ | ||
useCustomComponents: () => ({ | ||
components: { | ||
Header: () => null, | ||
Footer: () => null, | ||
VerifyUser: { Header: () => null, Footer: () => null }, | ||
}, | ||
}), | ||
})); | ||
|
||
describe('VerifyUser', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should select the first unverified attribute', async () => { | ||
(useAuthenticator as jest.Mock).mockReturnValue({ | ||
isPending: false, | ||
unverifiedUserAttributes: { | ||
email: 'test@example.com', | ||
}, | ||
} as UseAuthenticator); | ||
|
||
render(<VerifyUser className="className" variation="default" />); | ||
|
||
const radioInput = screen.getByRole('radio', { | ||
name: (content) => content.startsWith('Email:'), | ||
}); | ||
|
||
expect(radioInput).toBeChecked(); | ||
}); | ||
|
||
it('should select the first unverified attribute when there are multiple attributes', async () => { | ||
(useAuthenticator as jest.Mock).mockReturnValue({ | ||
isPending: false, | ||
unverifiedUserAttributes: { | ||
phone_number: '+1234566789', | ||
email: 'test@example.com', | ||
}, | ||
} as UseAuthenticator); | ||
|
||
render(<VerifyUser className="className" variation="default" />); | ||
|
||
const phoneNumberRadioInput = screen.getByRole('radio', { | ||
name: (content) => content.startsWith('Phone Number:'), | ||
}); | ||
|
||
const emailRadioInput = screen.getByRole('radio', { | ||
name: (content) => content.startsWith('Email:'), | ||
}); | ||
|
||
expect(phoneNumberRadioInput).toBeChecked(); | ||
expect(emailRadioInput).not.toBeChecked(); | ||
}); | ||
}); |
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