Repository navigation
test(mobile): test PR review diff behavior instead of internals #8029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
14f6f6c
test(mobile): replace internal-pinning PR review diff tests with beha…
iscekic 6919f61
test(mobile): satisfy mobile typecheck and formatting for the new suites
iscekic 31f0851
test(mobile): strengthen new suites per review: drag reset, idempoten…
iscekic 874e8bd
test(mobile): satisfy lint on the SecureStore stub
iscekic 579d830
test(mobile): cover the trailing separator's unknown-end branch in th…
iscekic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
150 changes: 150 additions & 0 deletions
150
apps/mobile/src/lib/pr-review/diff/pr-review-file-list-state.mounted.test.tsx
This file contains hidden or 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,150 @@ | ||
| import { createElement } from 'react'; | ||
| import { act } from '@/test/renderer'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { | ||
| type PrReviewFileListQueryResult, | ||
| usePrReviewFileListQuery, | ||
| } from '@/lib/pr-review/diff/pr-review-file-list-state'; | ||
| import { renderWithProviders, waitFor } from '@/test/render-with-providers'; | ||
|
|
||
| // ── Mocks ────────────────────────────────────────────────────────────────── | ||
|
|
||
| const queryFnMock = vi.hoisted(() => vi.fn()); | ||
|
|
||
| vi.mock('@/lib/trpc', () => ({ | ||
| useTRPC: () => ({ | ||
| githubPrReview: { | ||
| listFiles: { | ||
| infiniteQueryOptions: (input: unknown, opts: object) => ({ | ||
| ...opts, | ||
| queryKey: ['githubPrReview', 'listFiles', input], | ||
| queryFn: queryFnMock, | ||
| initialPageParam: undefined as string | undefined, | ||
| getNextPageParam: (lastPage: { nextCursor: string | null }) => | ||
| lastPage.nextCursor ?? undefined, | ||
| }), | ||
| }, | ||
| }, | ||
| }), | ||
| })); | ||
|
|
||
| // The hook's import chain pulls the real viewed-files store (SecureStore); | ||
| // the store is not the subject here, so it is stubbed like the other mounted | ||
| // suites for this module do. | ||
| vi.mock('@/lib/pr-review/viewed-files', () => ({ | ||
| getViewedFiles: vi.fn(async () => { | ||
| await Promise.resolve(); | ||
| return [] as string[]; | ||
| }), | ||
| toggleViewedFile: vi.fn(async () => { | ||
| await Promise.resolve(); | ||
| }), | ||
| })); | ||
|
|
||
| // ── Harness ──────────────────────────────────────────────────────────────── | ||
|
|
||
| type Result = PrReviewFileListQueryResult; | ||
|
|
||
| function Probe({ holder }: { holder: { current: Result | null } }) { | ||
| holder.current = usePrReviewFileListQuery({ | ||
| owner: 'octocat', | ||
| repo: 'hello', | ||
| number: 1, | ||
| enabled: true, | ||
| }); | ||
| return null; | ||
| } | ||
|
|
||
| async function mountProbe() { | ||
| const holder: { current: Result | null } = { current: null }; | ||
| await renderWithProviders(createElement(Probe, { holder })); | ||
| return holder; | ||
| } | ||
|
|
||
| function current(holder: { current: Result | null }): Result { | ||
| const result = holder.current; | ||
| if (!result) { | ||
| throw new Error('probe did not render'); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| const FILE_A = { path: 'a.ts' }; | ||
| const FILE_B = { path: 'b.ts' }; | ||
|
|
||
| beforeEach(() => { | ||
| queryFnMock.mockReset(); | ||
| }); | ||
|
|
||
| // ── Tests ────────────────────────────────────────────────────────────────── | ||
|
|
||
| describe('usePrReviewFileListQuery error classification', () => { | ||
| it('a first-page failure surfaces firstPageErrorState and no laterPageError', async () => { | ||
| queryFnMock.mockRejectedValue(new Error('network down')); | ||
| const holder = await mountProbe(); | ||
|
|
||
| await waitFor(() => current(holder).errorState !== null); | ||
|
|
||
| const result = current(holder); | ||
| expect(result.errorState?.kind).toBe('retryable'); | ||
| expect(result.firstPageErrorState?.kind).toBe('retryable'); | ||
| expect(result.laterPageError).toBe(false); | ||
| expect(result.files).toEqual([]); | ||
| }); | ||
|
|
||
| it('a NOT_FOUND first page classifies as not-found', async () => { | ||
| queryFnMock.mockRejectedValue({ data: { code: 'NOT_FOUND' } }); | ||
| const holder = await mountProbe(); | ||
|
|
||
| await waitFor(() => current(holder).errorState !== null); | ||
|
|
||
| const result = current(holder); | ||
| expect(result.errorState?.kind).toBe('not-found'); | ||
| expect(result.firstPageErrorState?.kind).toBe('not-found'); | ||
| expect(result.laterPageError).toBe(false); | ||
| }); | ||
|
|
||
| it('a later-page failure keeps the loaded files and flips laterPageError', async () => { | ||
| queryFnMock | ||
| .mockResolvedValueOnce({ files: [FILE_A], nextCursor: 'cursor-2' }) | ||
| .mockRejectedValueOnce(new Error('page 2 failed')); | ||
| const holder = await mountProbe(); | ||
|
|
||
| // Load page one, then let the hook auto-run fetch-to-completion? No: the | ||
| // hook itself only reads; drive page two through the query handle it | ||
| // exposes. | ||
| await waitFor(() => current(holder).files.length === 1); | ||
| expect(current(holder).files).toEqual([FILE_A]); | ||
|
|
||
| await act(async () => { | ||
| await current(holder).query.fetchNextPage(); | ||
| }); | ||
| await waitFor(() => current(holder).errorState !== null); | ||
|
|
||
| const result = current(holder); | ||
| expect(result.errorState?.kind).toBe('retryable'); | ||
| // A page-1 set survived: the tab must not blank on a later-page failure. | ||
| expect(result.firstPageErrorState).toBeNull(); | ||
| expect(result.laterPageError).toBe(true); | ||
| expect(result.files).toEqual([FILE_A]); | ||
| expect(queryFnMock).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| it('loads pages through the provider page shape (sanity on the option wiring)', async () => { | ||
| queryFnMock | ||
| .mockResolvedValueOnce({ files: [FILE_A], nextCursor: 'cursor-2' }) | ||
| .mockResolvedValueOnce({ files: [FILE_B], nextCursor: null }); | ||
| const holder = await mountProbe(); | ||
|
|
||
| await act(async () => { | ||
| await current(holder).query.fetchNextPage(); | ||
| }); | ||
|
|
||
| await waitFor(() => current(holder).files.length === 2); | ||
| expect(current(holder).files).toEqual([FILE_A, FILE_B]); | ||
| expect(current(holder).errorState).toBeNull(); | ||
| expect(current(holder).firstPageErrorState).toBeNull(); | ||
| expect(current(holder).laterPageError).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.