Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
26 changes: 26 additions & 0 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
37 changes: 37 additions & 0 deletions tests/specs/test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading