-
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.
(PC-33888) feat(ChronicleCardList): add chronicle card list for mobil…
…e and web
- Loading branch information
1 parent
4885a71
commit 1706c0e
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
src/features/chronicle/components/ChronicleCardList/ChronicleCardList.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,3 @@ | ||
import { ChronicleCardListBase } from 'features/chronicle/components/ChronicleCardListBase/ChronicleCardListBase' | ||
|
||
export const ChronicleCardList = ChronicleCardListBase |
67 changes: 67 additions & 0 deletions
67
src/features/chronicle/components/ChronicleCardList/ChronicleCardList.web.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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react' | ||
|
||
import { ChronicleCardList } from 'features/chronicle/components/ChronicleCardList/ChronicleCardList.web' | ||
import { chroniclesSnap } from 'features/chronicle/fixtures/chroniclesSnap' | ||
import { fireEvent, render, screen } from 'tests/utils/web' | ||
|
||
describe('ChronicleCardList', () => { | ||
it('should render the ChronicleCardList correctly with horizontal mode', () => { | ||
render(<ChronicleCardList data={chroniclesSnap} />) | ||
|
||
expect(screen.getByText('Le Voyage Extraordinaire')).toBeInTheDocument() | ||
expect(screen.getByText('L’Art de la Cuisine')).toBeInTheDocument() | ||
|
||
expect(screen.getByTestId('chronicle-list-right-arrow')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the ChronicleCardList correctly with vertical mode', () => { | ||
render(<ChronicleCardList data={chroniclesSnap} horizontal={false} />) | ||
|
||
expect(screen.getByText('Le Voyage Extraordinaire')).toBeInTheDocument() | ||
|
||
expect(screen.queryByTestId('chronicle-list-left-arrow')).not.toBeInTheDocument() | ||
expect(screen.queryByTestId('chronicle-list-right-arrow')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should go to next page when right arrow is pressed', () => { | ||
render(<ChronicleCardList data={chroniclesSnap} horizontal />) | ||
|
||
fireEvent.click(screen.getByTestId('chronicle-list-right-arrow')) | ||
|
||
// 2 item | ||
expect(screen.getByText('L’Art de la Cuisine')).toBeInTheDocument() | ||
// 11 item | ||
expect(screen.queryByText('L’Odyssée des Espèces')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should go to previous page when left arrow is pressed', () => { | ||
render(<ChronicleCardList data={chroniclesSnap} horizontal />) | ||
|
||
fireEvent.click(screen.getByTestId('chronicle-list-right-arrow')) | ||
|
||
fireEvent.click(screen.getByTestId('chronicle-list-left-arrow')) | ||
|
||
expect(screen.getByText('Le Voyage Extraordinaire')).toBeInTheDocument() | ||
expect(screen.getByText('Explorateur du monde')).toBeInTheDocument() | ||
}) | ||
|
||
it('should disable the left arrow when on the first item', () => { | ||
render(<ChronicleCardList data={chroniclesSnap} horizontal />) | ||
|
||
// Ensure that the left arrow is not clickable on the first item | ||
expect(screen.queryByTestId('chronicle-list-left-arrow')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should disable the right arrow when on the last item', () => { | ||
render(<ChronicleCardList data={chroniclesSnap} horizontal />) | ||
|
||
const rightArrow = screen.getByTestId('chronicle-list-right-arrow') | ||
|
||
// Simulate clicks until the right arrow button is no longer visible | ||
while (rightArrow && rightArrow.isConnected) { | ||
fireEvent.click(rightArrow) | ||
} | ||
|
||
expect(screen.queryByTestId('chronicle-list-right-arrow')).not.toBeInTheDocument() | ||
}) | ||
}) |
51 changes: 51 additions & 0 deletions
51
src/features/chronicle/components/ChronicleCardList/ChronicleCardList.web.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,51 @@ | ||
import React, { FunctionComponent, useState } from 'react' | ||
import styled from 'styled-components/native' | ||
|
||
import { ChronicleCardProps } from 'features/chronicle/components/ChronicleCard/ChronicleCard' | ||
import { ChronicleCardListBase } from 'features/chronicle/components/ChronicleCardListBase/ChronicleCardListBase' | ||
import { PlaylistArrowButton } from 'ui/Playlist/PlaylistArrowButton' | ||
|
||
type ChronicleCardListProps = { | ||
data: ChronicleCardProps[] | ||
horizontal?: boolean | ||
} | ||
|
||
export const ChronicleCardList: FunctionComponent<ChronicleCardListProps> = ({ | ||
data, | ||
horizontal = true, | ||
}) => { | ||
const [indexItem, setIndexItem] = useState(0) | ||
|
||
const goToPreviousPage = () => setIndexItem((prev) => Math.max(prev - 1, 0)) | ||
const goToNextPage = () => setIndexItem((prev) => Math.min(prev + 1, data.length - 1)) | ||
|
||
return ( | ||
<FlatListContainer> | ||
{horizontal ? ( | ||
<React.Fragment> | ||
{indexItem > 0 ? ( | ||
<PlaylistArrowButton | ||
direction="left" | ||
onPress={goToPreviousPage} | ||
testID="chronicle-list-left-arrow" | ||
/> | ||
) : null} | ||
|
||
{indexItem < data.length - 1 ? ( | ||
<PlaylistArrowButton | ||
direction="right" | ||
onPress={goToNextPage} | ||
testID="chronicle-list-right-arrow" | ||
/> | ||
) : null} | ||
</React.Fragment> | ||
) : null} | ||
<ChronicleCardListBase data={data} indexItem={indexItem} horizontal={horizontal} /> | ||
</FlatListContainer> | ||
) | ||
} | ||
|
||
const FlatListContainer = styled.View<{ minHeight?: number }>({ | ||
position: 'relative', | ||
width: '100%', | ||
}) |