From 777b68f87b8c11376c6ca462ff11ce268147b090 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 18 Apr 2026 11:45:19 +0200 Subject: [PATCH] fix tests for sidebar/settings refactor + weather archive fallback - DayPlanSidebar: add aria-label to undo button, replace title with aria-label so tests can still locate buttons by accessible name after tooltip refactor - tests: switch getByTitle("Add Note") to getByLabelText - tests: find undo button via aria-label (new expand/collapse button also uses width:30, breaking the old style-based lookup) - PlacesSidebar tests: loosen "All" button regex to account for count badge - DisplaySettingsTab tests: use getByRole for Auto button (two "Auto" spans coexist for mobile/desktop); handle multiple English matches in lang test - weatherService tests: past-date case now expects an archive fetch instead of an immediate no_forecast error --- .../Planner/DayPlanSidebar.test.tsx | 28 +++++-------------- .../src/components/Planner/DayPlanSidebar.tsx | 1 + .../components/Planner/PlacesSidebar.test.tsx | 2 +- .../Settings/DisplaySettingsTab.test.tsx | 17 ++++++----- .../unit/services/weatherService.test.ts | 27 ++++++++++++++++-- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/client/src/components/Planner/DayPlanSidebar.test.tsx b/client/src/components/Planner/DayPlanSidebar.test.tsx index 07125d9e..fb0d1187 100644 --- a/client/src/components/Planner/DayPlanSidebar.test.tsx +++ b/client/src/components/Planner/DayPlanSidebar.test.tsx @@ -187,7 +187,7 @@ describe('DayPlanSidebar', () => { const assignments = { '10': [assignment] } render() // The chevron button immediately follows the "Add Note" button (which has a title attribute) - const addNoteBtn = screen.getByTitle('Add Note') + const addNoteBtn = screen.getByLabelText('Add Note') const chevron = addNoteBtn.nextElementSibling as HTMLButtonElement expect(chevron).toBeTruthy() await user.click(chevron) @@ -201,7 +201,7 @@ describe('DayPlanSidebar', () => { const assignment = buildAssignment({ id: 99, day_id: 10, order_index: 0, place }) const assignments = { '10': [assignment] } render() - const getChevron = () => screen.getByTitle('Add Note').nextElementSibling as HTMLButtonElement + const getChevron = () => screen.getByLabelText('Add Note').nextElementSibling as HTMLButtonElement await user.click(getChevron()) // collapse expect(screen.queryByText('Eiffel Tower')).not.toBeInTheDocument() await user.click(getChevron()) // re-expand @@ -362,28 +362,14 @@ describe('DayPlanSidebar', () => { const user = userEvent.setup() const onUndo = vi.fn() render() - // Find the undo button — it has width 30, height 30 and is not disabled - const buttons = screen.getAllByRole('button') - // The undo button is the one with the Undo2 icon and is not disabled - const undoBtn = buttons.find(btn => { - const style = btn.getAttribute('style') || '' - return style.includes('width: 30px') || style.includes('width:30px') || (style.includes('30') && !btn.disabled) - }) - if (undoBtn) { - await user.click(undoBtn) - expect(onUndo).toHaveBeenCalled() - } + const undoBtn = screen.getByLabelText('Undo') + await user.click(undoBtn) + expect(onUndo).toHaveBeenCalled() }) it('FE-PLANNER-DAYPLAN-024: undo button not present when onUndo not provided', () => { render() - // When onUndo is not provided, the undo section is not rendered at all - const buttons = screen.getAllByRole('button') - const undoBtn = buttons.find(btn => { - const style = btn.getAttribute('style') || '' - return style.includes('width: 30px') - }) - expect(undoBtn).toBeUndefined() + expect(screen.queryByLabelText('Undo')).toBeNull() }) // ── PDF export ────────────────────────────────────────────────────────── @@ -931,7 +917,7 @@ describe('DayPlanSidebar', () => { const user = userEvent.setup() const day = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' }) render() - const addNoteBtn = screen.getByTitle('Add Note') + const addNoteBtn = screen.getByLabelText('Add Note') await user.click(addNoteBtn) expect(mockDayNotesState.openAddNote).toHaveBeenCalled() }) diff --git a/client/src/components/Planner/DayPlanSidebar.tsx b/client/src/components/Planner/DayPlanSidebar.tsx index a9c99e40..7a100c09 100644 --- a/client/src/components/Planner/DayPlanSidebar.tsx +++ b/client/src/components/Planner/DayPlanSidebar.tsx @@ -1074,6 +1074,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar({