Skip to content
Snippets Groups Projects
StepIdentityAndPdl.spec.tsx 2.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { mount } from 'enzyme'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import toJson from 'enzyme-to-json'
    import React from 'react'
    
    import { Provider } from 'react-redux'
    
    import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store'
    
    import StepIdentityAndPdl from './StepIdentityAndPdl'
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    const mockHandleChange = jest.fn()
    
    
    describe('StepIdentityAndPdl component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepIdentityAndPdl
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
      it('should change firstName value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepIdentityAndPdl
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#firstName').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('firstName', '')
      })
      it('should change lastName value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepIdentityAndPdl
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#lastName').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('lastName', '')
      })
      it('should change pdl value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepIdentityAndPdl
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#pdl').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('pdl', '', 14)
      })
      it('should open hint modal', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepIdentityAndPdl
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('.pdl-hint').first().simulate('click')
        expect(wrapper.find('.sgeHintModal')).toBeTruthy()
      })
      it('should have an existing pdl value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepIdentityAndPdl
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={{ ...mockGlobalState.sgeConnect, pdl: 11111111111111 }}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        expect(wrapper.find('#pdl').first().props().value).toBe(11111111111111)
      })
    })