fix(dashboard): respect pointer type when focusing trip titles

Mark the title through the existing dialog focus mechanism so a
mouse can type right away and touch keeps focus on the dialog.
Cover creating and editing a trip in the dashboard tests.
This commit is contained in:
Maurice
2026-12-02 14:49:52 +01:00
parent 7a66a54e66
commit a2cf911ce1
4 changed files with 22 additions and 22 deletions
+17 -7
View File
@@ -42,8 +42,17 @@ beforeEach(() => {
afterEach(() => {
vi.useRealTimers();
vi.unstubAllGlobals();
});
function mockFinePointer() {
const matchMedia = window.matchMedia.bind(window);
vi.stubGlobal('matchMedia', (query: string) => {
const result = matchMedia(query);
return query === '(pointer: fine)' ? { ...result, matches: true } : result;
});
}
describe('DashboardPage', () => {
describe('FE-PAGE-DASH-001: Unauthenticated user is redirected', () => {
it('does not render dashboard content when not authenticated', () => {
@@ -100,7 +109,8 @@ describe('DashboardPage', () => {
});
describe('FE-PAGE-DASH-005: Create Trip button opens TripFormModal', () => {
it('clicking New Trip button opens the trip form modal', async () => {
it.each(['mouse', 'touch'])('PR-3305: opening the trip form sets the right focus for %s', async (pointer) => {
if (pointer === 'mouse') mockFinePointer();
const user = userEvent.setup();
render(<DashboardPage />);
@@ -110,10 +120,9 @@ describe('DashboardPage', () => {
await user.click(screen.getAllByRole('button', { name: /new trip/i })[0]);
// TripFormModal opens — "Create New Trip" appears in heading and submit button
await waitFor(() => {
expect(screen.getAllByText(/create new trip/i).length).toBeGreaterThan(0);
});
const dialog = await screen.findByRole('dialog', { name: 'Create New Trip' });
const target = pointer === 'mouse' ? within(dialog).getByPlaceholderText(/summer in japan/i) : dialog;
expect(target).toHaveFocus();
});
});
@@ -253,7 +262,8 @@ describe('DashboardPage', () => {
});
describe('FE-PAGE-DASH-012: Edit trip opens form with pre-filled data', () => {
it('clicking edit on a trip card opens TripFormModal with trip title pre-filled', async () => {
it('PR-3305: focuses the prefilled title when editing a trip', async () => {
mockFinePointer();
const user = userEvent.setup();
render(<DashboardPage />);
@@ -266,7 +276,7 @@ describe('DashboardPage', () => {
await waitFor(() => {
const titleInput = screen.getByDisplayValue('Paris Adventure');
expect(titleInput).toBeInTheDocument();
expect(titleInput).toHaveFocus();
});
});
});
-1
View File
@@ -297,7 +297,6 @@ function DashboardPageDesktop(): React.ReactElement {
{showForm && (
<TripFormModal
isOpen={showForm}
focusTitle
trip={editingTrip}
onClose={() => { setShowForm(false); setEditingTrip(null) }}
onSave={editingTrip ? handleUpdate : handleCreate}