diff --git a/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.native.test.tsx b/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.native.test.tsx index 361af955835..77577d2bfd6 100644 --- a/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.native.test.tsx +++ b/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.native.test.tsx @@ -1,12 +1,18 @@ import React, { createRef } from 'react' import { FlatList } from 'react-native-gesture-handler' +import { ReactTestInstance } from 'react-test-renderer' +import { navigate } from '__mocks__/@react-navigation/native' import { CHRONICLE_CARD_WIDTH } from 'features/chronicle/constant' import { chroniclesSnap } from 'features/chronicle/fixtures/chroniclesSnap' -import { render, screen } from 'tests/utils' +import { render, screen, userEvent } from 'tests/utils' import { ChronicleCardListBase } from './ChronicleCardListBase' +const user = userEvent.setup() + +jest.useFakeTimers() + describe('ChronicleCardListBase', () => { const ref = createRef() @@ -34,4 +40,66 @@ describe('ChronicleCardListBase', () => { expect(screen.getByText('La Nature Sauvage')).toBeOnTheScreen() }) + + it('should display "Voir plus" button on all cards when shouldShowSeeMoreButton is true and offerId defined', () => { + render( + + ) + + expect(screen.getAllByText('Voir plus')).toHaveLength(10) + }) + + it('should not display "Voir plus" button on all cards when shouldShowSeeMoreButton is not defined', () => { + render( + + ) + + expect(screen.queryByText('Voir plus')).not.toBeOnTheScreen() + }) + + it('should not display "Voir plus" button on all cards when offerId is not defined', () => { + render( + + ) + + expect(screen.queryByText('Voir plus')).not.toBeOnTheScreen() + }) + + it('should navigate to chronicles page with anchor on the selected chronicle when pressing "Voir plus" button', async () => { + render( + + ) + + const seeMoreButtons = screen.getAllByText('Voir plus') + + // Using as because links is never undefined and the typing is not correct + await user.press(seeMoreButtons[2] as ReactTestInstance) + + expect(navigate).toHaveBeenNthCalledWith(1, 'Chronicles', { offerId: 1, chronicleId: 3 }) + }) }) diff --git a/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.tsx b/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.tsx index 9ef9c7acb98..dbe2b63fcb8 100644 --- a/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.tsx +++ b/src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.tsx @@ -1,15 +1,20 @@ import React, { ReactElement, forwardRef, + useCallback, useEffect, useImperativeHandle, useMemo, useRef, } from 'react' -import { FlatList, FlatListProps, StyleProp, ViewStyle } from 'react-native' +import { FlatList, FlatListProps, StyleProp, View, ViewStyle } from 'react-native' import styled from 'styled-components/native' import { ChronicleCardData } from 'features/chronicle/type' +import { ButtonTertiaryBlack } from 'ui/components/buttons/ButtonTertiaryBlack' +import { styledButton } from 'ui/components/buttons/styledButton' +import { InternalTouchableLink } from 'ui/components/touchableLink/InternalTouchableLink' +import { PlainMore } from 'ui/svg/icons/PlainMore' import { getSpacing } from 'ui/theme' import { ChronicleCard } from '../ChronicleCard/ChronicleCard' @@ -37,31 +42,6 @@ export type ChronicleCardListProps = Pick< offerId?: number } -const renderItem = ({ - item, - cardWidth, - shouldShowSeeMoreButton, - offerId, -}: { - item: ChronicleCardData - cardWidth?: number - shouldShowSeeMoreButton?: boolean - offerId?: number -}) => { - return ( - - ) -} - export const ChronicleCardListBase = forwardRef< Partial>, ChronicleCardListProps @@ -106,13 +86,38 @@ export const ChronicleCardListBase = forwardRef< [separatorSize, horizontal] ) + const renderItem = useCallback( + ({ item }: { item: ChronicleCardData }) => { + return ( + + {shouldShowSeeMoreButton && offerId ? ( + + + + ) : null} + + ) + }, + [cardWidth, offerId, shouldShowSeeMoreButton] + ) + return ( renderItem({ item, cardWidth, shouldShowSeeMoreButton, offerId })} + renderItem={renderItem} keyExtractor={keyExtractor} ItemSeparatorComponent={Separator} contentContainerStyle={contentContainerStyle} @@ -128,3 +133,13 @@ export const ChronicleCardListBase = forwardRef< /> ) }) + +const StyledPlainMore = styled(PlainMore).attrs(({ theme }) => ({ + size: theme.icons.sizes.extraSmall, +}))`` + +const StyledButtonTertiaryBlack = styledButton(ButtonTertiaryBlack).attrs({ + icon: StyledPlainMore, + iconPosition: 'right', + buttonHeight: 'extraSmall', +})`` diff --git a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.native.test.tsx b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.native.test.tsx index 483c6be7a63..845194bd593 100644 --- a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.native.test.tsx +++ b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.native.test.tsx @@ -22,6 +22,7 @@ describe('ChroniclesSection', () => { data={chroniclesSnap} subtitle="subtitle" navigateTo={{ screen: 'Offer' }} + offerId={1} /> ) @@ -40,6 +41,7 @@ describe('ChroniclesSection', () => { data={chroniclesSnap} subtitle="subtitle" navigateTo={{ screen: 'Offer' }} + offerId={1} /> ) diff --git a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.test.tsx b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.test.tsx index 8f38bfbd52b..3eb6539b5b9 100644 --- a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.test.tsx +++ b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.test.tsx @@ -20,6 +20,7 @@ describe('ChroniclesSection', () => { data={chroniclesSnap} subtitle="subtitle" navigateTo={{ screen: 'Offer' }} + offerId={1} /> ) @@ -37,6 +38,7 @@ describe('ChroniclesSection', () => { data={chroniclesSnap} subtitle="subtitle" navigateTo={{ screen: 'Offer' }} + offerId={1} />, { theme: { isDesktopViewport: true } } ) @@ -55,6 +57,7 @@ describe('ChroniclesSection', () => { data={chroniclesSnap} subtitle="subtitle" navigateTo={{ screen: 'Offer' }} + offerId={1} /> ) diff --git a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.tsx b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.tsx index 11fdd4d9dc4..0957e63d3b4 100644 --- a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.tsx +++ b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSection.web.tsx @@ -16,7 +16,7 @@ import { ChronicleSectionProps } from './types' export const ChronicleSection = (props: ChronicleSectionProps) => { const { isDesktopViewport } = useTheme() - const { data, title, subtitle, ctaLabel, navigateTo, style } = props + const { data, title, subtitle, offerId, ctaLabel, navigateTo, style } = props return isDesktopViewport ? ( @@ -35,7 +35,7 @@ export const ChronicleSection = (props: ChronicleSectionProps) => { {subtitle ? {subtitle} : null} - + ) : ( diff --git a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSectionBase.tsx b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSectionBase.tsx index e4e824098db..c4c945b75da 100644 --- a/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSectionBase.tsx +++ b/src/features/offer/components/OfferContent/ChronicleSection/ChronicleSectionBase.tsx @@ -14,6 +14,7 @@ import { ChronicleSectionProps } from './types' export const ChronicleSectionBase = ({ data, title, + offerId, subtitle, ctaLabel, navigateTo, @@ -25,7 +26,7 @@ export const ChronicleSectionBase = ({ {title} {subtitle ? {subtitle} : null} - + = ({ title="L’avis du book club" ctaLabel="Voir tous les avis" subtitle="Des avis de jeunes passionnés sélectionnés par le pass Culture !" + offerId={offer.id} data={chronicles} navigateTo={{ screen: 'Chronicles', params: { offerId: offer.id } }} />