From 49d3725c4c531711919c014d190e15ec8251f8d0 Mon Sep 17 00:00:00 2001 From: Copilot <223556219+Copilot@users.noreply.github.com> Date: Mon, 18 May 2026 10:22:01 +0000 Subject: [PATCH] test: add login journey, dashboard row data, and error message tests - Add login-to-dashboard E2E journey test verifying complete user outcome - Add activity table row data verification test for all 3 rows - Enhance empty form error test to assert specific error message text - Update test plan with 3 new test entries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/dashboard.spec.ts | 22 ++++++++++++++++++++++ tests/login.spec.ts | 26 ++++++++++++++++++++++++++ tests/specs/test-plan.md | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/tests/dashboard.spec.ts b/tests/dashboard.spec.ts index b27a445..c50b5c2 100644 --- a/tests/dashboard.spec.ts +++ b/tests/dashboard.spec.ts @@ -43,4 +43,26 @@ test.describe('Dashboard page', () => { const rows = table.locator('tbody tr'); await expect(rows).not.toHaveCount(0); }); + + test('should display correct data in each activity table row', async ({ page }) => { + await page.goto('/dashboard'); + + const rows = page.locator('#activity-table tbody tr'); + await expect(rows).toHaveCount(3); + + const firstRow = rows.nth(0); + await expect(firstRow.getByRole('cell', { name: 'Alice' })).toBeVisible(); + await expect(firstRow.getByRole('cell', { name: 'Created account' })).toBeVisible(); + await expect(firstRow.getByRole('cell', { name: '2026-05-14' })).toBeVisible(); + + const secondRow = rows.nth(1); + await expect(secondRow.getByRole('cell', { name: 'Bob' })).toBeVisible(); + await expect(secondRow.getByRole('cell', { name: 'Placed order' })).toBeVisible(); + await expect(secondRow.getByRole('cell', { name: '2026-05-13' })).toBeVisible(); + + const thirdRow = rows.nth(2); + await expect(thirdRow.getByRole('cell', { name: 'Charlie' })).toBeVisible(); + await expect(thirdRow.getByRole('cell', { name: 'Updated profile' })).toBeVisible(); + await expect(thirdRow.getByRole('cell', { name: '2026-05-12' })).toBeVisible(); + }); }); diff --git a/tests/login.spec.ts b/tests/login.spec.ts index 3ccc617..2b75892 100644 --- a/tests/login.spec.ts +++ b/tests/login.spec.ts @@ -64,5 +64,31 @@ test.describe('Login page', () => { const message = page.locator('#message'); await expect(message).toBeVisible(); await expect(message).toHaveClass(/error/); + await expect(message).toContainText('Username and password required'); + }); + + test('should redirect to dashboard with full content after login', async ({ page }) => { + const email = process.env.TEST_USER_EMAIL; + const password = process.env.TEST_USER_PASSWORD; + if (!email) throw new Error('TEST_USER_EMAIL is not set'); + if (!password) throw new Error('TEST_USER_PASSWORD is not set'); + + await page.goto('/login'); + await expect(page.getByRole('button', { name: 'Login' })).toBeVisible(); + + await page.getByRole('textbox', { name: 'Username' }).fill(email); + await page.getByRole('textbox', { name: 'Password' }).fill(password); + await page.getByRole('button', { name: 'Login' }).click(); + + const message = page.locator('#message'); + await expect(message).toBeVisible(); + await expect(message).toContainText('Welcome'); + + await expect(page).toHaveURL(/.*dashboard/); + + await expect(page.getByRole('heading', { name: 'Dashboard', level: 1 })).toBeVisible(); + await expect(page.locator('#user-count')).not.toBeEmpty(); + await expect(page.locator('#revenue')).not.toBeEmpty(); + await expect(page.locator('#order-count')).not.toBeEmpty(); }); }); diff --git a/tests/specs/test-plan.md b/tests/specs/test-plan.md index 5af25ca..1765ad9 100644 --- a/tests/specs/test-plan.md +++ b/tests/specs/test-plan.md @@ -41,3 +41,40 @@ Sample Web App — a React application with React Router that provides routes su Expectation: Login page loads 4. Step: Click "SampleApp" logo link Expectation: URL changes to / + +### Login → Dashboard Journey +4. **Login redirects to dashboard with full content** — `tests/login.spec.ts` + - Preconditions: TEST_USER_EMAIL and TEST_USER_PASSWORD env vars set + - Step/Expectation Pairs: + 1. Step: Navigate to /login + Expectation: Login page loads with form visible + 2. Step: Fill username and password fields with valid credentials, click Login + Expectation: Success message appears with "Welcome" text + 3. Step: Wait for redirect to complete + Expectation: URL changes to /dashboard + 4. Step: Inspect dashboard content + Expectation: Dashboard heading is visible and stat cards are present + +### Dashboard Data +5. **Activity table displays correct row data** — `tests/dashboard.spec.ts` + - Preconditions: Authenticated (storageState from auth.setup.ts) + - Step/Expectation Pairs: + 1. Step: Navigate to /dashboard + Expectation: Dashboard page loads + 2. Step: Inspect first activity row + Expectation: Row contains "Alice", "Created account", "2026-05-14" + 3. Step: Inspect second activity row + Expectation: Row contains "Bob", "Placed order", "2026-05-13" + 4. Step: Inspect third activity row + Expectation: Row contains "Charlie", "Updated profile", "2026-05-12" + +### Login Validation +6. **Empty form submission shows specific error message** — `tests/login.spec.ts` + - Preconditions: None (no auth needed) + - Step/Expectation Pairs: + 1. Step: Navigate to /login + Expectation: Login page loads + 2. Step: Bypass HTML5 required validation and submit empty form + Expectation: Error message appears with class "error" + 3. Step: Inspect error message text + Expectation: Message contains "Username and password required"