Skip to content
Snippets Groups Projects
FeedbackModal.spec.tsx 2.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { render, screen } from '@testing-library/react'
    import userEvent from '@testing-library/user-event'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import FeedbackModal from 'components/Feedback/FeedbackModal'
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    
    import React from 'react'
    
    import { Provider } from 'react-redux'
    
    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 } })
    
      beforeEach(() => {
    
        jest.clearAllMocks()
    
      })
      it('should render the component', () => {
        const component = mount(
          <Provider store={store}>
    
            <FeedbackModal />
    
          </Provider>
    
        )
        expect(toJson(component)).toMatchSnapshot()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      describe('FeedbackModal functionalities', () => {
    
        it('should close modal with the "x" button', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          render(
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            <Provider store={store}>
    
              <FeedbackModal />
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            </Provider>
          )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          await userEvent.click(screen.getAllByRole('button')[0])
    
          expect(mockAppDispatch).toHaveBeenCalledTimes(1)
        })
    
        it('should close modal with the "later" button', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          render(
    
            <Provider store={store}>
              <FeedbackModal />
            </Provider>
          )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          await userEvent.click(screen.getAllByRole('button')[1])
    
          expect(mockAppDispatch).toHaveBeenCalledTimes(1)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        it('should open the SAU link', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          global.open = jest.fn()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          render(
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            <Provider store={store}>
    
              <FeedbackModal />
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            </Provider>
          )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          await userEvent.click(screen.getAllByRole('button')[2])
    
          expect(window.open).toHaveBeenCalledTimes(1)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          expect(global.open).toHaveBeenCalledWith(`${__SAU_LINK__}?version=0.0.0`)
        })