diff --git a/src/components/Duel/DuelError.spec.tsx b/src/components/Duel/DuelError.spec.tsx index ac1dd002d555210e9a71807cb8ba5a0f9703c8d7..84528c4e7f10ac68a5fa21b0922a74fc38de4e72 100644 --- a/src/components/Duel/DuelError.spec.tsx +++ b/src/components/Duel/DuelError.spec.tsx @@ -12,8 +12,6 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { } }) -jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn()) - describe('DuelError component', () => { it('should be rendered correctly', () => { const component = shallow(<DuelError />).getElement diff --git a/src/components/Duel/DuelView.spec.tsx b/src/components/Duel/DuelView.spec.tsx index 6fa8250438d92c6b6f5e2b150b8306ed16bba7ff..94aceabddea64b8bc3a05c4b6e7c0056bc6bfaad 100644 --- a/src/components/Duel/DuelView.spec.tsx +++ b/src/components/Duel/DuelView.spec.tsx @@ -10,8 +10,6 @@ import DuelUnlocked from './DuelUnlocked' import DuelOngoing from './DuelOngoing' import { UserBossState } from 'enum/userBoss.enum' -jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn()) - const mockUseSelector = jest.spyOn(reactRedux, 'useSelector') describe('DuelView component', () => { diff --git a/src/components/Season/SeasonCard.spec.tsx b/src/components/Season/SeasonCard.spec.tsx index 68119d458e3116623bc9291ef85d6af6d7eed763..f3728e529c150b9c3c64d4d694feece02b99e39e 100644 --- a/src/components/Season/SeasonCard.spec.tsx +++ b/src/components/Season/SeasonCard.spec.tsx @@ -16,8 +16,6 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { } }) -jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn()) - describe('SeasonCard component', () => { it('should be rendered correctly', () => { const component = shallow( diff --git a/src/components/Season/SeasonCardDone.tsx b/src/components/Season/SeasonCardDone.tsx index 8aaf0f04cfa850d22f763f49d3f7a4efa88c1eeb..9f82232288ec22da07689bda9f8bffb20d958733 100644 --- a/src/components/Season/SeasonCardDone.tsx +++ b/src/components/Season/SeasonCardDone.tsx @@ -1,12 +1,13 @@ -import React, { useCallback } from 'react' +import React from 'react' import './seasonCardDone.scss' +import { useI18n } from 'cozy-ui/transpiled/react/I18n' +import classNames from 'classnames' +import { formatNumberValues } from 'utils/utils' import { UserSeason } from 'models' import iconSuccess from 'assets/png/seasons/beariconSuccess.png' import iconAlmost from 'assets/png/seasons/bearx.png' import { UserSeasonSuccess } from 'enum/userSeason.enum' import { DateTime } from 'luxon' -import { formatNumberValues } from 'utils/utils' -import { useI18n } from 'cozy-ui/transpiled/react/I18n' interface SeasonCardDoneProps { userSeason: UserSeason @@ -16,13 +17,12 @@ const SeasonCardDone: React.FC<SeasonCardDoneProps> = ({ userSeason, }: SeasonCardDoneProps) => { const { t } = useI18n() - const getNumberDayProgress = useCallback((localUserSeason: UserSeason) => { - if ( - localUserSeason.startDate !== null && - localUserSeason.endingDate !== null - ) { - const startDate = DateTime.fromISO(localUserSeason.startDate) - const endDate = DateTime.fromISO(localUserSeason.endingDate) + + // TODO Use pluarality of I18n + const getNumberDayProgress = (_userSeason: UserSeason) => { + if (_userSeason.startDate !== null && _userSeason.endingDate !== null) { + const startDate: DateTime = _userSeason.startDate + const endDate: DateTime = _userSeason.endingDate const delta = endDate.diff(startDate, 'days').toObject() if (delta && delta.days !== undefined) { @@ -34,44 +34,42 @@ const SeasonCardDone: React.FC<SeasonCardDoneProps> = ({ return ' ' + delta.days + ' ' + label } } else return '' - }, []) - const getUserSaving = useCallback((localUserSeason: UserSeason) => { + } + + const getUserSaving = (_userSeason: UserSeason) => { let label - if (localUserSeason.boss.threshold > localUserSeason.boss.userConsumption) + if (_userSeason.success === UserSeasonSuccess.WIN) label = t('season.card_done.saving') else label = t('season.card_done.depense') return ( label + + ' ' + formatNumberValues( - Math.abs( - localUserSeason.boss.threshold - localUserSeason.boss.userConsumption - ) + Math.abs(_userSeason.boss.threshold - _userSeason.boss.userConsumption) ) + '€' ) - }, []) - const getResultLabel = useCallback( - (localUserSeason: UserSeason, className = false) => { - switch (localUserSeason.success) { - case UserSeasonSuccess.WIN: - return className ? 'labelResult win' : t('season.card_done.win') - case UserSeasonSuccess.ALMOST_WIN: - return className - ? 'labelResult almostWin' - : t('season.card_done.almostWin') - case UserSeasonSuccess.LOST: - return className ? 'labelResult lost' : t('season.card_done.lost') - } - }, - [] - ) - const getIcon = useCallback((localUserSeason: UserSeason) => { + } + + const getResultLabel = (_userSeason: UserSeason) => { + switch (_userSeason.success) { + case UserSeasonSuccess.WIN: + return t('season.card_done.win') + case UserSeasonSuccess.ALMOST_WIN: + return t('season.card_done.almostWin') + case UserSeasonSuccess.LOST: + return t('season.card_done.lost') + } + } + + const getIcon = (_userSeason: UserSeason) => { let icon - if (localUserSeason.success == UserSeasonSuccess.WIN) icon = iconSuccess + if (_userSeason.success == UserSeasonSuccess.WIN) icon = iconSuccess else icon = iconAlmost return icon - }, []) + } + return ( <div className="cardContent cardDone"> <div className="headerCard">{t('season.card.title')}</div> @@ -79,7 +77,13 @@ const SeasonCardDone: React.FC<SeasonCardDoneProps> = ({ <div className="iconResult"> <img src={getIcon(userSeason)} className="imgResult" /> </div> - <div className={getResultLabel(userSeason, true)}> + <div + className={classNames('labelResult', { + ['win']: userSeason.success === UserSeasonSuccess.WIN, + ['almostWin']: userSeason.success === UserSeasonSuccess.ALMOST_WIN, + ['lost']: userSeason.success === UserSeasonSuccess.LOST, + })} + > {getResultLabel(userSeason)} </div> <div className="statsResult"> diff --git a/src/components/Season/SeasonCardUnlocked.spec.tsx b/src/components/Season/SeasonCardUnlocked.spec.tsx index dfa739de7ebbc5fe9f512241fa57e32d401245d3..bdc16a1c8d298e2f43f9458a18d9cd53f23c0eee 100644 --- a/src/components/Season/SeasonCardUnlocked.spec.tsx +++ b/src/components/Season/SeasonCardUnlocked.spec.tsx @@ -1,9 +1,12 @@ import React from 'react' -import { shallow } from 'enzyme' +import { mount } from 'enzyme' +import { Provider } from 'react-redux' +import configureStore from 'redux-mock-store' import SeasonCardUnlocked from './SeasonCardUnlocked' import { userSeasonData } from '../../../test/__mocks__/userSeasonData.mock' import { globalStateData } from '../../../test/__mocks__/globalStateData.mock' -import StyledButtonValid from 'components/CommonKit/Button/StyledButtonValid' +import SeasonNoFluidModal from './SeasonNoFluidModal' +import { FluidType } from 'enum/fluid.enum' jest.mock('cozy-ui/transpiled/react/I18n', () => { return { @@ -14,34 +17,69 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { }), } }) -jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn()) -const mocklaunchSeason = jest.fn() -const mockUseSelector = globalStateData -jest.mock('react-redux', () => ({ - useSelector: jest.fn().mockResolvedValue(mockUseSelector), - useDispatch: () => jest.fn(), -})) +const mockStartUserSeason = jest.fn() +jest.mock('services/season.service', () => { + return jest.fn(() => { + return { + startUserSeason: mockStartUserSeason, + } + }) +}) + +const mockStore = configureStore([]) //TODO fix click test describe('SeasonCardUnlocked component', () => { it('should be rendered correctly', () => { - const component = shallow( - <SeasonCardUnlocked userSeason={userSeasonData[0]} /> - ).getElement() - expect(component).toMatchSnapshot() + const store = mockStore({ + global: globalStateData, + }) + const wrapper = mount( + <Provider store={store}> + <SeasonCardUnlocked userSeason={userSeasonData[0]} /> + </Provider> + ) + expect(wrapper.find('.title').exists()).toBeTruthy() + expect(wrapper.find('.seasonTitle').text()).toEqual(userSeasonData[0].title) + expect(wrapper.find('.launchButton').exists()).toBeTruthy() + expect(wrapper.find(SeasonNoFluidModal).exists()).toBeTruthy() + }) + + it('should display SeasonNoFluidModal when launching season without configured fluid', () => { + const store = mockStore({ + global: globalStateData, + }) + const wrapper = mount( + <Provider store={store}> + <SeasonCardUnlocked userSeason={userSeasonData[0]} /> + </Provider> + ) + wrapper + .find('.launchButton') + .first() + .simulate('click') + expect(wrapper.find('.modal-opened').exists()).toBeTruthy() }) - it('should launch the season', () => { - const wrapper = shallow( - <SeasonCardUnlocked userSeason={userSeasonData[0]} /> + it('should not display SeasonNoFluidModal and update userSeason when launching season with configured fluid', () => { + const updateGlobalStoreData = { + ...globalStateData, + fluidTypes: [FluidType.ELECTRICITY], + } + const store = mockStore({ + global: updateGlobalStoreData, + }) + const wrapper = mount( + <Provider store={store}> + <SeasonCardUnlocked userSeason={userSeasonData[0]} /> + </Provider> ) wrapper - .find(StyledButtonValid) + .find('.launchButton') .first() .simulate('click') - console.log('button', wrapper.find(StyledButtonValid).first()) - expect(mocklaunchSeason).toHaveBeenCalled() + expect(wrapper.find('.modal-opened').exists()).toBeFalsy() + expect(mockStartUserSeason).toHaveBeenCalledWith(userSeasonData[0]) }) - // it('should open the fluid modal', () => {}) }) diff --git a/src/components/Season/SeasonView.spec.tsx b/src/components/Season/SeasonView.spec.tsx index 02a0159ef274c7d5c3403414e137914a47f44dbb..eff88b040d57fc5e05e4fb888aa24e6996f0d8c1 100644 --- a/src/components/Season/SeasonView.spec.tsx +++ b/src/components/Season/SeasonView.spec.tsx @@ -1,38 +1,16 @@ import React from 'react' import { shallow } from 'enzyme' import SeasonView from 'components/Season/SeasonView' +import * as reactRedux from 'react-redux' import { seasonStateDataFull } from '../../../test/__mocks__/seasonStateData.mock' -const mockaHandleTouchStart = jest.fn() -// const mockaHandleTouchMove = jest.fn() -// const mockaHandleTouchEnd = jest.fn() - -const mockUseSelector = seasonStateDataFull -jest.mock('@material-ui/core/styles/createMuiTheme', () => jest.fn()) - -jest.mock('react-redux', () => ({ - useSelector: jest.fn().mockResolvedValue(mockUseSelector), - useDispatch: () => jest.fn(), -})) +const mockUseSelector = jest.spyOn(reactRedux, 'useSelector') //TODO fix error userseasonlist undefined describe('SeasonView component', () => { it('should be rendered correctly', () => { + mockUseSelector.mockReturnValue(seasonStateDataFull) const component = shallow(<SeasonView />).getElement() expect(component).toMatchSnapshot() }) - // it('should detect user swipe on slider', () => { - // const wrapper = shallow(<SeasonView />) - // // TODO how to simulate Touch event in jest - // wrapper.find('.seasonSlider').simulate('touchStart', { - // targetTouches: [ - // { - // clientX: 50, - // }, - // ], - // }) - // mockaHandleTouchStart.mockReturnValueOnce({ nativeEvent: '' }) - - // expect(mockaHandleTouchStart).toBeCalledTimes(1) - // }) }) diff --git a/src/components/Season/__snapshots__/SeasonCardDone.spec.tsx.snap b/src/components/Season/__snapshots__/SeasonCardDone.spec.tsx.snap index 5b92e46cbbc3ed3d8bd2dcaef2c66e1172d7528e..903bb48ddc4aa6e41b0c6c316eb99ce8a6c59264 100644 --- a/src/components/Season/__snapshots__/SeasonCardDone.spec.tsx.snap +++ b/src/components/Season/__snapshots__/SeasonCardDone.spec.tsx.snap @@ -2,7 +2,7 @@ exports[`SeasonCardDone component should be rendered correctly 1`] = ` <div - className="cardContent" + className="cardContent cardDone" > <div className="headerCard" @@ -22,7 +22,11 @@ exports[`SeasonCardDone component should be rendered correctly 1`] = ` src="test-file-stub" /> </div> - <div /> + <div + className="labelResult win" + > + season.card_done.win + </div> <div className="statsResult" > @@ -45,7 +49,7 @@ exports[`SeasonCardDone component should be rendered correctly 1`] = ` <span className="text-18-bold" > - season.card_done.depense--,--€ + season.card_done.saving 1.00€ </span> <br /> season.card_done.final_defi diff --git a/src/components/Season/__snapshots__/SeasonCardLocked.spec.tsx.snap b/src/components/Season/__snapshots__/SeasonCardLocked.spec.tsx.snap index 397bae64b857bf3eff8c33e2a58ac8ecdc85265b..49b4ebd6923a861657c396b943a9f2d60f6ad7d6 100644 --- a/src/components/Season/__snapshots__/SeasonCardLocked.spec.tsx.snap +++ b/src/components/Season/__snapshots__/SeasonCardLocked.spec.tsx.snap @@ -2,7 +2,7 @@ exports[`SeasonCardLocked component should be rendered correctly 1`] = ` <div - className="cardContent" + className="cardContent cardLocked" > <p className="title" diff --git a/src/components/Season/__snapshots__/SeasonCardUnlocked.spec.tsx.snap b/src/components/Season/__snapshots__/SeasonCardUnlocked.spec.tsx.snap deleted file mode 100644 index cc42dd055ee3b76a50edb9de49aebbd8f847c9f5..0000000000000000000000000000000000000000 --- a/src/components/Season/__snapshots__/SeasonCardUnlocked.spec.tsx.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`SeasonCardUnlocked component should be rendered correctly 1`] = ` -<React.Fragment> - <div - className="cardContent" - > - <p - className="title" - > - season.card.title - </p> - <span - className="seasonTitle" - > - Season 1 - </span> - <StyledIcon - className="seasonIcon" - icon="test-file-stub" - /> - <StyledButtonValid - className="launchButton" - color="primary" - onClick={[Function]} - > - season.card.unlocked.launch - </StyledButtonValid> - </div> - <SeasonNoFluidModal - handleCloseClick={[Function]} - open={false} - /> -</React.Fragment> -`; diff --git a/src/components/Season/__snapshots__/SeasonView.spec.tsx.snap b/src/components/Season/__snapshots__/SeasonView.spec.tsx.snap index 3cc771eb9e56f251dadd77096ad8acdbb09e87ec..ce488fb1c9588b3c6ab6beb78bf842350f18dd0b 100644 --- a/src/components/Season/__snapshots__/SeasonView.spec.tsx.snap +++ b/src/components/Season/__snapshots__/SeasonView.spec.tsx.snap @@ -3,10 +3,10 @@ exports[`SeasonView component should be rendered correctly 1`] = ` <React.Fragment> <CozyBar - titleKey="COMMON.APP_OPTIONS_TITLE" + titleKey="COMMON.APP_CHALLENGE_TITLE" /> <Header - desktopTitleKey="COMMON.APP_OPTIONS_TITLE" + desktopTitleKey="COMMON.APP_CHALLENGE_TITLE" setHeaderHeight={[Function]} /> <Content @@ -14,6 +14,7 @@ exports[`SeasonView component should be rendered correctly 1`] = ` > <div className="seasonSlider" + onClick={[Function]} onMouseDown={[Function]} onMouseMove={[Function]} onMouseUp={[Function]} @@ -30,56 +31,152 @@ exports[`SeasonView component should be rendered correctly 1`] = ` } > <SeasonCard + cardHeight={384} + cardWidth={285} index={0} - season={ + indexSlider={0} + userSeason={ Object { - "name": "saison0", - "saison": 0, + "boss": Object { + "description": "Je parie un ours polaire que vous ne pouvez pas consommer moins que #CONSUMPTION € en 1 semaine", + "duration": "P30D", + "id": "BOSS001", + "startDate": null, + "state": 0, + "threshold": 1, + "title": "NicolasHublot", + "userConsumption": 0, + }, + "description": "Description season 1", + "endingDate": null, + "id": "SEASON0001", + "progress": 0, + "quiz": null, + "startDate": null, + "state": 4, + "success": 3, + "target": 15, + "title": "Season 1", } } /> <SeasonCard - index={0} - season={ - Object { - "name": "saison1", - "saison": 1, - } - } - /> - <SeasonCard - index={0} - season={ + cardHeight={384} + cardWidth={285} + index={1} + indexSlider={0} + userSeason={ Object { - "name": "saison2", - "saison": 2, + "boss": Object { + "description": "Je parie un ours polaire que vous ne pouvez pas consommer moins que #CONSUMPTION € en 1 semaine", + "duration": "P30D", + "id": "BOSS001", + "startDate": null, + "state": 0, + "threshold": 1, + "title": "NicolasHublot", + "userConsumption": 0, + }, + "description": "Description season 2", + "endingDate": null, + "id": "SEASON0002", + "progress": 0, + "quiz": null, + "startDate": null, + "state": 4, + "success": 1, + "target": 15, + "title": "Season 2", } } /> <SeasonCard - index={0} - season={ + cardHeight={384} + cardWidth={285} + index={2} + indexSlider={0} + userSeason={ Object { - "name": "saison3", - "saison": 3, + "boss": Object { + "description": "Je parie un ours polaire que vous ne pouvez pas consommer moins que #CONSUMPTION € en 1 semaine", + "duration": "P30D", + "id": "BOSS001", + "startDate": null, + "state": 0, + "threshold": 1, + "title": "NicolasHublot", + "userConsumption": 0, + }, + "description": "Description season 3", + "endingDate": null, + "id": "SEASON0003", + "progress": 0, + "quiz": null, + "startDate": null, + "state": 2, + "success": 0, + "target": 15, + "title": "Season 3", } } /> <SeasonCard - index={0} - season={ + cardHeight={384} + cardWidth={285} + index={3} + indexSlider={0} + userSeason={ Object { - "name": "saison4", - "saison": 4, + "boss": Object { + "description": "Je parie un ours polaire que vous ne pouvez pas consommer moins que #CONSUMPTION € en 1 semaine", + "duration": "P30D", + "id": "BOSS001", + "startDate": null, + "state": 0, + "threshold": 1, + "title": "NicolasHublot", + "userConsumption": 0, + }, + "description": "Description season 4", + "endingDate": null, + "id": "SEASON0004", + "progress": 0, + "quiz": null, + "startDate": null, + "state": 1, + "success": 0, + "target": 15, + "title": "Season 4", } } /> <SeasonCard - index={0} - season={ + cardHeight={384} + cardWidth={285} + index={4} + indexSlider={0} + userSeason={ Object { - "name": "saison5", - "saison": 5, + "boss": Object { + "description": "Je parie un ours polaire que vous ne pouvez pas consommer moins que #CONSUMPTION € en 1 semaine", + "duration": "P30D", + "id": "BOSS001", + "startDate": null, + "state": 0, + "threshold": 1, + "title": "NicolasHublot", + "userConsumption": 0, + }, + "description": "Description season 5", + "endingDate": null, + "id": "SEASON0005", + "progress": 0, + "quiz": null, + "startDate": null, + "state": 0, + "success": 0, + "target": 15, + "title": "Season 5", } } /> diff --git a/src/locales/fr.json b/src/locales/fr.json index 69f5e206be863022cfdd3f3ad74503d2b272365e..87b80927deb33ba215470002dfb0676f0a67e29c 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -349,7 +349,7 @@ "card_done": { "day" : " jour", "days" : " jours", - "saving" : "Economie de ", + "saving" : "Economie de", "depense" : "Dépense de", "win" : "Gagné", "almostWin" : "Presque gagné", diff --git a/src/models/season.model.ts b/src/models/season.model.ts index d6a19ce6b1681bae64f25e22bf8489e5a30e9bba..cc12d10cff0d1e26e02d5843b8c0939399881c3e 100644 --- a/src/models/season.model.ts +++ b/src/models/season.model.ts @@ -15,8 +15,8 @@ export interface SeasonEntity { quizType: string } -// TODO Link icône -export interface UserSeason { +// Entity of User Season +export interface UserSeasonEntity { id: string title: string description: string @@ -25,9 +25,15 @@ export interface UserSeason { progress: number boss: Boss success: UserSeasonSuccess + startDate: string | null + endingDate: string | null + quiz: null +} + +export interface UserSeason + extends Omit<UserSeasonEntity, 'startDate' | 'endingDate'> { startDate: DateTime | null endingDate: DateTime | null - quiz: null } // export interface Quiz {} diff --git a/src/services/season.service.ts b/src/services/season.service.ts index 8f156831e2a7f70144ee654c04a5580a5549f911..35f86478095e3fd24eca6152eff78c6bf5b16818 100644 --- a/src/services/season.service.ts +++ b/src/services/season.service.ts @@ -1,6 +1,6 @@ import { Client, QueryDefinition, QueryResult, Q } from 'cozy-client' import { SEASON_DOCTYPE, USERSEASON_DOCTYPE } from 'doctypes' -import { SeasonEntity, UserSeason } from 'models/season.model' +import { SeasonEntity, UserSeason, UserSeasonEntity } from 'models/season.model' import { Boss, BossEntity } from 'models/boss.model' import { UserSeasonState, UserSeasonSuccess } from 'enum/userSeason.enum' @@ -26,6 +26,21 @@ export default class SeasonService { return userSeasons } + public parseUserSeasonEntityToUserSeason( + userSeasonEntity: UserSeasonEntity + ): UserSeason { + const userSeason: UserSeason = { + ...userSeasonEntity, + startDate: userSeasonEntity.startDate + ? DateTime.fromISO(userSeasonEntity.startDate) + : null, + endingDate: userSeasonEntity.endingDate + ? DateTime.fromISO(userSeasonEntity.endingDate) + : null, + } + return userSeason + } + public formatToUserSeason(season: SeasonEntity, boss: Boss): UserSeason { const userSeason: UserSeason = { id: season.id, @@ -60,10 +75,7 @@ export default class SeasonService { querySeasonEntity ) - const queryUserSeason: QueryDefinition = Q(USERSEASON_DOCTYPE) - const { - data: userSeasonList, - }: QueryResult<UserSeason[]> = await this._client.query(queryUserSeason) + const userSeasonList: UserSeason[] = await this.getAllUserSeasonsEntities() const bossService = new BossService(this._client) let buildList: UserSeason[] = [] @@ -125,31 +137,29 @@ export default class SeasonService { public async getAllUserSeasonsEntities(): Promise<UserSeason[]> { const query: QueryDefinition = Q(USERSEASON_DOCTYPE) const { - data: userSeasons, - }: QueryResult<UserSeason[]> = await this._client.query(query) + data: userSeasonEntities, + }: QueryResult<UserSeasonEntity[]> = await this._client.query(query) + const userSeasons: UserSeason[] = userSeasonEntities.map(userSeasonEntity => + this.parseUserSeasonEntityToUserSeason(userSeasonEntity) + ) return userSeasons } public async startUserSeason(userSeason: UserSeason): Promise<UserSeason> { - /* - Passer une selected userSeason ONGOING - 0 Progress - Start Date / End Date from duration - Ongoing Success - Quizz . - create userSeason en base - */ userSeason.state = UserSeasonState.ONGOING userSeason.progress = 0 userSeason.startDate = DateTime.local() userSeason.success = UserSeasonSuccess.ONGOING try { const { - data: updatedUserSeason, - }: QueryResult<UserSeason> = await this._client.create( + data: updatedUserSeasonEntity, + }: QueryResult<UserSeasonEntity> = await this._client.create( USERSEASON_DOCTYPE, userSeason ) + const updatedUserSeason: UserSeason = this.parseUserSeasonEntityToUserSeason( + updatedUserSeasonEntity + ) return updatedUserSeason } catch (error) { console.log('Initialization error: ', error) @@ -161,7 +171,7 @@ export default class SeasonService { userSeason: UserSeason, flag: UpdateUserSeason ): Promise<UserSeason> { - let updatedUserSeason = userSeason + let updatedUserSeason: UserSeason let updatedBoss = userSeason.boss const bossService = new BossService(this._client) switch (flag) { @@ -219,10 +229,15 @@ export default class SeasonService { break } try { - const { data }: QueryResult<UserSeason> = await this._client.save( + const { + data: userSeasonEntity, + }: QueryResult<UserSeasonEntity> = await this._client.save( updatedUserSeason ) - return data + const result: UserSeason = this.parseUserSeasonEntityToUserSeason( + userSeasonEntity + ) + return result } catch (error) { console.log('Update user season error : ', error) throw error diff --git a/test/jestLib/setup.js b/test/jestLib/setup.js index b6deccdf3165fb81f5e290b2c08f73ed02206e96..918766e8e218532d5b58406bcee4cc6b8241eeb8 100644 --- a/test/jestLib/setup.js +++ b/test/jestLib/setup.js @@ -20,3 +20,18 @@ global.cozy = { setTheme: () => null, }, } + +Object.defineProperty(window, 'getComputedStyle', { + value: () => ({ + getPropertyValue: prop => { + switch (prop) { + case '--blue': + return '#58ffff' + case '--greyDark': + return '#7b7b7b' + default: + return '#FFFFFF' + } + }, + }), +})