Skip to content

Commit

Permalink
Add tests to UpdatePassword component
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Sep 27, 2023
1 parent dc9d8a8 commit 5796292
Showing 1 changed file with 51 additions and 0 deletions.
@@ -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,
})
})
})

0 comments on commit 5796292

Please sign in to comment.