Skip to content
Snippets Groups Projects
StepConsent.spec.tsx 1.96 KiB
Newer Older
  • Learn to ignore specific revisions
  • import React from 'react'
    import { mount } from 'enzyme'
    import configureStore from 'redux-mock-store'
    import { Provider } from 'react-redux'
    import { globalStateData } from '../../../../tests/__mocks__/globalStateData.mock'
    import toJson from 'enzyme-to-json'
    import StepConsent from './StepConsent'
    
    jest.mock('cozy-ui/transpiled/react/I18n', () => {
      return {
        useI18n: jest.fn(() => {
          return {
            t: (str: string) => str,
          }
        }),
      }
    })
    const mockStore = configureStore([])
    
    describe('StepConsent component', () => {
      it('should be rendered correctly', () => {
        const mockHandleChange = jest.fn()
        const store = mockStore({
          ecolyo: {
            global: globalStateData,
          },
        })
        const wrapper = mount(
          <Provider store={store}>
            <StepConsent
              sgeState={globalStateData.sgeConnect}
              onChange={mockHandleChange}
            />
          </Provider>
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
      it('should change pdlConfirm value', () => {
        const mockHandleChange = jest.fn()
        const store = mockStore({
          ecolyo: {
            global: globalStateData,
          },
        })
        const wrapper = mount(
          <Provider store={store}>
            <StepConsent
              sgeState={globalStateData.sgeConnect}
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#pdlConfirm').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('pdlConfirm', false)
      })
      it('should change dataConsent value', () => {
        const mockHandleChange = jest.fn()
        const store = mockStore({
          ecolyo: {
            global: globalStateData,
          },
        })
        const wrapper = mount(
          <Provider store={store}>
            <StepConsent
              sgeState={globalStateData.sgeConnect}
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#dataConsent').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('dataConsent', false)
      })
    })