|
| 1 | +import { expect, test } from '../playwright/fixtures'; |
| 2 | +import { PLAYWRIGHT_BASE_URL } from '../playwright/config'; |
| 3 | +import type { Page } from '@playwright/test'; |
| 4 | +import { |
| 5 | + assertThatTimerHasStarted, |
| 6 | + assertThatTimerIsStopped, |
| 7 | + newTimeEntryResponse, |
| 8 | + startOrStopTimerWithButton, |
| 9 | + stoppedTimeEntryResponse, |
| 10 | +} from './utils/currentTimeEntry'; |
| 11 | +import { createBareTimeEntryViaApi } from './utils/api'; |
| 12 | + |
| 13 | +async function goToDashboard(page: Page) { |
| 14 | + await page.goto(PLAYWRIGHT_BASE_URL + '/dashboard'); |
| 15 | +} |
| 16 | + |
| 17 | +test('test that dashboard loads with all expected sections', async ({ page }) => { |
| 18 | + await goToDashboard(page); |
| 19 | + await expect(page.getByTestId('dashboard_view')).toBeVisible({ timeout: 10000 }); |
| 20 | + |
| 21 | + // Timer section (scoped to dashboard_timer to avoid matching sidebar timer) |
| 22 | + await expect(page.getByTestId('time_entry_description')).toBeVisible(); |
| 23 | + await expect(page.getByTestId('dashboard_timer').getByTestId('timer_button')).toBeVisible(); |
| 24 | + |
| 25 | + // Dashboard cards |
| 26 | + await expect(page.getByText('Recent Time Entries', { exact: true })).toBeVisible(); |
| 27 | + await expect(page.getByText('Last 7 Days', { exact: true })).toBeVisible(); |
| 28 | + await expect(page.getByText('Activity Graph', { exact: true })).toBeVisible(); |
| 29 | + await expect(page.getByText('Team Activity', { exact: true })).toBeVisible(); |
| 30 | + |
| 31 | + // Weekly overview section |
| 32 | + await expect(page.getByText('This Week', { exact: true })).toBeVisible(); |
| 33 | +}); |
| 34 | + |
| 35 | +test('test that dashboard shows time entry data after creating entries', async ({ page, ctx }) => { |
| 36 | + await createBareTimeEntryViaApi(ctx, 'Dashboard test entry', '1h'); |
| 37 | + |
| 38 | + await goToDashboard(page); |
| 39 | + await expect(page.getByTestId('dashboard_view')).toBeVisible(); |
| 40 | + |
| 41 | + // The "Last 7 Days" or "This Week" section should reflect tracked time |
| 42 | + await expect(page.getByText('This Week', { exact: true })).toBeVisible(); |
| 43 | +}); |
| 44 | + |
| 45 | +test('test that timer on dashboard can start and stop', async ({ page }) => { |
| 46 | + await goToDashboard(page); |
| 47 | + await Promise.all([newTimeEntryResponse(page), startOrStopTimerWithButton(page)]); |
| 48 | + await assertThatTimerHasStarted(page); |
| 49 | + |
| 50 | + await page.waitForTimeout(1500); |
| 51 | + |
| 52 | + await Promise.all([stoppedTimeEntryResponse(page), startOrStopTimerWithButton(page)]); |
| 53 | + await assertThatTimerIsStopped(page); |
| 54 | +}); |
| 55 | + |
| 56 | +test('test that weekly overview section displays stat cards', async ({ page, ctx }) => { |
| 57 | + await createBareTimeEntryViaApi(ctx, 'Stats test entry', '2h'); |
| 58 | + |
| 59 | + await goToDashboard(page); |
| 60 | + |
| 61 | + // Verify stat card labels are visible |
| 62 | + await expect(page.getByText('Spent Time')).toBeVisible(); |
| 63 | + await expect(page.getByText('Billable Time')).toBeVisible(); |
| 64 | + await expect(page.getByText('Billable Amount')).toBeVisible(); |
| 65 | +}); |
| 66 | + |
| 67 | +test('test that stopping timer refreshes dashboard data', async ({ page }) => { |
| 68 | + await goToDashboard(page); |
| 69 | + |
| 70 | + // Start timer |
| 71 | + await Promise.all([newTimeEntryResponse(page), startOrStopTimerWithButton(page)]); |
| 72 | + await assertThatTimerHasStarted(page); |
| 73 | + await page.waitForTimeout(1500); |
| 74 | + |
| 75 | + // Stop timer and verify dashboard queries are refetched |
| 76 | + await Promise.all([ |
| 77 | + stoppedTimeEntryResponse(page), |
| 78 | + page.waitForResponse( |
| 79 | + (response) => |
| 80 | + response.url().includes('/charts/') && |
| 81 | + response.request().method() === 'GET' && |
| 82 | + response.status() === 200 |
| 83 | + ), |
| 84 | + startOrStopTimerWithButton(page), |
| 85 | + ]); |
| 86 | + await assertThatTimerIsStopped(page); |
| 87 | +}); |
| 88 | + |
| 89 | +// ============================================= |
| 90 | +// Employee Permission Tests |
| 91 | +// ============================================= |
| 92 | + |
| 93 | +test.describe('Employee Dashboard Restrictions', () => { |
| 94 | + test('employee dashboard loads and timer is functional', async ({ employee }) => { |
| 95 | + await employee.page.goto(PLAYWRIGHT_BASE_URL + '/dashboard'); |
| 96 | + await expect(employee.page.getByTestId('dashboard_view')).toBeVisible({ |
| 97 | + timeout: 10000, |
| 98 | + }); |
| 99 | + |
| 100 | + // Timer should be available |
| 101 | + await expect( |
| 102 | + employee.page.getByTestId('dashboard_timer').getByTestId('timer_button') |
| 103 | + ).toBeVisible(); |
| 104 | + await expect(employee.page.getByTestId('time_entry_description')).toBeEditable(); |
| 105 | + }); |
| 106 | + |
| 107 | + test('employee cannot see Team Activity card', async ({ employee }) => { |
| 108 | + await employee.page.goto(PLAYWRIGHT_BASE_URL + '/dashboard'); |
| 109 | + await expect(employee.page.getByTestId('dashboard_view')).toBeVisible({ |
| 110 | + timeout: 10000, |
| 111 | + }); |
| 112 | + |
| 113 | + // Other dashboard cards should be visible |
| 114 | + await expect(employee.page.getByText('Recent Time Entries', { exact: true })).toBeVisible(); |
| 115 | + |
| 116 | + // Team Activity should NOT be visible for employees |
| 117 | + await expect(employee.page.getByText('Team Activity', { exact: true })).not.toBeVisible(); |
| 118 | + }); |
| 119 | +}); |
0 commit comments