Skip to content
Snippets Groups Projects
StepAddress.spec.tsx 2.21 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'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import {
      createMockEcolyoStore,
      mockGlobalState,
    } from '../../../../tests/__mocks__/store'
    
    import StepAddress from './StepAddress'
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    jest.mock('cozy-ui/transpiled/react/I18n', () => ({
      useI18n: jest.fn(() => ({
        t: (str: string) => str,
      })),
    }))
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    const mockHandleChange = jest.fn()
    
    
    describe('StepAddress component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepAddress
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
      it('should change address value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepAddress
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#address').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('address', '')
      })
      it('should change zipCode value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepAddress
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#zipCode').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('zipCode', '', 5)
      })
      it('should have an existing zipCode value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepAddress
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={{ ...mockGlobalState.sgeConnect, zipCode: 69200 }}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        expect(wrapper.find('#zipCode').first().props().value).toBe(69200)
      })
      it('should change city value', () => {
        const wrapper = mount(
          <Provider store={store}>
            <StepAddress
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
              sgeState={mockGlobalState.sgeConnect}
    
              onChange={mockHandleChange}
            />
          </Provider>
        )
        wrapper.find('#city').first().simulate('change')
        expect(mockHandleChange).toHaveBeenCalledWith('city', '')
      })
    })