Skip to content
Snippets Groups Projects
Commit 22b77337 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

Merge branch 'rtl/options' into 'dev'

test(rtl): options

See merge request !1053
parents 0cbc2c37 ee9183a5
No related branches found
No related tags found
2 merge requests!10622.7 Release,!1053test(rtl): options
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react' import userEvent from '@testing-library/user-event'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import ExportDoneModal from './exportDoneModal' import ExportDoneModal from './exportDoneModal'
...@@ -19,16 +18,16 @@ describe('exportDoneModal component', () => { ...@@ -19,16 +18,16 @@ describe('exportDoneModal component', () => {
expect(baseElement).toMatchSnapshot() expect(baseElement).toMatchSnapshot()
}) })
it('should close modal', () => { it('should close modal', async () => {
const mockHandleClose = jest.fn() const mockHandleClose = jest.fn()
const wrapper = mount( render(
<ExportDoneModal <ExportDoneModal
open={true} open={true}
error={false} error={false}
handleCloseClick={mockHandleClose} handleCloseClick={mockHandleClose}
/> />
) )
wrapper.find(Button).first().simulate('click') await userEvent.click(screen.getAllByRole('button')[0])
expect(mockHandleClose).toHaveBeenCalledTimes(1) expect(mockHandleClose).toHaveBeenCalledTimes(1)
}) })
}) })
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react' import { userEvent } from '@testing-library/user-event'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { allFluids } from 'utils/utils' import { allFluids } from 'utils/utils'
import ExportLoadingModal from './exportLoadingModal' import ExportLoadingModal from './exportLoadingModal'
...@@ -18,9 +17,9 @@ describe('ExportLoadingModal component', () => { ...@@ -18,9 +17,9 @@ describe('ExportLoadingModal component', () => {
expect(baseElement).toMatchSnapshot() expect(baseElement).toMatchSnapshot()
}) })
it('should cancel download', () => { it('should cancel download', async () => {
const mockHandleClose = jest.fn() const mockHandleClose = jest.fn()
const wrapper = mount( render(
<ExportLoadingModal <ExportLoadingModal
open={true} open={true}
handleCloseClick={mockHandleClose} handleCloseClick={mockHandleClose}
...@@ -28,7 +27,7 @@ describe('ExportLoadingModal component', () => { ...@@ -28,7 +27,7 @@ describe('ExportLoadingModal component', () => {
selectedFluids={allFluids} selectedFluids={allFluids}
/> />
) )
wrapper.find(Button).first().simulate('click') await userEvent.click(screen.getAllByRole('button')[0])
expect(mockHandleClose).toHaveBeenCalledTimes(1) expect(mockHandleClose).toHaveBeenCalledTimes(1)
}) })
}) })
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react' import userEvent from '@testing-library/user-event'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import ExportStartModal from './exportStartModal' import ExportStartModal from './exportStartModal'
...@@ -16,16 +15,16 @@ describe('exportStartModal component', () => { ...@@ -16,16 +15,16 @@ describe('exportStartModal component', () => {
expect(baseElement).toMatchSnapshot() expect(baseElement).toMatchSnapshot()
}) })
it('should close modal', () => { it('should close modal', async () => {
const mockHandleClose = jest.fn() const mockHandleClose = jest.fn()
const wrapper = mount( render(
<ExportStartModal <ExportStartModal
open={true} open={true}
handleCloseClick={mockHandleClose} handleCloseClick={mockHandleClose}
handleDownloadClick={jest.fn()} handleDownloadClick={jest.fn()}
/> />
) )
wrapper.find(Button).first().simulate('click') await userEvent.click(screen.getAllByRole('button')[0])
expect(mockHandleClose).toHaveBeenCalledTimes(1) expect(mockHandleClose).toHaveBeenCalledTimes(1)
}) })
}) })
import profileIcon from 'assets/icons/ico/profile.svg' import { render, screen } from '@testing-library/react'
import StyledCard from 'components/CommonKit/Card/StyledCard' import { userEvent } from '@testing-library/user-event'
import StyledIcon from 'components/CommonKit/Icon/StyledIcon'
import ProfileTypeOptions from 'components/Options/ProfileTypeOptions/ProfileTypeOptions' import ProfileTypeOptions from 'components/Options/ProfileTypeOptions/ProfileTypeOptions'
import { import {
HousingType, HousingType,
...@@ -8,7 +7,6 @@ import { ...@@ -8,7 +7,6 @@ import {
IndividualOrCollective, IndividualOrCollective,
ThreeChoicesAnswer, ThreeChoicesAnswer,
} from 'enums' } from 'enums'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { mockProfileType } from 'tests/__mocks__/profileType.mock' import { mockProfileType } from 'tests/__mocks__/profileType.mock'
...@@ -18,18 +16,23 @@ import { ...@@ -18,18 +16,23 @@ import {
mockProfileState, mockProfileState,
} from 'tests/__mocks__/store' } from 'tests/__mocks__/store'
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigate,
}))
describe('ProfileTypeOptions component', () => { describe('ProfileTypeOptions component', () => {
const store = createMockEcolyoStore() const store = createMockEcolyoStore()
it('should be rendered correctly', () => { it('should be rendered correctly with profile NOT completed', async () => {
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<ProfileTypeOptions /> <ProfileTypeOptions />
</Provider> </Provider>
) )
expect(wrapper.find(StyledCard).exists()).toBeTruthy() expect(container.getElementsByClassName('profile-icon').length).toBeTruthy()
expect(wrapper.find(StyledIcon).exists()).toBeTruthy() await userEvent.click(screen.getByRole('button'))
expect(wrapper.find(profileIcon)).toBeTruthy() expect(mockedNavigate).toHaveBeenCalled()
wrapper.find('.profile-link').first().simulate('click')
}) })
it('should be rendered when user complete profile type form', () => { it('should be rendered when user complete profile type form', () => {
const store = createMockEcolyoStore({ const store = createMockEcolyoStore({
...@@ -37,12 +40,14 @@ describe('ProfileTypeOptions component', () => { ...@@ -37,12 +40,14 @@ describe('ProfileTypeOptions component', () => {
profileType: mockProfileType, profileType: mockProfileType,
challenge: mockChallengeState, challenge: mockChallengeState,
}) })
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<ProfileTypeOptions /> <ProfileTypeOptions />
</Provider> </Provider>
) )
expect(wrapper.find('.profile-container').exists()).toBeTruthy() expect(
container.getElementsByClassName('profile-container')[0]
).toBeInTheDocument()
}) })
it('should be rendered when housing_type = apartment', () => { it('should be rendered when housing_type = apartment', () => {
const store = createMockEcolyoStore({ const store = createMockEcolyoStore({
...@@ -50,12 +55,12 @@ describe('ProfileTypeOptions component', () => { ...@@ -50,12 +55,12 @@ describe('ProfileTypeOptions component', () => {
profileType: { ...mockProfileType, housingType: HousingType.APARTMENT }, profileType: { ...mockProfileType, housingType: HousingType.APARTMENT },
challenge: mockChallengeState, challenge: mockChallengeState,
}) })
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<ProfileTypeOptions /> <ProfileTypeOptions />
</Provider> </Provider>
) )
expect(wrapper.find('.floor').exists()).toBeTruthy() expect(container.getElementsByClassName('floor')[0]).toBeInTheDocument()
}) })
it('should display heating with equipments', () => { it('should display heating with equipments', () => {
const store = createMockEcolyoStore({ const store = createMockEcolyoStore({
...@@ -69,12 +74,14 @@ describe('ProfileTypeOptions component', () => { ...@@ -69,12 +74,14 @@ describe('ProfileTypeOptions component', () => {
}, },
challenge: mockChallengeState, challenge: mockChallengeState,
}) })
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<ProfileTypeOptions /> <ProfileTypeOptions />
</Provider> </Provider>
) )
expect(wrapper.find('.equipments').exists()).toBeTruthy() expect(
container.getElementsByClassName('equipments')[0]
).toBeInTheDocument()
}) })
it('should display insulation work', () => { it('should display insulation work', () => {
const store = createMockEcolyoStore({ const store = createMockEcolyoStore({
...@@ -92,11 +99,13 @@ describe('ProfileTypeOptions component', () => { ...@@ -92,11 +99,13 @@ describe('ProfileTypeOptions component', () => {
}, },
challenge: mockChallengeState, challenge: mockChallengeState,
}) })
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<ProfileTypeOptions /> <ProfileTypeOptions />
</Provider> </Provider>
) )
expect(wrapper.find('.insulation').exists()).toBeTruthy() expect(
container.getElementsByClassName('insulation')[0]
).toBeInTheDocument()
}) })
}) })
...@@ -48,6 +48,14 @@ const ProfileTypeOptions = () => { ...@@ -48,6 +48,14 @@ const ProfileTypeOptions = () => {
<div className="head text-16-normal-uppercase"> <div className="head text-16-normal-uppercase">
{t('profile_type.title_profile')} {t('profile_type.title_profile')}
</div> </div>
{!profile.isProfileTypeCompleted && (
<StyledCard onClick={goToForm} className="profile-link">
<StyledIcon className="profile-icon" icon={profileIcon} size={42} />
<span className="link-label text-16-normal">
{t('profile_type.read_profile')}
</span>
</StyledCard>
)}
{profile.isProfileTypeCompleted && ( {profile.isProfileTypeCompleted && (
<Accordion <Accordion
expanded={active} expanded={active}
...@@ -225,14 +233,6 @@ const ProfileTypeOptions = () => { ...@@ -225,14 +233,6 @@ const ProfileTypeOptions = () => {
</AccordionDetails> </AccordionDetails>
</Accordion> </Accordion>
)} )}
{!profile.isProfileTypeCompleted && (
<StyledCard onClick={goToForm} className="profile-link">
<StyledIcon className="profile-icon" icon={profileIcon} size={42} />
<span className="link-label text-16-normal">
{t('profile_type.read_profile')}
</span>
</StyledCard>
)}
</div> </div>
</div> </div>
) )
......
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import StyledSwitch from 'components/CommonKit/Switch/StyledSwitch' import { userEvent } from '@testing-library/user-event'
import ReportOptions from 'components/Options/ReportOptions/ReportOptions' import ReportOptions from 'components/Options/ReportOptions/ReportOptions'
import { FluidState, FluidType } from 'enums'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import * as profileActions from 'store/profile/profile.slice' import * as profileActions from 'store/profile/profile.slice'
import { fluidStatusConnectedData } from 'tests/__mocks__/fluidStatusData.mock'
import { import {
createMockEcolyoStore, createMockEcolyoStore,
mockInitialEcolyoState, mockGlobalState,
mockProfileState,
} from 'tests/__mocks__/store' } from 'tests/__mocks__/store'
const mockUpdateProfile = jest.fn() const mockUpdateProfile = jest.fn()
...@@ -27,67 +27,76 @@ describe('ReportOptions component', () => { ...@@ -27,67 +27,76 @@ describe('ReportOptions component', () => {
}) })
it('should be rendered with sendAnalysisNotification to true', () => { it('should be rendered with sendAnalysisNotification to true', () => {
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<ReportOptions /> <ReportOptions />
</Provider> </Provider>
) )
expect(wrapper.find(Button).text()).toBe('profile.report.deactivate') expect(screen.getByText('profile.report.deactivate')).toBeInTheDocument()
}) })
it('should update the profile with sendAnalysisNotification to false', () => { it('should update the profile with sendAnalysisNotification to false', async () => {
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<ReportOptions /> <ReportOptions />
</Provider> </Provider>
) )
wrapper.find(Button).first().simulate('click') await userEvent.click(screen.getAllByRole('button')[0])
expect(updateProfileSpy).toHaveBeenCalledTimes(1) expect(updateProfileSpy).toHaveBeenCalledTimes(1)
expect(updateProfileSpy).toHaveBeenCalledWith({ expect(updateProfileSpy).toHaveBeenCalledWith({
sendAnalysisNotification: false, sendAnalysisNotification: false,
}) })
}) })
it('should be rendered with sendAnalysisNotification false and toggle it to true', () => { it('should be rendered with sendAnalysisNotification false and toggle it to true', async () => {
mockInitialEcolyoState.profile.sendAnalysisNotification = false const store = createMockEcolyoStore({
global: mockGlobalState,
const wrapper = mount( profile: { ...mockProfileState, sendAnalysisNotification: false },
})
render(
<Provider store={store}> <Provider store={store}>
<ReportOptions /> <ReportOptions />
</Provider> </Provider>
) )
wrapper.find(Button).first().simulate('click') await userEvent.click(screen.getAllByRole('button')[0])
expect(updateProfileSpy).toHaveBeenCalledTimes(1) expect(updateProfileSpy).toHaveBeenCalledTimes(1)
expect(updateProfileSpy).toHaveBeenCalledWith({ expect(updateProfileSpy).toHaveBeenCalledWith({
sendAnalysisNotification: true, sendAnalysisNotification: true,
}) })
}) })
it('should be rendered with sendConsumptionAlert to false', () => { describe('should test water alert', () => {
mockInitialEcolyoState.profile.sendAnalysisNotification = false const storeWaterDone = createMockEcolyoStore({
mockInitialEcolyoState.global.fluidStatus[FluidType.WATER].status = global: { ...mockGlobalState, fluidStatus: fluidStatusConnectedData },
FluidState.DONE profile: { sendAnalysisNotification: false },
const wrapper = mount( })
<Provider store={store}> it('should be rendered with sendConsumptionAlert to false and enable it', async () => {
<ReportOptions /> render(
</Provider> <Provider store={storeWaterDone}>
) <ReportOptions />
expect(wrapper.find(StyledSwitch)).toHaveLength(1) </Provider>
expect(wrapper.find(StyledSwitch).first().props().checked).toBeFalsy() )
}) expect(screen.getByRole('checkbox')).not.toBeChecked()
await userEvent.click(screen.getByRole('checkbox'))
expect(updateProfileSpy).toHaveBeenCalledTimes(1)
expect(updateProfileSpy).toHaveBeenCalledWith({
sendConsumptionAlert: true,
})
})
it('should update the profile with sendConsumptionAlert to true', () => { it('should render waterLimit to 100', async () => {
const wrapper = mount( const storeWaterAlert = createMockEcolyoStore({
<Provider store={store}> global: { ...mockGlobalState, fluidStatus: fluidStatusConnectedData },
<ReportOptions /> profile: {
</Provider> sendConsumptionAlert: true,
) waterDailyConsumptionLimit: 100,
wrapper },
.find('input') })
.first() render(
.simulate('change', { target: { checked: 'true' } }) <Provider store={storeWaterAlert}>
expect(updateProfileSpy).toHaveBeenCalledTimes(1) <ReportOptions />
expect(updateProfileSpy).toHaveBeenCalledWith({ </Provider>
sendConsumptionAlert: true, )
expect(screen.getByRole('spinbutton')).toHaveValue(100)
}) })
}) })
}) })
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react' import userEvent from '@testing-library/user-event'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import * as profileActions from 'store/profile/profile.slice' import * as profileActions from 'store/profile/profile.slice'
...@@ -39,13 +38,13 @@ describe('UnSubscribe component', () => { ...@@ -39,13 +38,13 @@ describe('UnSubscribe component', () => {
expect(container).toMatchSnapshot() expect(container).toMatchSnapshot()
}) })
it('should click on button and deactivate report', () => { it('should click on button and deactivate report', async () => {
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<UnSubscribeView /> <UnSubscribeView />
</Provider> </Provider>
) )
wrapper.find(Button).simulate('click') await userEvent.click(screen.getByRole('button'))
expect(updateProfileSpy).toHaveBeenCalledWith({ expect(updateProfileSpy).toHaveBeenCalledWith({
sendAnalysisNotification: false, sendAnalysisNotification: false,
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment