-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove useless lunatic data in visualization download (#175)
- Loading branch information
1 parent
f4c6187
commit fe12c1a
Showing
23 changed files
with
268 additions
and
96 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
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
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
158 changes: 158 additions & 0 deletions
158
src/components/orchestrator/hooks/useStromaeNavigation.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,158 @@ | ||
import { act, renderHook } from '@testing-library/react' | ||
|
||
import { PAGE_TYPE } from '@/constants/page' | ||
import type { InternalPageType, PageType, StromaePage } from '@/models/Page' | ||
|
||
import { useStromaeNavigation } from './useStromaeNavigation' | ||
|
||
describe('Use stromae navigation', () => { | ||
test.each<{ initialCurrentPage?: PageType; expected: InternalPageType }>([ | ||
{ initialCurrentPage: PAGE_TYPE.WELCOME, expected: PAGE_TYPE.LUNATIC }, | ||
{ initialCurrentPage: PAGE_TYPE.VALIDATION, expected: PAGE_TYPE.LUNATIC }, | ||
{ initialCurrentPage: PAGE_TYPE.END, expected: PAGE_TYPE.END }, | ||
{ expected: PAGE_TYPE.LUNATIC }, | ||
])( | ||
'go to next $initialCurrentPage -> $expected', | ||
async ({ initialCurrentPage, expected }) => { | ||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
initialCurrentPage, | ||
}), | ||
) | ||
|
||
act(() => result.current.goNext()) | ||
|
||
expect(result.current.currentPage).toBe(expected) | ||
}, | ||
) | ||
|
||
test('go to next lunaticPage -> lunaticPage (not last page)', () => { | ||
const goNextWithControlsMock = (goNext: () => void) => goNext() | ||
const goNextLunaticMock = vi.fn() | ||
|
||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
goNextWithControls: goNextWithControlsMock, | ||
goNextLunatic: goNextLunaticMock, | ||
}), | ||
) | ||
|
||
act(() => result.current.goNext()) // go to lunatic page | ||
|
||
act(() => result.current.goNext()) | ||
|
||
expect(goNextLunaticMock).toHaveBeenCalledOnce() | ||
expect(result.current.currentPage).toBe(PAGE_TYPE.LUNATIC) | ||
}) | ||
|
||
test('go to next lunaticPage -> validationPage (last page)', () => { | ||
const goNextWithControlsMock = (goNext: () => void) => goNext() | ||
const goNextLunaticMock = vi.fn() | ||
|
||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
isLastPage: true, | ||
goNextWithControls: goNextWithControlsMock, | ||
goNextLunatic: goNextLunaticMock, | ||
}), | ||
) | ||
|
||
act(() => result.current.goNext()) // go to lunatic page | ||
|
||
act(() => result.current.goNext()) | ||
|
||
expect(goNextLunaticMock).not.toHaveBeenCalled() | ||
expect(result.current.currentPage).toBe(PAGE_TYPE.VALIDATION) | ||
}) | ||
|
||
test.each<{ initialCurrentPage?: PageType; expected: InternalPageType }>([ | ||
{ initialCurrentPage: PAGE_TYPE.WELCOME, expected: PAGE_TYPE.WELCOME }, | ||
{ initialCurrentPage: PAGE_TYPE.VALIDATION, expected: PAGE_TYPE.WELCOME }, | ||
{ initialCurrentPage: PAGE_TYPE.END, expected: PAGE_TYPE.END }, | ||
{ expected: PAGE_TYPE.WELCOME }, | ||
])( | ||
'go to previous $initialCurrentPage -> $expected', | ||
async ({ initialCurrentPage, expected }) => { | ||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
initialCurrentPage, | ||
}), | ||
) | ||
|
||
act(() => result.current.goPrevious()) | ||
|
||
expect(result.current.currentPage).toBe(expected) | ||
}, | ||
) | ||
|
||
test('go to previous lunaticPage -> lunaticPage (not first page)', () => { | ||
const goPrevLunaticMock = vi.fn() | ||
|
||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
goPrevLunatic: goPrevLunaticMock, | ||
}), | ||
) | ||
|
||
act(() => result.current.goNext()) // go to lunatic page | ||
|
||
act(() => result.current.goPrevious()) | ||
|
||
expect(goPrevLunaticMock).toHaveBeenCalledOnce() | ||
expect(result.current.currentPage).toBe(PAGE_TYPE.LUNATIC) | ||
}) | ||
|
||
test('go to next lunaticPage -> welcomePage (first page)', () => { | ||
const goPrevLunaticMock = vi.fn() | ||
|
||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
isFirstPage: true, | ||
goPrevLunatic: goPrevLunaticMock, | ||
}), | ||
) | ||
|
||
act(() => result.current.goNext()) // go to lunatic page | ||
|
||
act(() => result.current.goPrevious()) | ||
|
||
expect(goPrevLunaticMock).not.toHaveBeenCalled() | ||
expect(result.current.currentPage).toBe(PAGE_TYPE.WELCOME) | ||
}) | ||
|
||
test.each<{ page: StromaePage; shouldGoToLunaticPageBeCalled?: boolean }>([ | ||
{ page: PAGE_TYPE.WELCOME }, | ||
{ page: PAGE_TYPE.VALIDATION }, | ||
{ page: PAGE_TYPE.END }, | ||
])('go to page $page', ({ page }) => { | ||
const goToLunaticPageMock = vi.fn() | ||
|
||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
goToLunaticPage: goToLunaticPageMock, | ||
}), | ||
) | ||
|
||
act(() => result.current.goToPage({ page })) | ||
expect(goToLunaticPageMock).not.toHaveBeenCalled() | ||
|
||
expect(result.current.currentPage).toBe(page) | ||
}) | ||
|
||
test('go to lunatic page ', () => { | ||
const goToLunaticPageMock = vi.fn() | ||
|
||
const { result } = renderHook(() => | ||
useStromaeNavigation({ | ||
goToLunaticPage: goToLunaticPageMock, | ||
}), | ||
) | ||
|
||
act(() => result.current.goToPage({ page: 1 })) | ||
|
||
expect(goToLunaticPageMock).toHaveBeenCalledOnce() | ||
expect(goToLunaticPageMock).toHaveBeenCalledWith({ page: 1 }) | ||
|
||
expect(result.current.currentPage).toBe(PAGE_TYPE.LUNATIC) | ||
}) | ||
}) |
Oops, something went wrong.