-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rna): Add SignIn subcomponent (#2812)
* feat(rna): Add SignIn subcomponent
- Loading branch information
1 parent
198eedc
commit d6d2e27
Showing
23 changed files
with
1,280 additions
and
66 deletions.
There are no files selected for viewing
53 changes: 46 additions & 7 deletions
53
examples/react-native/storybook/stories/SignIn.stories.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 |
---|---|---|
@@ -1,11 +1,50 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react-native'; | ||
import { SignIn } from '@aws-amplify/ui-react-native/dist/Authenticator/Defaults'; | ||
import { Authenticator } from '@aws-amplify/ui-react-native'; | ||
import noop from 'lodash/noop'; | ||
|
||
const props = {} as any; | ||
const username = { | ||
name: 'username', | ||
label: 'Username', | ||
placeholder: 'Username', | ||
type: 'default' as const, | ||
}; | ||
|
||
storiesOf('SignIn', module) | ||
.add('default', () => <SignIn {...props} />) | ||
.add('header', () => <SignIn.Header />) | ||
.add('footer', () => <SignIn.Footer />) | ||
.add('formFields', () => <SignIn.FormFields {...props} />); | ||
const password = { | ||
name: 'password', | ||
label: 'Password', | ||
placeholder: 'Password', | ||
type: 'password' as const, | ||
}; | ||
|
||
const fields = [username, password]; | ||
|
||
const baseProps = { | ||
fields, | ||
Footer: Authenticator.SignIn.Footer, | ||
FormFields: Authenticator.SignIn.FormFields, | ||
Header: Authenticator.SignIn.Header, | ||
hideSignUp: false, | ||
isPending: false, | ||
handleBlur: noop, | ||
handleSubmit: (values: any) => { | ||
console.log('Values', values); | ||
}, | ||
handleChange: noop, | ||
toFederatedSignIn: noop, | ||
toResetPassword: noop, | ||
toSignUp: noop, | ||
error: null as unknown as string, | ||
}; | ||
|
||
storiesOf('Authenticator.SignIn', module) | ||
.add('Basic', () => <Authenticator.SignIn {...baseProps} />) | ||
.add('With error', () => ( | ||
<Authenticator.SignIn {...baseProps} error={'Error!'} /> | ||
)) | ||
.add('With Social Providers', () => ( | ||
<Authenticator.SignIn | ||
{...baseProps} | ||
socialProviders={['amazon', 'facebook']} | ||
/> | ||
)); |
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
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
4 changes: 0 additions & 4 deletions
4
packages/react-native/src/Authenticator/Defaults/FormFields.tsx
This file was deleted.
Oops, something went wrong.
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
102 changes: 96 additions & 6 deletions
102
packages/react-native/src/Authenticator/Defaults/SignIn/SignIn.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
55 changes: 45 additions & 10 deletions
55
packages/react-native/src/Authenticator/Defaults/SignIn/__tests__/SignIn.spec.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 |
---|---|---|
@@ -1,22 +1,57 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
|
||
import { SignIn } from '..'; | ||
import SignIn from '../SignIn'; | ||
|
||
const props = {} as any; | ||
const props = { | ||
fields: [], | ||
Footer: SignIn.Footer, | ||
FormFields: SignIn.FormFields, | ||
handleBlur: jest.fn(), | ||
handleChange: jest.fn(), | ||
handleSubmit: jest.fn(), | ||
Header: SignIn.Header, | ||
isPending: false, | ||
socialProviders: undefined, | ||
toResetPassword: jest.fn(), | ||
toFederatedSignIn: jest.fn(), | ||
toSignUp: jest.fn(), | ||
}; | ||
|
||
describe('SignIn', () => { | ||
it('renders as expected', () => { | ||
const { toJSON, getByRole } = render( | ||
<> | ||
<SignIn {...props} /> | ||
<SignIn.Header /> | ||
<SignIn.Footer /> | ||
<SignIn.FormFields {...props} /> | ||
</> | ||
); | ||
const { toJSON, getByRole, getAllByRole } = render(<SignIn {...props} />); | ||
expect(toJSON()).toMatchSnapshot(); | ||
|
||
expect(getAllByRole('tab')).toHaveLength(2); | ||
expect(getByRole('header')).toBeDefined(); | ||
}); | ||
|
||
it('renders as expected with an error', () => { | ||
const error = 'An error!'; | ||
const { getByRole, getByText, toJSON } = render( | ||
<SignIn {...props} error={error} /> | ||
); | ||
|
||
expect(getByRole('alert')).toBeDefined(); | ||
expect(getByText(error)).toBeDefined(); | ||
|
||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders as expected when hideSignUp is true', () => { | ||
const { toJSON } = render(<SignIn {...props} hideSignUp />); | ||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders as expected with socialProviders', () => { | ||
const { toJSON, getByText } = render( | ||
<SignIn {...props} socialProviders={['amazon', 'facebook']} /> | ||
); | ||
|
||
expect(getByText('Sign In with Amazon')).toBeDefined(); | ||
expect(getByText('Sign In with Facebook')).toBeDefined(); | ||
|
||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.