Newer
Older
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 () => {
wrapper.find('.modal-paper-close-button').first().simulate('click')
expect(mockAppDispatch).toHaveBeenCalledTimes(1)
})
it('should close modal with the "later" button', async () => {
const wrapper = mount(
<Provider store={store}>
<FeedbackModal />
</Provider>
)
wrapper.find('.btn-secondary-positive').first().simulate('click')
expect(mockAppDispatch).toHaveBeenCalledTimes(1)
it('should open the SAU link', () => {
global.open = jest.fn()
const wrapper = mount(
<Provider store={store}>
</Provider>
)
wrapper.find('.btn-highlight').first().simulate('click')
expect(window.open).toHaveBeenCalledTimes(1)
expect(global.open).toHaveBeenCalledWith(`${__SAU_LINK__}?version=0.0.0`)
})