-
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-34395) feat(ChronicleCard): display button when the chronicle is …
…too long
- Loading branch information
1 parent
833ba2b
commit 81f883a
Showing
4 changed files
with
205 additions
and
13 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
src/features/chronicle/components/ChronicleCard/ChronicleCard.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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from 'react' | ||
import { View } from 'react-native' | ||
|
||
import { chroniclesSnap } from 'features/chronicle/fixtures/chroniclesSnap' | ||
import { act, render, screen, userEvent } from 'tests/utils' | ||
import { ButtonTertiaryBlack } from 'ui/components/buttons/ButtonTertiaryBlack' | ||
|
||
import { ChronicleCard } from './ChronicleCard' | ||
|
||
const mockOnLayoutWithButton = { | ||
nativeEvent: { | ||
layout: { | ||
height: 157, | ||
}, | ||
}, | ||
} | ||
|
||
const mockOnLayoutWithoutButton = { | ||
nativeEvent: { | ||
layout: { | ||
height: 30, | ||
}, | ||
}, | ||
} | ||
|
||
const user = userEvent.setup() | ||
const mockOnSeeMoreButtonPress = jest.fn() | ||
jest.useFakeTimers() | ||
|
||
describe('ChronicleCard (Mobile)', () => { | ||
it('should render the ChronicleCard component with correct title', () => { | ||
render( | ||
<ChronicleCard {...chroniclesSnap[0]}> | ||
<View> | ||
<ButtonTertiaryBlack | ||
wording="Voir plus" | ||
onPress={() => mockOnSeeMoreButtonPress(chroniclesSnap[0].id)} | ||
/> | ||
</View> | ||
</ChronicleCard> | ||
) | ||
|
||
expect(screen.getByText(chroniclesSnap[0].title)).toBeOnTheScreen() | ||
}) | ||
|
||
it('should display the "Voir plus" button if content overflows', async () => { | ||
render( | ||
<ChronicleCard {...chroniclesSnap[0]}> | ||
<View> | ||
<ButtonTertiaryBlack | ||
wording="Voir plus" | ||
onPress={() => mockOnSeeMoreButtonPress(chroniclesSnap[0].id)} | ||
/> | ||
</View> | ||
</ChronicleCard> | ||
) | ||
|
||
const description = screen.getByTestId('description') | ||
|
||
await act(async () => { | ||
description.props.onLayout(mockOnLayoutWithButton) | ||
}) | ||
|
||
expect(screen.getByText('Voir plus')).toBeOnTheScreen() | ||
}) | ||
|
||
it('should not display the "Voir plus" button', async () => { | ||
render( | ||
<ChronicleCard {...chroniclesSnap[0]}> | ||
<View> | ||
<ButtonTertiaryBlack | ||
wording="Voir plus" | ||
onPress={() => mockOnSeeMoreButtonPress(chroniclesSnap[0].id)} | ||
/> | ||
</View> | ||
</ChronicleCard> | ||
) | ||
|
||
const description = screen.getByTestId('description') | ||
|
||
await act(async () => { | ||
description.props.onLayout(mockOnLayoutWithoutButton) | ||
}) | ||
|
||
expect(screen.queryByText('Voir plus')).not.toBeOnTheScreen() | ||
}) | ||
|
||
it('should call onSeeMoreButtonPress when "Voir plus" is clicked', async () => { | ||
render( | ||
<ChronicleCard {...chroniclesSnap[0]}> | ||
<View> | ||
<ButtonTertiaryBlack | ||
wording="Voir plus" | ||
onPress={() => mockOnSeeMoreButtonPress(chroniclesSnap[0].id)} | ||
/> | ||
</View> | ||
</ChronicleCard> | ||
) | ||
|
||
const description = screen.getByTestId('description') | ||
|
||
await act(async () => { | ||
description.props.onLayout(mockOnLayoutWithButton) | ||
}) | ||
|
||
await user.press(screen.getByText('Voir plus')) | ||
|
||
expect(mockOnSeeMoreButtonPress).toHaveBeenCalledTimes(1) | ||
expect(mockOnSeeMoreButtonPress).toHaveBeenCalledWith(chroniclesSnap[0].id) | ||
}) | ||
}) |
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