-
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.
- Loading branch information
1 parent
bf2f469
commit e49078e
Showing
8 changed files
with
192 additions
and
115 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
42 changes: 37 additions & 5 deletions
42
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 |
---|---|---|
@@ -1,22 +1,54 @@ | ||
import { OfferChronicle } from 'api/gen' | ||
import { offerChroniclesToChronicleCardData } from 'features/chronicle/adapters/offerChroniclesToChronicleCardData/offerChroniclesToChronicleCardData' | ||
import { useChronicles } from 'features/chronicle/api/useChronicles/useChronicles' | ||
import { offerChroniclesFixture } from 'features/chronicle/fixtures/offerChronicles.fixture' | ||
import { ChronicleCardData } from 'features/chronicle/type' | ||
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse' | ||
import { mockServer } from 'tests/mswServer' | ||
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC' | ||
import { act, renderHook } from 'tests/utils' | ||
import { act, renderHook, waitFor } 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), | ||
}) | ||
const { result } = renderHook( | ||
() => | ||
useChronicles({ | ||
offerId: offerResponseSnap.id, | ||
}), | ||
{ | ||
wrapper: ({ children }) => reactQueryProviderHOC(children), | ||
} | ||
) | ||
|
||
await waitFor(() => | ||
expect(JSON.stringify(result.current.data)).toEqual(JSON.stringify(offerChroniclesFixture)) | ||
) | ||
}) | ||
|
||
it('should call API and format output data', async () => { | ||
const { result } = renderHook( | ||
() => | ||
useChronicles<ChronicleCardData[]>({ | ||
offerId: offerResponseSnap.id, | ||
select: (data) => offerChroniclesToChronicleCardData(data.chronicles), | ||
}), | ||
{ | ||
wrapper: ({ children }) => reactQueryProviderHOC(children), | ||
} | ||
) | ||
|
||
await act(async () => {}) | ||
|
||
expect(JSON.stringify(result.current.data)).toEqual(JSON.stringify(offerChroniclesFixture)) | ||
expect(JSON.stringify(result.current.data)).toEqual( | ||
JSON.stringify( | ||
offerChroniclesToChronicleCardData([ | ||
...offerChroniclesFixture.chronicles, | ||
] as OfferChronicle[]) | ||
) | ||
) | ||
}) | ||
}) |
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
src/features/chronicle/components/ChronicleCardList/ChronicleCardListBase.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,27 @@ | ||
import React from 'react' | ||
|
||
import { CHRONICLE_CARD_WIDTH } from 'features/chronicle/constant' | ||
import { chroniclesSnap } from 'features/chronicle/fixtures/chroniclesSnap' | ||
import { render, screen } from 'tests/utils' | ||
|
||
import { ChronicleCardListBase } from './ChronicleCardListBase' | ||
|
||
describe('ChronicleCardListBase', () => { | ||
it('should display all chronicle cards in the list in horizontal', () => { | ||
render(<ChronicleCardListBase data={chroniclesSnap} horizontal separatorSize={10} />) | ||
|
||
expect(screen.getByText('Le Voyage Extraordinaire')).toBeOnTheScreen() | ||
}) | ||
|
||
it('should display all chronicle cards in the list in vertical', () => { | ||
render(<ChronicleCardListBase data={chroniclesSnap} separatorSize={20} />) | ||
|
||
expect(screen.getByText('Le Voyage Extraordinaire')).toBeOnTheScreen() | ||
}) | ||
|
||
it('should scroll to the correct page when offset is provided', () => { | ||
render(<ChronicleCardListBase data={chroniclesSnap} offset={CHRONICLE_CARD_WIDTH} horizontal />) | ||
|
||
expect(screen.getByText('La Nature Sauvage')).toBeOnTheScreen() | ||
}) | ||
}) |
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
Oops, something went wrong.