Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to UpdatePassword component
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/app/components/Toolbar/Features/Profile/__tests__/UpdatePassword.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,51 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import { Provider } from 'react-redux' | ||
import { configureAppStore } from 'store/configureStore' | ||
import { ThemeProvider } from 'styles/theme/ThemeProvider' | ||
import { persistActions } from 'app/state/persist' | ||
import { UpdatePassword } from '../UpdatePassword' | ||
|
||
const renderComponent = (store: any) => | ||
render( | ||
<Provider store={store}> | ||
<ThemeProvider> | ||
<UpdatePassword /> | ||
</ThemeProvider> | ||
</Provider>, | ||
) | ||
|
||
describe('<UpdatePassword />', () => { | ||
let store: ReturnType<typeof configureAppStore> | ||
|
||
beforeEach(() => { | ||
store = configureAppStore() | ||
}) | ||
|
||
it('should dispatch action on submit', async () => { | ||
const spy = jest.spyOn(store, 'dispatch') | ||
renderComponent(store) | ||
|
||
await userEvent.type(screen.getByPlaceholderText('toolbar.profile.password.current'), 'asd') | ||
await userEvent.type(screen.getByPlaceholderText('toolbar.profile.password.enterNewPassword'), '123') | ||
await userEvent.type(screen.getByPlaceholderText('toolbar.profile.password.reenterNewPassword'), '123') | ||
await userEvent.click(screen.getByRole('button', { name: 'toolbar.profile.password.submit' })) | ||
expect(spy).toHaveBeenCalledWith({ | ||
payload: { | ||
currentPassword: 'asd', | ||
password: '123', | ||
}, | ||
type: persistActions.updatePasswordAsync.type, | ||
}) | ||
}) | ||
|
||
it('should clear redux password error', () => { | ||
const spy = jest.spyOn(store, 'dispatch') | ||
const { unmount } = renderComponent(store) | ||
|
||
unmount() | ||
expect(spy).toHaveBeenCalledWith({ | ||
type: persistActions.resetWrongPassword.type, | ||
}) | ||
}) | ||
}) |