Newer
Older
import { Button } from '@material-ui/core'
import { FluidType } from 'enums'

Guilhem CARRON
committed
import { mount } from 'enzyme'
import toJson from 'enzyme-to-json'
import React from 'react'

Guilhem CARRON
committed
import { Provider } from 'react-redux'
import { fluidStatusConnectedData } from 'tests/__mocks__/fluidStatusData.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import ExpiredConsentModal from './ExpiredConsentModal'

Guilhem CARRON
committed
const mockedNavigate = jest.fn()

Guilhem CARRON
committed
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigate,

Guilhem CARRON
committed
}))
const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch')
const mockToggleModal = jest.fn()
const mockHandleCloseClick = jest.fn()

Guilhem CARRON
committed
describe('ExpiredConsentModal component', () => {
beforeEach(() => {

Guilhem CARRON
committed
it('should be rendered correctly', () => {
const component = mount(
<Provider store={store}>
<ExpiredConsentModal
open={true}
handleCloseClick={jest.fn()}
fluidType={FluidType.ELECTRICITY}
toggleModal={mockToggleModal}

Guilhem CARRON
committed
/>
</Provider>
)
expect(toJson(component)).toMatchSnapshot()
})
it('should launch the update consent process for GRDF', () => {

Guilhem CARRON
committed
const component = mount(
<Provider store={store}>
<ExpiredConsentModal
open={true}
handleCloseClick={jest.fn()}
fluidType={FluidType.GAS}
toggleModal={mockToggleModal}

Guilhem CARRON
committed
/>
</Provider>
)
component.find(Button).at(1).simulate('click')
expect(mockAppDispatch).toHaveBeenCalledTimes(1)
expect(mockedNavigate).toHaveBeenCalledTimes(1)

Guilhem CARRON
committed
})
it('should launch the update consent process for Enedis', () => {
const store = createMockEcolyoStore({
global: { fluidStatus: fluidStatusConnectedData },
})
const component = mount(
<Provider store={store}>
<ExpiredConsentModal
open={true}
handleCloseClick={jest.fn()}
fluidType={FluidType.ELECTRICITY}
toggleModal={mockToggleModal}
/>
</Provider>
)
component.find(Button).at(1).simulate('click')
expect(mockAppDispatch).toHaveBeenCalledTimes(1)
expect(mockedNavigate).toHaveBeenCalledTimes(1)
})
it('should click on close modal', () => {
const component = mount(
<Provider store={store}>
<ExpiredConsentModal
open={true}
handleCloseClick={mockHandleCloseClick}
fluidType={FluidType.ELECTRICITY}
toggleModal={mockToggleModal}
/>
</Provider>
)
component.find(Button).at(0).simulate('click')
expect(mockHandleCloseClick).toHaveBeenCalled()
})