Commit 5f2d0535 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

fix(ecogestures): Update ecogesture profile and profiletype properly

parent eca5ef46
......@@ -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')
}
......
......@@ -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 && (
......
......@@ -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')
})
})
......@@ -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)
......
......@@ -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,
......
......@@ -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 **/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment