diff --git a/e2e/command-palette.spec.ts b/e2e/command-palette.spec.ts index 013f0138..535a4900 100644 --- a/e2e/command-palette.spec.ts +++ b/e2e/command-palette.spec.ts @@ -31,15 +31,21 @@ async function selectCommand(page: Page, name: string) { } async function assertTimerIsRunning(page: Page) { - await expect(page.locator(TIMER_BUTTON_SELECTOR)).toHaveClass(/bg-red-400\/80/, { - timeout: 10000, - }); + await expect(page.locator(TIMER_BUTTON_SELECTOR).and(page.locator(':visible'))).toHaveClass( + /bg-red-400\/80/, + { + timeout: 10000, + } + ); } async function assertTimerIsStopped(page: Page) { - await expect(page.locator(TIMER_BUTTON_SELECTOR)).toHaveClass(/bg-accent-300\/70/, { - timeout: 10000, - }); + await expect(page.locator(TIMER_BUTTON_SELECTOR).and(page.locator(':visible'))).toHaveClass( + /bg-accent-300\/70/, + { + timeout: 10000, + } + ); } test.describe('Command Palette', () => { diff --git a/e2e/dashboard.spec.ts b/e2e/dashboard.spec.ts index 79dba6b7..2799a3f0 100644 --- a/e2e/dashboard.spec.ts +++ b/e2e/dashboard.spec.ts @@ -25,7 +25,12 @@ test('test that dashboard loads with all expected sections', async ({ page }) => // Timer section (scoped to dashboard_timer to avoid matching sidebar timer) await expect(page.getByTestId('time_entry_description')).toBeVisible(); - await expect(page.getByTestId('dashboard_timer').getByTestId('timer_button')).toBeVisible(); + await expect( + page + .getByTestId('dashboard_timer') + .getByTestId('timer_button') + .and(page.locator(':visible')) + ).toBeVisible(); // Dashboard cards await expect(page.getByText('Recent Time Entries', { exact: true })).toBeVisible(); @@ -104,7 +109,10 @@ test.describe('Employee Dashboard Restrictions', () => { // Timer should be available await expect( - employee.page.getByTestId('dashboard_timer').getByTestId('timer_button') + employee.page + .getByTestId('dashboard_timer') + .getByTestId('timer_button') + .and(employee.page.locator(':visible')) ).toBeVisible(); await expect(employee.page.getByTestId('time_entry_description')).toBeEditable(); }); diff --git a/e2e/time.spec.ts b/e2e/time.spec.ts index c5fa5ab9..0b5e23d3 100644 --- a/e2e/time.spec.ts +++ b/e2e/time.spec.ts @@ -1450,7 +1450,10 @@ test.describe('Employee Time Entry Isolation', () => { await employee.page.goto(PLAYWRIGHT_BASE_URL + '/time'); await expect( - employee.page.getByTestId('dashboard_timer').getByTestId('timer_button') + employee.page + .getByTestId('dashboard_timer') + .getByTestId('timer_button') + .and(employee.page.locator(':visible')) ).toBeVisible({ timeout: 10000 }); // Employee's time entry IS visible diff --git a/e2e/timetracker.spec.ts b/e2e/timetracker.spec.ts index 9c63eb16..55e222b4 100644 --- a/e2e/timetracker.spec.ts +++ b/e2e/timetracker.spec.ts @@ -354,7 +354,10 @@ test('test that timer started on dashboard is visible on time page', async ({ pa // Timer should still be running (the timer button should be red/active) await expect( - page.locator('[data-testid="dashboard_timer"] [data-testid="timer_button"]') + page + .getByTestId('dashboard_timer') + .getByTestId('timer_button') + .and(page.locator(':visible')) ).toHaveClass(/bg-red-400\/80/); // Stop the timer diff --git a/e2e/utils/currentTimeEntry.ts b/e2e/utils/currentTimeEntry.ts index 3c543d82..6b5986ba 100644 --- a/e2e/utils/currentTimeEntry.ts +++ b/e2e/utils/currentTimeEntry.ts @@ -2,12 +2,19 @@ import { expect } from '@playwright/test'; import type { Page } from '@playwright/test'; export async function startOrStopTimerWithButton(page: Page) { - await page.locator('[data-testid="dashboard_timer"] [data-testid="timer_button"]').click(); + await page + .getByTestId('dashboard_timer') + .getByTestId('timer_button') + .and(page.locator(':visible')) + .click(); } export async function assertThatTimerHasStarted(page: Page) { await expect( - page.locator('[data-testid="dashboard_timer"] [data-testid="timer_button"]') + page + .getByTestId('dashboard_timer') + .getByTestId('timer_button') + .and(page.locator(':visible')) ).toHaveClass(/bg-red-400\/80/); } @@ -34,7 +41,10 @@ export function newTimeEntryResponse( export async function assertThatTimerIsStopped(page: Page) { await expect( - page.locator('[data-testid="dashboard_timer"] [data-testid="timer_button"]') + page + .getByTestId('dashboard_timer') + .getByTestId('timer_button') + .and(page.locator(':visible')) ).toHaveClass(/bg-accent-300\/70/); }