-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* (PC-33639) feat(api): regenerate file * (PC-33639) test(offer): fix fixtures and tests with chronicles * (PC-33649) feat(chronicle): use prop for card width * (PC-33639) feat(chronicle): get chronicles data from backend * (PC-33639) feat(chronicle): display chronicles data from backend * (PC-33639) fix(chronicle): go back on web * (PC-33639) fix(storybook): ChronicleCard story * (PC-33639) refactor(chronicle): remarks (move some file in shared folder + add adapters folder)
- Loading branch information
1 parent
33ac075
commit a3c4293
Showing
26 changed files
with
1,127 additions
and
753 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...le/adapters/offerChroniclesToChronicleCardData/offerChroniclesToChronicleCardData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { offerChroniclesToChronicleCardData } from 'features/chronicle/adapters/offerChroniclesToChronicleCardData/offerChroniclesToChronicleCardData' | ||
import { chroniclesFixture } from 'features/chronicle/fixtures/offerChronicles.fixture' | ||
|
||
describe('transformOfferChroniclesToChronicleCardData', () => { | ||
it('should transform offer chronicles to chronicle card data', () => { | ||
const chronicles = [...chroniclesFixture] | ||
const result = offerChroniclesToChronicleCardData(chronicles) | ||
|
||
expect(result).toEqual([ | ||
{ | ||
date: 'Janvier 2025', | ||
description: 'Chronique sur le produit Product 30 mais sans utilisateur.', | ||
id: 31, | ||
subtitle: '', | ||
title: 'Membre du Book Club', | ||
}, | ||
{ | ||
date: 'Janvier 2025', | ||
description: | ||
'Chronique sur le produit Product 30 écrite par l’utilisateur Jeanne Doux (2).', | ||
id: 1, | ||
subtitle: 'Membre du Book Club', | ||
title: 'Jeanne, 15 ans', | ||
}, | ||
]) | ||
}) | ||
}) |
16 changes: 16 additions & 0 deletions
16
...ronicle/adapters/offerChroniclesToChronicleCardData/offerChroniclesToChronicleCardData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { OfferChronicle } from 'api/gen' | ||
import { ChronicleCardData } from 'features/chronicle/type' | ||
import { getChronicleCardTitle } from 'shared/chronicle/getChronicleCardTitle/getChronicleCardTitle' | ||
import { getFormattedLongMonthYear } from 'shared/date/getFormattedLongMonthYear/getFormattedLongMonthYear' | ||
|
||
export function offerChroniclesToChronicleCardData( | ||
chronicles: OfferChronicle[] | ||
): ChronicleCardData[] { | ||
return chronicles.map(({ id, author, content, dateCreated }) => ({ | ||
id, | ||
title: getChronicleCardTitle(author), | ||
subtitle: author?.firstName ? 'Membre du Book Club' : '', | ||
description: content, | ||
date: getFormattedLongMonthYear(dateCreated), | ||
})) | ||
} |
22 changes: 22 additions & 0 deletions
22
src/features/chronicle/api/useChronicles/useChronicles.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useChronicles } from 'features/chronicle/api/useChronicles/useChronicles' | ||
import { offerChroniclesFixture } from 'features/chronicle/fixtures/offerChronicles.fixture' | ||
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse' | ||
import { mockServer } from 'tests/mswServer' | ||
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC' | ||
import { act, renderHook } from 'tests/utils' | ||
|
||
describe('useChronicles', () => { | ||
beforeEach(() => | ||
mockServer.getApi(`/v1/offer/${offerResponseSnap.id}/chronicles`, offerChroniclesFixture) | ||
) | ||
|
||
it('should call API otherwise', async () => { | ||
const { result } = renderHook(() => useChronicles({ offerId: offerResponseSnap.id }), { | ||
wrapper: ({ children }) => reactQueryProviderHOC(children), | ||
}) | ||
|
||
await act(async () => {}) | ||
|
||
expect(JSON.stringify(result.current.data)).toEqual(JSON.stringify(offerChroniclesFixture)) | ||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
src/features/chronicle/api/useChronicles/useChronicles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useQuery } from 'react-query' | ||
|
||
import { api } from 'api/api' | ||
import { OfferChronicles } from 'api/gen' | ||
import { QueryKeys } from 'libs/queryKeys' | ||
|
||
export const useChronicles = ({ offerId }: { offerId: number }) => { | ||
return useQuery<OfferChronicles | undefined>([QueryKeys.OFFER_CHRONICLES, offerId], () => | ||
offerId ? api.getNativeV1OfferofferIdChronicles(offerId) : undefined | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
src/features/chronicle/components/ChroniclesHeader/ChroniclesHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import React, { FunctionComponent } from 'react' | ||
import { Animated } from 'react-native' | ||
|
||
import { getSearchStackConfig } from 'features/navigation/SearchStackNavigator/helpers' | ||
import { useGoBack } from 'features/navigation/useGoBack' | ||
import { ContentHeader } from 'ui/components/headers/ContentHeader' | ||
|
||
type Props = { | ||
headerTransition: Animated.AnimatedInterpolation<string | number> | ||
title: string | ||
handleGoBack: VoidFunction | ||
} | ||
|
||
export const ChroniclesHeader: FunctionComponent<Props> = ({ headerTransition, title }) => { | ||
const { goBack } = useGoBack(...getSearchStackConfig('SearchLanding')) | ||
|
||
export const ChroniclesHeader: FunctionComponent<Props> = ({ | ||
headerTransition, | ||
title, | ||
handleGoBack, | ||
}) => { | ||
return ( | ||
<ContentHeader | ||
headerTitle={title} | ||
headerTransition={headerTransition} | ||
titleTestID="chroniclesHeaderName" | ||
onBackPress={goBack} | ||
onBackPress={handleGoBack} | ||
/> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
src/features/chronicle/fixtures/offerChronicles.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { ReadonlyDeep } from 'type-fest' | ||
|
||
import { OfferChronicle, OfferChronicles } from 'api/gen' | ||
|
||
export const chroniclesFixture = [ | ||
{ | ||
id: 31, | ||
dateCreated: '2025-01-20T23:32:14.456451Z', | ||
author: { | ||
firstName: null, | ||
age: 15, | ||
city: 'Paris', | ||
}, | ||
content: 'Chronique sur le produit Product 30 mais sans utilisateur.', | ||
}, | ||
{ | ||
id: 1, | ||
dateCreated: '2025-01-20T23:32:13.978038Z', | ||
author: { | ||
firstName: 'Jeanne', | ||
age: 15, | ||
city: 'Paris', | ||
}, | ||
content: 'Chronique sur le produit Product 30 \u00e9crite par l’utilisateur Jeanne Doux (2).', | ||
}, | ||
] as const satisfies readonly OfferChronicle[] | ||
|
||
export const offerChroniclesFixture = { | ||
chronicles: chroniclesFixture, | ||
} as const satisfies ReadonlyDeep<OfferChronicles> |
22 changes: 19 additions & 3 deletions
22
src/features/chronicle/pages/Chronicles/Chronicles.native.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import React from 'react' | ||
|
||
import { useRoute } from '__mocks__/@react-navigation/native' | ||
import { offerChroniclesFixture } from 'features/chronicle/fixtures/offerChronicles.fixture' | ||
import { Chronicles } from 'features/chronicle/pages/Chronicles/Chronicles' | ||
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse' | ||
import { mockServer } from 'tests/mswServer' | ||
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC' | ||
import { render, screen } from 'tests/utils' | ||
|
||
useRoute.mockReturnValue({ | ||
params: { | ||
offerId: offerResponseSnap.id, | ||
}, | ||
}) | ||
|
||
describe('Chronicles', () => { | ||
it('should render correctly', () => { | ||
render(<Chronicles />) | ||
beforeEach(() => { | ||
mockServer.getApi(`/v2/offer/${offerResponseSnap.id}`, offerResponseSnap) | ||
mockServer.getApi(`/v1/offer/${offerResponseSnap.id}/chronicles`, offerChroniclesFixture) | ||
}) | ||
|
||
it('should render correctly', async () => { | ||
render(reactQueryProviderHOC(<Chronicles />)) | ||
|
||
expect(screen.getByText('Tous les avis')).toBeOnTheScreen() | ||
expect(await screen.findByText('Tous les avis')).toBeOnTheScreen() | ||
}) | ||
}) |
Oops, something went wrong.