mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
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:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -297,7 +297,6 @@ function DashboardPageDesktop(): React.ReactElement {
|
||||
{showForm && (
|
||||
<TripFormModal
|
||||
isOpen={showForm}
|
||||
focusTitle
|
||||
trip={editingTrip}
|
||||
onClose={() => { setShowForm(false); setEditingTrip(null) }}
|
||||
onSave={editingTrip ? handleUpdate : handleCreate}
|
||||
|
||||
Reference in New Issue
Block a user