diff --git a/src/components/EcogestureForm/EcogestureFormEquipment.tsx b/src/components/EcogestureForm/EcogestureFormEquipment.tsx index 857f575a6383a374013fd4145c76611ee1317532..8f0524dbd29ef957a45f40723e1ccb4903861424 100644 --- a/src/components/EcogestureForm/EcogestureFormEquipment.tsx +++ b/src/components/EcogestureForm/EcogestureFormEquipment.tsx @@ -7,7 +7,10 @@ import { ProfileEcogesture } from 'models/profileEcogesture.model' import { EquipmentType } from 'enum/ecogesture.enum' import EquipmentIcon from './EquipmentIcon' import './ecogestureFormEquipment.scss' -import { newProfileEcogestureEntry } from 'store/profileEcogesture/profileEcogesture.actions' +import { + newProfileEcogestureEntry, + updateProfileEcogesture, +} from 'store/profileEcogesture/profileEcogesture.actions' import { useDispatch, useSelector } from 'react-redux' import { updateProfile } from 'store/profile/profile.actions' import { useHistory } from 'react-router-dom' @@ -43,11 +46,12 @@ const EcogestureFormEquipment: React.FC<EcogestureFormEquipmentProps> = ({ const handleNext = useCallback(() => { profileEcogesture.equipments = answer as EquipmentType[] - dispatch(newProfileEcogestureEntry(profileEcogesture)) // Check if gestureForm is used from Big profile or small profile if (setNextStep) { setNextStep() + dispatch(updateProfileEcogesture(profileEcogesture)) } else { + dispatch(newProfileEcogestureEntry(profileEcogesture)) dispatch(updateProfile({ isProfileEcogestureCompleted: true })) history.push('/ecogesture-selection') } diff --git a/src/components/EcogestureForm/EcogestureFormView.tsx b/src/components/EcogestureForm/EcogestureFormView.tsx index 18812975d292be79358555e9dd838169b6e434ae..cb07519ce15b54b21fb914f1e883c49c65011351 100644 --- a/src/components/EcogestureForm/EcogestureFormView.tsx +++ b/src/components/EcogestureForm/EcogestureFormView.tsx @@ -20,11 +20,10 @@ import ProfileEcogestureFormService from 'services/profileEcogestureForm.service import StyledSpinner from 'components/CommonKit/Spinner/StyledSpinner' import { FluidType } from 'enum/fluid.enum' import './ecogestureFormView.scss' -import { useHistory, useLocation } from 'react-router-dom' +import { useLocation } from 'react-router-dom' import ProfileTypeView from 'components/ProfileType/ProfileTypeView' const EcogestureFormView: React.FC = () => { - const history = useHistory() const [headerHeight, setHeaderHeight] = useState<number>(0) const defineHeaderHeight = (height: number) => { setHeaderHeight(height) @@ -111,9 +110,7 @@ const EcogestureFormView: React.FC = () => { ></Header> <Content height={headerHeight}> {isProfileTypeCompleted ? ( - <ProfileTypeView - handleEnd={() => history.push('/ecogesture-selection')} - /> + <ProfileTypeView /> ) : ( <> {step === EcogestureStepForm.EQUIPMENTS && ( diff --git a/src/components/ProfileType/ProfileTypeFinished.spec.tsx b/src/components/ProfileType/ProfileTypeFinished.spec.tsx index 5500282f8580a31156513f7f51cd4f14d101115d..60f540a189cae15d509f1f49d466241cf8dc1b3a 100644 --- a/src/components/ProfileType/ProfileTypeFinished.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFinished.spec.tsx @@ -7,7 +7,21 @@ import { } from '../../../tests/__mocks__/store' import ProfileTypeFinished from './ProfileTypeFinished' import { mockProfileType } from '../../../tests/__mocks__/profileType.mock' +import { Button } from '@material-ui/core' +const mockHistoryGoBack = jest.fn() +const mockHistoryPush = jest.fn() + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useLocation: () => ({ + pathname: '/ecogesture-form', + }), + useHistory: () => ({ + goBack: mockHistoryGoBack, + push: mockHistoryPush, + }), +})) jest.mock('cozy-ui/transpiled/react/I18n', () => { return { useI18n: jest.fn(() => { @@ -18,14 +32,18 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { } }) -describe('ProfileTypeView component', () => { +describe('ProfileTypeFinished component', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let store: any beforeEach(() => { + jest.clearAllMocks() store = createMockStore(mockInitialEcolyoState) }) + afterEach(() => { + jest.clearAllMocks() + }) - it('should be rendered correctly', () => { + it('should be rendered correctly', async () => { const wrapper = mount( <Provider store={store}> <ProfileTypeFinished profileType={mockProfileType} /> @@ -33,4 +51,16 @@ describe('ProfileTypeView component', () => { ) expect(wrapper.find('profile-type-finished-card')).toBeTruthy() }) + it('should go to ecogesture selection', () => { + const wrapper = mount( + <Provider store={store}> + <ProfileTypeFinished profileType={mockProfileType} /> + </Provider> + ) + wrapper + .find(Button) + .first() + .simulate('click') + expect(mockHistoryPush).toHaveBeenCalledWith('/ecogesture-selection') + }) }) diff --git a/src/components/ProfileType/ProfileTypeFinished.tsx b/src/components/ProfileType/ProfileTypeFinished.tsx index 714438c7fd798ead16b92fbcb12c4a4516e94e3d..be6a82b0c28f9351c09d2526f2240e8cef9e9ae1 100644 --- a/src/components/ProfileType/ProfileTypeFinished.tsx +++ b/src/components/ProfileType/ProfileTypeFinished.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react' import 'components/ProfileType/profileTypeFinished.scss' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useDispatch, useSelector } from 'react-redux' -import { useHistory } from 'react-router-dom' +import { useHistory, useLocation } from 'react-router-dom' import { updateProfile } from 'store/profile/profile.actions' import { newProfileTypeEntry } from 'store/profileType/profileType.actions' import { ProfileType } from 'models/profileType.model' @@ -28,6 +28,7 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({ profileType, }: ProfileTypeFinishedProps) => { const { t } = useI18n() + const location = useLocation() const dispatch = useDispatch() const history = useHistory() const client = useClient() @@ -35,7 +36,11 @@ const ProfileTypeFinished: React.FC<ProfileTypeFinishedProps> = ({ (state: AppStore) => state.ecolyo.challenge ) const handleClick = () => { - history.goBack() + if (location && location.pathname === '/ecogesture-form') { + history.push('/ecogesture-selection') + } else { + history.goBack() + } } const [isSaved, setIsSaved] = useState<boolean>(false) diff --git a/src/components/ProfileType/ProfileTypeView.tsx b/src/components/ProfileType/ProfileTypeView.tsx index 40bfbdef84d4997c2daa6d9836fd305039685c3c..8d43c4f1f7d9fd414e75fe17013e87be23ce6bcb 100644 --- a/src/components/ProfileType/ProfileTypeView.tsx +++ b/src/components/ProfileType/ProfileTypeView.tsx @@ -32,13 +32,7 @@ import ProfileTypeFormDateSelection from './ProfileTypeFormDateSelection' import EcogestureFormEquipment from 'components/EcogestureForm/EcogestureFormEquipment' import { ProfileEcogesture } from 'models/profileEcogesture.model' -interface ProfileTypeViewProps { - handleEnd: Function -} - -const ProfileTypeView: React.FC<ProfileTypeViewProps> = ({ - handleEnd, -}: ProfileTypeViewProps) => { +const ProfileTypeView: React.FC = () => { const profile = useSelector((state: AppStore) => state.ecolyo.profile) const curProfileType = useSelector( (state: AppStore) => state.ecolyo.profileType @@ -107,9 +101,6 @@ const ProfileTypeView: React.FC<ProfileTypeViewProps> = ({ step, !profile.isProfileTypeCompleted ) - if (nextStep === ProfileTypeStepForm.END && handleEnd) { - handleEnd() - } setIsLoading(true) if (nextStep > viewedStep) { setViewedStep(nextStep) @@ -118,7 +109,6 @@ const ProfileTypeView: React.FC<ProfileTypeViewProps> = ({ }, [ curProfileEcogesture, - handleEnd, profile.isProfileTypeCompleted, profileType, step, diff --git a/src/styles/index.css b/src/styles/index.css index 9e1b70aab157ae4e9f6c485cc9310d15b259c173..f6c38b90351ff7c47bba17d78ceddf621c575ef5 100644 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -6,6 +6,7 @@ /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -172,6 +173,7 @@ body { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -182,6 +184,7 @@ body { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -651,6 +654,7 @@ p { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -941,6 +945,7 @@ p { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1160,6 +1165,7 @@ button.btn-profile-back { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1185,6 +1191,7 @@ button.btn-profile-back { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1260,6 +1267,7 @@ div.modal-paper-full-screen { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/ @@ -1324,6 +1332,7 @@ div.expansion-panel-details { /** BLACK **/ /** RED **/ /** YELLOW **/ +/** ORANGE **/ /** BLUE **/ /** GREEN **/ /** WHITE **/