Repository navigation
fix(ui): the test case or Finding you selected stays selected when you come back to its tab #155
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import '@testing-library/jest-dom/vitest' | ||
| import { fireEvent, render, screen, waitFor, within } from '@testing-library/react' | ||
| import { afterEach, beforeEach, expect, it, vi } from 'vitest' | ||
| import { draftFixture, entryFixture, findingFixture } from '../test/fixtures' | ||
| import { cleanupControllerTest, getTauriMock, setupControllerTest, useAppController } from './useAppController.testHarness' | ||
|
|
||
| const { AppShell } = await import('./AppShell') | ||
| const tauri = getTauriMock() | ||
| function Subject() { return <AppShell {...useAppController()} /> } | ||
|
|
||
| beforeEach(() => { | ||
| setupControllerTest() | ||
| HTMLElement.prototype.scrollIntoView = vi.fn() | ||
| tauri.listDrafts.mockResolvedValue([ | ||
| draftFixture({ id: 'draft-new', title: 'Newer test cases', updatedAt: '2026-11-13T09:00:00Z' }), | ||
| draftFixture({ id: 'draft-old', title: 'Older test cases', updatedAt: '2026-07-22T00:00:00Z' }), | ||
| ]) | ||
| tauri.listFindings.mockResolvedValue([ | ||
| findingFixture({ id: 'finding-new', title: 'Newer finding', updatedAt: '2026-11-13T09:00:00Z' }), | ||
| findingFixture({ id: 'finding-old', title: 'Older finding', updatedAt: '2026-07-22T00:00:00Z' }), | ||
| ]) | ||
| tauri.readNoteSource.mockResolvedValue({ entry: entryFixture({ body: '<p>Pay with a saved card.</p>' }), revision: 0 }) | ||
| }) | ||
| afterEach(cleanupControllerTest) | ||
|
|
||
| const openTab = async (name: RegExp) => fireEvent.click(await screen.findByRole('tab', { name })) | ||
| const shownRecord = (title: string) => screen.findByRole('heading', { level: 2, name: title }) | ||
|
|
||
| async function selectRecord(listName: string, title: string) { | ||
| fireEvent.click(await within(await screen.findByRole('complementary', { name: listName })).findByText(title)) | ||
| await shownRecord(title) | ||
| } | ||
|
|
||
| async function openAndCancelDraft(createLabel: string, titleLabel: string) { | ||
| const create = screen.getByRole('button', { name: createLabel }) | ||
| await waitFor(() => expect(create).toBeEnabled()) | ||
| fireEvent.click(create) | ||
| await screen.findByRole('textbox', { name: titleLabel }) | ||
| fireEvent.click(screen.getByRole('button', { name: 'Cancel' })) | ||
| await waitFor(() => expect(screen.queryByRole('textbox', { name: titleLabel })).not.toBeInTheDocument()) | ||
| } | ||
|
|
||
| it('keeps the selected test cases when another tab opens and a new draft is cancelled', async () => { | ||
| render(<Subject />) | ||
| await openTab(/Test cases/) | ||
| await selectRecord('Test cases records', 'Older test cases') | ||
|
|
||
| await openTab(/Findings/) | ||
| await shownRecord('Newer finding') | ||
| await openTab(/Test cases/) | ||
| expect(await shownRecord('Older test cases')).toBeInTheDocument() | ||
|
|
||
| await openAndCancelDraft('Create test cases', 'Test case title') | ||
| expect(await shownRecord('Older test cases')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('keeps the selected finding when the Note opens and a new draft is cancelled', async () => { | ||
| render(<Subject />) | ||
| await openTab(/Findings/) | ||
| await selectRecord('Findings records', 'Older finding') | ||
|
|
||
| await openTab(/Note/) | ||
| await openTab(/Findings/) | ||
| expect(await shownRecord('Older finding')).toBeInTheDocument() | ||
|
|
||
| await openAndCancelDraft('Create finding', 'Finding title') | ||
| expect(await shownRecord('Older finding')).toBeInTheDocument() | ||
| }) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { act, renderHook } from '@testing-library/react' | ||
| import { expect, it } from 'vitest' | ||
| import { useRecordSelection } from './useRecordSelection' | ||
|
|
||
| it('keeps the record navigation asked for while the view has no record to show yet', () => { | ||
| const { result } = renderHook(() => useRecordSelection()) | ||
| act(() => result.current.focusRecord('findings', 'finding-old')) | ||
| act(() => result.current.selectRecord.findings(null)) | ||
| expect(result.current.selectedRecordIds.findings).toBe('finding-old') | ||
| act(() => result.current.selectRecord.findings('finding-new')) | ||
| expect(result.current.selectedRecordIds).toEqual({ testware: null, findings: 'finding-new' }) | ||
| }) |
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,29 @@ | ||
| import { useCallback, useMemo, useState } from 'react' | ||
| import type { MainView } from '../ui/types' | ||
|
|
||
| export type RecordView = 'testware' | 'findings' | ||
| type RecordSelection = Record<RecordView, string | null> | ||
|
|
||
| const isRecordView = (view: MainView): view is RecordView => view === 'testware' || view === 'findings' | ||
|
|
||
| /** | ||
| * The record each record view shows. A view unmounts when another tab is open, so its selection is kept here: | ||
| * returning to Test cases or Findings, or leaving a new draft, shows the record that was selected, not the newest. | ||
| * `focusedRecordId` is the record navigation last opened, which the route names. | ||
| */ | ||
| export function useRecordSelection() { | ||
| const [focusedRecordId, setFocusedRecordId] = useState<string | null>(null) | ||
| const [selectedRecordIds, setSelectedRecordIds] = useState<RecordSelection>({ testware: null, findings: null }) | ||
| const select = useCallback((view: RecordView, id: string | null) => | ||
| setSelectedRecordIds((previous) => previous[view] === id ? previous : { ...previous, [view]: id }), []) | ||
| // A view shows no record while its records load, so an empty report keeps the record navigation asked for. | ||
| const selectRecord = useMemo(() => ({ | ||
| testware: (id: string | null) => { if (id) select('testware', id) }, | ||
| findings: (id: string | null) => { if (id) select('findings', id) }, | ||
| }), [select]) | ||
| const focusRecord = useCallback((view: MainView, id: string | null) => { | ||
| setFocusedRecordId(id) | ||
| if (isRecordView(view)) select(view, id) | ||
| }, [select]) | ||
| return { focusedRecordId, selectedRecordIds, selectRecord, focusRecord } | ||
| } | ||
|
vriesd marked this conversation as resolved.
Resolved
|
||
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.
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.