Skip to content
Snippets Groups Projects
Commit 0374df5e authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

test(rtl): welcome modal

parent a14a1f7e
No related branches found
No related tags found
2 merge requests!10622.7 Release,!1059test(rtl): welcome modal
import { Button, IconButton } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { mount } from 'enzyme' import userEvent from '@testing-library/user-event'
import toJson from 'enzyme-to-json'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import * as profileActions from 'store/profile/profile.slice' import * as profileActions from 'store/profile/profile.slice'
...@@ -41,58 +40,55 @@ jest.mock('services/profile.service') ...@@ -41,58 +40,55 @@ jest.mock('services/profile.service')
const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile')
describe('WelcomeModal component', () => { describe('WelcomeModal component', () => {
beforeEach(() => {
jest.clearAllMocks()
})
const store = createMockEcolyoStore() const store = createMockEcolyoStore()
it('should be rendered correctly', () => { it('should be rendered correctly', () => {
const component = mount( const { baseElement } = render(
<Provider store={store}> <Provider store={store}>
<WelcomeModal open={true} /> <WelcomeModal open={true} />
</Provider> </Provider>
) )
expect(toJson(component)).toMatchSnapshot() expect(baseElement).toMatchSnapshot()
expect(screen.getByRole('dialog')).toBeInTheDocument()
}) })
it('should not be rendered', () => { it('should not be rendered', () => {
const component = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<WelcomeModal open={false} /> <WelcomeModal open={false} />
</Provider> </Provider>
) )
expect(toJson(component)).toMatchSnapshot() expect(container.firstChild).toBeNull()
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
}) })
it('should send mail and update profile when user click on the ok button', async () => { describe('should test modal interactivity', () => {
const component = mount( beforeEach(() => {
<Provider store={store}> render(
<WelcomeModal open={true} /> <Provider store={store}>
</Provider> <WelcomeModal open={true} />
) </Provider>
component.find(Button).first().simulate('click') )
expect(mockSendMail).toHaveBeenCalled() })
expect(updateProfileSpy).toHaveBeenCalledWith({ it('should send mail and update profile when user click on the ok button', async () => {
isFirstConnection: false, await userEvent.click(screen.getAllByRole('button')[1])
onboarding: { expect(mockSendMail).toHaveBeenCalled()
isWelcomeSeen: true, expect(updateProfileSpy).toHaveBeenCalledWith({
}, isFirstConnection: false,
onboarding: {
isWelcomeSeen: true,
},
})
}) })
})
it('should send mail and update profile when modal is closed by user', async () => { it('should send mail and update profile when modal is closed by user', async () => {
const component = mount( await userEvent.click(screen.getAllByRole('button')[0])
<Provider store={store}> expect(mockSendMail).toHaveBeenCalled()
<WelcomeModal open={true} /> expect(updateProfileSpy).toHaveBeenCalledWith({
</Provider> isFirstConnection: false,
) onboarding: {
component.find(IconButton).first().simulate('click') isWelcomeSeen: true,
expect(mockSendMail).toHaveBeenCalled() },
expect(updateProfileSpy).toHaveBeenCalledWith({ })
isFirstConnection: false,
onboarding: {
isWelcomeSeen: true,
},
}) })
}) })
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment