-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from jwplayer/feat/dependencies-update
feat(project): deps update
- Loading branch information
Showing
22 changed files
with
3,367 additions
and
3,378 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import { fireEvent, act, render } from '@testing-library/react'; | ||
|
||
import LoginForm from './LoginForm'; | ||
|
||
import { renderWithRouter } from '#test/testUtils'; | ||
import { createWrapper, waitForWithFakeTimers } from '#test/testUtils'; | ||
|
||
vi.mock('../SocialButton/SocialButton.tsx', () => ({ | ||
default: (props: { href: string }) => { | ||
return <a href={props.href}>Social Button</a>; | ||
}, | ||
})); | ||
|
||
vi.mock('#src/stores/AccountController', async () => ({ | ||
getSocialLoginUrls: vi.fn(() => [ | ||
{ | ||
twitter: 'https://staging-v2.inplayer.com/', | ||
}, | ||
{ | ||
facebook: 'https://www.facebook.com/', | ||
}, | ||
{ | ||
google: 'https://accounts.google.com/', | ||
}, | ||
]), | ||
})); | ||
|
||
describe('<LoginForm>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = renderWithRouter( | ||
beforeEach(() => { | ||
vi.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.useRealTimers(); | ||
}); | ||
|
||
test('renders and matches snapshot', async () => { | ||
const { container } = render( | ||
<LoginForm | ||
onSubmit={vi.fn()} | ||
onChange={vi.fn()} | ||
|
@@ -18,13 +46,16 @@ describe('<LoginForm>', () => { | |
errors={{}} | ||
submitting={false} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
await waitForWithFakeTimers(); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('sets the correct values in the form fields', () => { | ||
const { getByLabelText } = renderWithRouter( | ||
test('sets the correct values in the form fields', async () => { | ||
const { getByLabelText } = render( | ||
<LoginForm | ||
onSubmit={vi.fn()} | ||
onChange={vi.fn()} | ||
|
@@ -35,14 +66,17 @@ describe('<LoginForm>', () => { | |
errors={{}} | ||
submitting={false} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
await waitForWithFakeTimers(); | ||
|
||
expect(getByLabelText('login.email')).toHaveValue('[email protected]'); | ||
expect(getByLabelText('login.password')).toHaveValue('mypassword'); | ||
}); | ||
|
||
test('sets the correct errors in the form fields', () => { | ||
const { queryByText } = renderWithRouter( | ||
test('sets the correct errors in the form fields', async () => { | ||
const { queryByText } = render( | ||
<LoginForm | ||
onSubmit={vi.fn()} | ||
onChange={vi.fn()} | ||
|
@@ -53,15 +87,18 @@ describe('<LoginForm>', () => { | |
errors={{ email: 'Email error', password: 'Password error', form: 'Form error' }} | ||
submitting={false} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
await waitForWithFakeTimers(); | ||
|
||
expect(queryByText('Email error')).toBeDefined(); | ||
expect(queryByText('Password error')).toBeDefined(); | ||
expect(queryByText('Form error')).toBeDefined(); | ||
}); | ||
|
||
test('disables the submit button when submitting is true', () => { | ||
const { getByRole } = renderWithRouter( | ||
test('disables the submit button when submitting is true', async () => { | ||
const { getByRole } = render( | ||
<LoginForm | ||
onSubmit={vi.fn()} | ||
onChange={vi.fn()} | ||
|
@@ -72,14 +109,18 @@ describe('<LoginForm>', () => { | |
errors={{}} | ||
submitting={true} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
await waitForWithFakeTimers(); | ||
|
||
expect(getByRole('button', { name: 'login.sign_in' })).toBeDisabled(); | ||
}); | ||
|
||
test('calls the onSubmit callback when the form gets submitted', () => { | ||
test('calls the onSubmit callback when the form gets submitted', async () => { | ||
const onSubmit = vi.fn(); | ||
const { getByTestId } = renderWithRouter( | ||
|
||
const { getByTestId } = render( | ||
<LoginForm | ||
onSubmit={onSubmit} | ||
onChange={vi.fn()} | ||
|
@@ -90,16 +131,22 @@ describe('<LoginForm>', () => { | |
errors={{}} | ||
submitting={true} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
fireEvent.submit(getByTestId('login-form')); | ||
act(() => { | ||
fireEvent.submit(getByTestId('login-form')); | ||
}); | ||
|
||
await waitForWithFakeTimers(); | ||
|
||
expect(onSubmit).toBeCalled(); | ||
}); | ||
|
||
test('calls the onChange callback when a text field changes', () => { | ||
test('calls the onChange callback when a text field changes', async () => { | ||
const onChange = vi.fn(); | ||
const { getByLabelText } = renderWithRouter( | ||
|
||
const { getByLabelText } = render( | ||
<LoginForm | ||
onSubmit={vi.fn()} | ||
onChange={onChange} | ||
|
@@ -110,10 +157,15 @@ describe('<LoginForm>', () => { | |
errors={{}} | ||
submitting={true} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
fireEvent.change(getByLabelText('login.email'), { target: { value: 'email' } }); | ||
fireEvent.change(getByLabelText('login.password'), { target: { value: 'password' } }); | ||
act(() => { | ||
fireEvent.change(getByLabelText('login.email'), { target: { value: 'email' } }); | ||
fireEvent.change(getByLabelText('login.password'), { target: { value: 'password' } }); | ||
}); | ||
|
||
await waitForWithFakeTimers(); | ||
|
||
expect(onChange).toBeCalledTimes(2); | ||
}); | ||
|
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.