Newer
Older
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import FeedbackModal from 'components/Feedback/FeedbackModal'
import { mount } from 'enzyme'
import toJson from 'enzyme-to-json'
import * as storeHooks from 'store/hooks'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
// Value coming from jest.config
declare let __SAU_LINK__: string
jest.mock('services/environment.service', () => {
return jest.fn(() => ({
isProduction: () => true,
}))
jest.mock('components/Hooks/useExploration', () => () => ['', jest.fn()])
const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch')
describe('FeedbackModal component', () => {
const store = createMockEcolyoStore({ modal: { isFeedbacksOpen: true } })
})
it('should render the component', () => {
const component = mount(
<Provider store={store}>
)
expect(toJson(component)).toMatchSnapshot()
it('should close modal with the "x" button', async () => {
await userEvent.click(screen.getAllByRole('button')[0])
expect(mockAppDispatch).toHaveBeenCalledTimes(1)
})
it('should close modal with the "later" button', async () => {
<Provider store={store}>
<FeedbackModal />
</Provider>
)
await userEvent.click(screen.getAllByRole('button')[1])
expect(mockAppDispatch).toHaveBeenCalledTimes(1)
await userEvent.click(screen.getAllByRole('button')[2])
expect(window.open).toHaveBeenCalledTimes(1)
expect(global.open).toHaveBeenCalledWith(`${__SAU_LINK__}?version=0.0.0`)
})