diff --git a/src/components/Home/ConsumptionDetails.spec.tsx b/src/components/Home/ConsumptionDetails.spec.tsx index 01b67448ebd5f6c648b246881716b8d21a92e2d2..1784cd6794e0ea1dbc30f66f7862e5e6f40140ff 100644 --- a/src/components/Home/ConsumptionDetails.spec.tsx +++ b/src/components/Home/ConsumptionDetails.spec.tsx @@ -1,10 +1,17 @@ import React from 'react' -import { mount, shallow } from 'enzyme' +import { mount } from 'enzyme' import ConsumptionDetails from './ConsumptionDetails' import * as reactRedux from 'react-redux' -import { globalStateData } from '../../../test/__mocks__/globalStateData.mock' import { TimeStep } from 'enum/timeStep.enum' import { FluidType } from 'enum/fluid.enum' +import { + createMockStore, + mockInitialChartState, + mockInitialEcolyoState, + mockInitialGlobalState, +} from '../../../test/__mocks__/store' +import { Provider } from 'react-redux' +import { BrowserRouter } from 'react-router-dom' jest.mock('cozy-ui/transpiled/react/I18n', () => { return { @@ -16,55 +23,87 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { } }) -jest.mock( - 'components/Konnector/KonnectorViewerCard', - () => 'KonnectorViewerCard' -) -const setIndicatorsLoaded = jest.fn() - const mockUseSelector = jest.spyOn(reactRedux, 'useSelector') -describe('HomeIndicators component', () => { +describe('ConsumptionDetails component', () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let store: any + beforeEach(() => { + store = createMockStore(mockInitialEcolyoState) mockUseSelector.mockClear() - setIndicatorsLoaded.mockClear() }) it('should be rendered correctly', () => { - mockUseSelector.mockReturnValueOnce(globalStateData) - const component = shallow( - <ConsumptionDetails - timeStep={TimeStep.DAY} - setIndicatorsLoaded={setIndicatorsLoaded} - /> - ).getElement() - expect(component).toMatchSnapshot() + mockUseSelector.mockReturnValue({ + fluidStatus: mockInitialGlobalState.fluidStatus, + fluidTypes: [FluidType.ELECTRICITY], + selectedDate: mockInitialChartState.selectedDate, + currentTimeStep: TimeStep.WEEK, + currentIndex: mockInitialChartState.currentIndex, + currentDatachart: mockInitialChartState.currentDatachart, + }) + const wrapper = mount( + <Provider store={store}> + <BrowserRouter> + <ConsumptionDetails fluidType={FluidType.ELECTRICITY} /> + </BrowserRouter> + </Provider> + ) + expect(wrapper).toMatchSnapshot() }) + it('should not render connection card ', () => { - const updatedState = { - ...globalStateData, - fluidStatus: [FluidType.ELECTRICITY, FluidType.GAS, FluidType.WATER], - } - mockUseSelector.mockReturnValue(updatedState) + mockUseSelector.mockReturnValue({ + fluidStatus: mockInitialGlobalState.fluidStatus, + fluidTypes: [FluidType.ELECTRICITY, FluidType.GAS, FluidType.WATER], + selectedDate: mockInitialChartState.selectedDate, + currentTimeStep: TimeStep.WEEK, + currentIndex: mockInitialChartState.currentIndex, + currentDatachart: mockInitialChartState.currentDatachart, + }) const wrapper = mount( - <ConsumptionDetails - timeStep={TimeStep.DAY} - setIndicatorsLoaded={setIndicatorsLoaded} - /> + <Provider store={store}> + <BrowserRouter> + <ConsumptionDetails fluidType={FluidType.MULTIFLUID} /> + </BrowserRouter> + </Provider> ) - expect(wrapper.contains('fluidcard-link')).toBeFalsy() + expect(wrapper.contains('.fluidcard-link')).toBeFalsy() }) it('should render one connection card ', () => { - const updatedState = { - ...globalStateData, - fluidStatus: [FluidType.ELECTRICITY, FluidType.GAS], - } - mockUseSelector.mockReturnValue(updatedState) + mockUseSelector.mockReturnValue({ + fluidStatus: mockInitialGlobalState.fluidStatus, + fluidTypes: [FluidType.ELECTRICITY, FluidType.GAS], + selectedDate: mockInitialChartState.selectedDate, + currentTimeStep: TimeStep.WEEK, + currentIndex: mockInitialChartState.currentIndex, + currentDatachart: mockInitialChartState.currentDatachart, + }) + const wrapper = mount( + <Provider store={store}> + <BrowserRouter> + <ConsumptionDetails fluidType={FluidType.MULTIFLUID} /> + </BrowserRouter> + </Provider> + ) + expect(wrapper.find('.fluidcard-link')).toBeTruthy() + }) + it('should not render connection card and show multifluid link', () => { + mockUseSelector.mockReturnValue({ + fluidStatus: mockInitialGlobalState.fluidStatus, + fluidTypes: [FluidType.ELECTRICITY, FluidType.GAS], + selectedDate: mockInitialChartState.selectedDate, + currentTimeStep: TimeStep.WEEK, + currentIndex: mockInitialChartState.currentIndex, + currentDatachart: mockInitialChartState.currentDatachart, + }) const wrapper = mount( - <ConsumptionDetails - timeStep={TimeStep.DAY} - setIndicatorsLoaded={setIndicatorsLoaded} - /> + <Provider store={store}> + <BrowserRouter> + <ConsumptionDetails fluidType={FluidType.ELECTRICITY} /> + </BrowserRouter> + </Provider> ) - expect(wrapper.find('fluidcard-link')).toBeTruthy() + expect(wrapper.find('.multi-link')).toBeTruthy() }) }) diff --git a/src/components/Home/ConsumptionDetails.tsx b/src/components/Home/ConsumptionDetails.tsx index b800d2bfcba8b1cf1053dfdba045f858236444e9..dc6646ffa1299fbc67b8b1a0549f9a3e8ceb69ad 100644 --- a/src/components/Home/ConsumptionDetails.tsx +++ b/src/components/Home/ConsumptionDetails.tsx @@ -93,7 +93,7 @@ const ConsumptionDetails: React.FC<ConsumptionDetailsProps> = ({ <div className="text-16-normal-uppercase details-title"> {t('COMMON.MINI_CARDS_LABEL')} </div> - <div className="details-container"> + <div className="details-container multi-link"> <FluidCard fluidType={FluidType.MULTIFLUID} /> {fluidConfig.map((fluid, index) => { return fluidType !== fluid.fluidTypeId && diff --git a/src/components/Home/__snapshots__/ConsumptionDetails.spec.tsx.snap b/src/components/Home/__snapshots__/ConsumptionDetails.spec.tsx.snap new file mode 100644 index 0000000000000000000000000000000000000000..b419df1dbe9acf8bf737c0194c47855854f814be --- /dev/null +++ b/src/components/Home/__snapshots__/ConsumptionDetails.spec.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ConsumptionDetails component should be rendered correctly 1`] = `ReactWrapper {}`; diff --git a/src/components/HomeCards/AddKonnectorCard.spec.tsx b/src/components/HomeCards/AddKonnectorCard.spec.tsx index 343bce53e05e565d7d4c152eadd518e1a8842b8c..236eb909e07f604daa721ab01d0d546e254f79d0 100644 --- a/src/components/HomeCards/AddKonnectorCard.spec.tsx +++ b/src/components/HomeCards/AddKonnectorCard.spec.tsx @@ -16,7 +16,7 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { }) describe('AddKonnectorCard component', () => { - it('should be rendered correctly with water connexion', () => { + it('should be rendered correctly', () => { const component = shallow( <AddKonnectorCard fluidType={FluidType.ELECTRICITY} @@ -25,4 +25,15 @@ describe('AddKonnectorCard component', () => { ).getElement() expect(component).toMatchSnapshot() }) + it('should be rendered with Elec connexion', () => { + const component = shallow( + <AddKonnectorCard + fluidType={FluidType.ELECTRICITY} + fluidStatus={fluidStatusData[0]} + /> + ) + expect(component.find('.add-konnector-title').text()).toContain( + 'ELECTRICITY' + ) + }) }) diff --git a/src/components/HomeCards/FluidCard.spec.tsx b/src/components/HomeCards/FluidCard.spec.tsx index 47db95d124a8fafeb66d3577b90bd15a81f1fde0..9019702f8bff3337a98ea8e84d4dcaf92b799e5f 100644 --- a/src/components/HomeCards/FluidCard.spec.tsx +++ b/src/components/HomeCards/FluidCard.spec.tsx @@ -1,8 +1,5 @@ import React from 'react' import { shallow } from 'enzyme' -import * as reactRedux from 'react-redux' -import { globalStateData } from '../../../test/__mocks__/globalStateData.mock' -import { TimeStep } from 'enum/timeStep.enum' import FluidCard from './FluidCard' import { FluidType } from 'enum/fluid.enum' @@ -24,9 +21,7 @@ describe('FluidCard component', () => { expect(component).toMatchSnapshot() }) it('should be rendered multifluid', () => { - const component = shallow( - <FluidCard fluidType={FluidType.MULTIFLUID} /> - ).getElement() - expect(component).toMatchSnapshot() + const component = shallow(<FluidCard fluidType={FluidType.MULTIFLUID} />) + expect(component.find('.mutlifluid')).toBeTruthy() }) }) diff --git a/src/components/HomeCards/TotalConsumption.spec.tsx b/src/components/HomeCards/TotalConsumption.spec.tsx index 18d21709c843f7d06e1b0d3ea8001dfcbdf14221..76b499c5cf0b5d862d3ab316d1ca5df9a0e657c3 100644 --- a/src/components/HomeCards/TotalConsumption.spec.tsx +++ b/src/components/HomeCards/TotalConsumption.spec.tsx @@ -1,10 +1,9 @@ import React from 'react' -import { shallow } from 'enzyme' -import * as reactRedux from 'react-redux' -import { globalStateData } from '../../../test/__mocks__/globalStateData.mock' -import { TimeStep } from 'enum/timeStep.enum' +import { mount } from 'enzyme' import { FluidType } from 'enum/fluid.enum' import TotalConsumption from './TotalConsumption' +import { mockInitialChartState } from '../../../test/__mocks__/store' +import { graphData } from '../../../test/__mocks__/datachartData.mock' jest.mock('cozy-ui/transpiled/react/I18n', () => { return { @@ -17,10 +16,49 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { }) describe('TotalConsumption component', () => { - // it('should be rendered correctly', () => { - // const component = shallow( - // <TotalConsumption fluidType={FluidType.ELECTRICITY} /> - // ).getElement() - // expect(component).toMatchSnapshot() - // }) + it('should be rendered correctly', () => { + const component = mount( + <TotalConsumption + fluidType={FluidType.ELECTRICITY} + actualData={mockInitialChartState.currentDatachart.actualData} + /> + ) + expect(component).toMatchSnapshot() + }) + it('should render euro value', () => { + const component = mount( + <TotalConsumption + fluidType={FluidType.ELECTRICITY} + actualData={graphData.actualData} + /> + ) + expect( + component + .find('.euro-value') + .first() + .text() + ).toEqual('20.23') + }) + it('should call Converter method', () => { + const mockLoadToEuro = jest.fn() + jest.mock('services/converter.service', () => { + return jest.fn(() => { + return { + loadToEuro: mockLoadToEuro, + } + }) + }) + const component = mount( + <TotalConsumption + fluidType={FluidType.MULTIFLUID} + actualData={graphData.actualData} + /> + ) + expect( + component + .find('.euro-value') + .first() + .text() + ).toEqual('130.84') + }) }) diff --git a/src/components/HomeCards/__snapshots__/AddKonnectorCard.spec.tsx.snap b/src/components/HomeCards/__snapshots__/AddKonnectorCard.spec.tsx.snap index b4b938c7dba81659b77e4cb231475ebe14b39eeb..d269ca97e0c8264e36cbdcd4418e05100da3c27b 100644 --- a/src/components/HomeCards/__snapshots__/AddKonnectorCard.spec.tsx.snap +++ b/src/components/HomeCards/__snapshots__/AddKonnectorCard.spec.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AddKonnectorCard component should be rendered correctly with water connexion 1`] = ` +exports[`AddKonnectorCard component should be rendered correctly 1`] = ` <ForwardRef className="fluidcard-link" to="/options/0" diff --git a/src/components/HomeCards/__snapshots__/FluidCard.spec.tsx.snap b/src/components/HomeCards/__snapshots__/FluidCard.spec.tsx.snap index 796e57e2433676b0f6a7f82502bf6a696d3ad8c5..92b3bfc6c85fbdf9d8a76571b73c870acdeced58 100644 --- a/src/components/HomeCards/__snapshots__/FluidCard.spec.tsx.snap +++ b/src/components/HomeCards/__snapshots__/FluidCard.spec.tsx.snap @@ -22,26 +22,3 @@ exports[`FluidCard component should be rendered correctly 1`] = ` </StyledCard> </ForwardRef> `; - -exports[`FluidCard component should be rendered multifluid 1`] = ` -<ForwardRef - className="fluidcard-link" - to="/consumption" -> - <StyledCard - className="fluidcard-content" - fluidType={3} - > - <StyledIcon - className="fluidcard-icon" - icon="test-file-stub" - size={50} - /> - <div - className="fluidcard-title multifluid" - > - FLUID.MULTIFLUID.LABEL - </div> - </StyledCard> -</ForwardRef> -`; diff --git a/src/components/HomeCards/__snapshots__/TotalConsumption.spec.tsx.snap b/src/components/HomeCards/__snapshots__/TotalConsumption.spec.tsx.snap new file mode 100644 index 0000000000000000000000000000000000000000..3a565c6656bae3808174e19bca79707febf5a9be --- /dev/null +++ b/src/components/HomeCards/__snapshots__/TotalConsumption.spec.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TotalConsumption component should be rendered correctly 1`] = `ReactWrapper {}`; diff --git a/src/services/dateChart.service.ts b/src/services/dateChart.service.ts index 04eb16f927a4ce6499f91ef686aae8ac6b33c929..03ede85e0ba1fd1c43cde5a93d7eadb2c857d9d0 100644 --- a/src/services/dateChart.service.ts +++ b/src/services/dateChart.service.ts @@ -80,6 +80,7 @@ export default class DateChartService { endDate: date.plus({ days: -1 * index }), } default: + console.log('ts', timeStep) throw new Error('TimeStep unknown') } }