-
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-33638) feat(chronicle): add anchor on chronicle when see more but…
…ton used with InteractionManager
- Loading branch information
1 parent
fdb05b5
commit d04439d
Showing
6 changed files
with
132 additions
and
89 deletions.
There are no files selected for viewing
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
73 changes: 65 additions & 8 deletions
73
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,28 +1,85 @@ | ||
import React from 'react' | ||
import { FlatList } from 'react-native' | ||
|
||
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' | ||
import { act, fireEvent, render, screen } from 'tests/utils' | ||
|
||
useRoute.mockReturnValue({ | ||
params: { | ||
offerId: offerResponseSnap.id, | ||
const mockOnLayout = { | ||
nativeEvent: { | ||
layout: { | ||
width: 375, | ||
height: 2100, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const mockScrollToIndex = jest.fn() | ||
jest.spyOn(FlatList.prototype, 'scrollToIndex').mockImplementation(mockScrollToIndex) | ||
|
||
const mockChronicles = offerChroniclesFixture.chronicles | ||
jest.mock('features/chronicle/api/useChronicles/useChronicles', () => ({ | ||
useChronicles: () => ({ data: mockChronicles, isLoading: false }), | ||
})) | ||
|
||
describe('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 />)) | ||
describe('When chronicle id not defined', () => { | ||
beforeAll(() => { | ||
useRoute.mockReturnValue({ | ||
params: { | ||
offerId: offerResponseSnap.id, | ||
}, | ||
}) | ||
}) | ||
|
||
it('should render correctly', async () => { | ||
render(reactQueryProviderHOC(<Chronicles />)) | ||
|
||
expect(await screen.findByText('Tous les avis')).toBeOnTheScreen() | ||
}) | ||
|
||
it('should not scroll to selected chronicle on layout', async () => { | ||
render(reactQueryProviderHOC(<Chronicles />)) | ||
|
||
await screen.findByText('Tous les avis') | ||
|
||
await act(async () => { | ||
fireEvent(screen.getByTestId('chronicle-list'), 'onLayout', mockOnLayout) | ||
}) | ||
|
||
expect(mockScrollToIndex).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe('When chronicle id defined', () => { | ||
beforeAll(() => { | ||
useRoute.mockReturnValue({ | ||
params: { | ||
offerId: offerResponseSnap.id, | ||
chronicleId: 1, | ||
}, | ||
}) | ||
}) | ||
|
||
it('should scroll to selected chronicle on layout', async () => { | ||
render(reactQueryProviderHOC(<Chronicles />)) | ||
|
||
await screen.findByText('Tous les avis') | ||
|
||
await act(async () => { | ||
fireEvent(screen.getByTestId('chronicle-list'), 'onLayout', mockOnLayout) | ||
}) | ||
|
||
expect(await screen.findByText('Tous les avis')).toBeOnTheScreen() | ||
expect(mockScrollToIndex).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
}) |
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