Skip to content
Merged
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
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,36 @@ jobs:
name: dist-${{ github.sha }}
path: dist/
retention-days: 14

# Browser tests against the mock-data app (`vite --mode mock`): no Power
# Platform access and no secrets, so it runs as its own parallel job.
e2e:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: 22
cache: npm

- name: Install dependencies
run: npm ci

- name: Install Playwright browser
run: npx playwright install --with-deps chromium

- name: End-to-end tests
run: npm run test:e2e

- name: Upload Playwright report
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v7
with:
name: playwright-report-${{ github.sha }}
path: playwright-report/
retention-days: 14
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ dist-ssr
/[0-9][0-9]-*.png
/mock-*.png

# Playwright Test output (npm run test:e2e)
/test-results/
/playwright-report/
/blob-report/

# Sensitive / environment-specific material — never committed (see
# specs/003-github-actions-cicd/contracts/secrets-and-environments.contract.md)
power.config.json
Expand Down
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"vitest.explorer",
"ms-playwright.playwright"
]
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ All four workflows live in [`.github/workflows/`](.github/workflows/). Credentia
```
Pull Request
└── ci.yml ──► install → lint → type-check → build → test → secret scan → workflow lint
└─► e2e (parallel job): Playwright against the mock-data app
All must pass. Target: < 10 minutes with npm caching.

Merge to main
Expand Down Expand Up @@ -171,6 +172,14 @@ Tests:
npm run test
```

End-to-end tests (Playwright, against the mock-data app — no Power Platform needed):

```bash
npx playwright install chromium # once per machine
npm run test:e2e # headless
npm run test:e2e:ui # interactive runner
```

CI build (matches the pipeline exactly — no deploy side-effects):

```bash
Expand Down
44 changes: 44 additions & 0 deletions e2e/analytics.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import fs from 'node:fs/promises'
import type { Page } from '@playwright/test'
import { test, expect } from './fixtures'

async function exportCsv(page: Page): Promise<string> {
const downloadPromise = page.waitForEvent('download')
await page.getByRole('button', { name: 'Export CSV' }).click()
const download = await downloadPromise
expect(download.suggestedFilename()).toMatch(/\.csv$/)
// saveAs(), not path(): the VS Code extension drives a remotely connected
// browser, where the download's own path is not readable.
const savedPath = test.info().outputPath(download.suggestedFilename())
await download.saveAs(savedPath)
return fs.readFile(savedPath, 'utf-8')
}

test.beforeEach(async ({ page }) => {
await page.goto('/analytics')
await expect(page.getByRole('heading', { name: 'Medication Breakdown' })).toBeVisible()
})

test('the breakdown lists each medication with its adherence', async ({ page }) => {
const breakdown = page.getByRole('region', { name: 'Per-medication breakdown' })

await expect(breakdown.getByRole('row', { name: /^Metformin \d+ \d+ \d+%$/ })).toBeVisible()
await expect(breakdown.getByRole('row', { name: /^Insulin Glargine \d+ \d+ \d+%$/ })).toBeVisible()
})

test('Export CSV downloads the intake logs', async ({ page }) => {
const csv = await exportCsv(page)

expect(csv).toContain('Metformin')
expect(csv).toContain('Insulin Glargine')
})

test('the medication filter narrows the export', async ({ page }) => {
await page.getByRole('combobox', { name: 'Medication filter' }).click()
await page.getByRole('option', { name: 'Metformin' }).click()

const csv = await exportCsv(page)

expect(csv).toContain('Metformin')
expect(csv).not.toContain('Insulin Glargine')
})
26 changes: 26 additions & 0 deletions e2e/calendar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect } from './fixtures'

test.beforeEach(async ({ page }) => {
await page.goto('/calendar')
await expect(page.getByRole('grid', { name: 'March 2026' })).toBeVisible()
})

test('selecting a past day lists that day\'s logs', async ({ page }) => {
const dayDetail = page.getByRole('region', { name: 'Day detail' })
await expect(dayDetail).toContainText('No logs for this day.')

await page.getByRole('gridcell', { name: 'Tuesday, March 10th, 2026' }).click()

await expect(dayDetail.getByRole('heading', { name: 'March 10, 2026' })).toBeVisible()
await expect(dayDetail).toContainText('Metformin')
await expect(dayDetail).toContainText('Insulin Glargine')
})

test('month navigation moves back and returns to today', async ({ page }) => {
await page.getByRole('button', { name: 'Previous month' }).click()
await expect(page.getByRole('grid', { name: 'February 2026' })).toBeVisible()

await page.getByRole('button', { name: 'Today' }).click()
await expect(page.getByRole('grid', { name: 'March 2026' })).toBeVisible()
await expect(page.getByRole('gridcell', { name: /^Today, Wednesday, March 11th, 2026/ })).toBeVisible()
})
36 changes: 36 additions & 0 deletions e2e/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { test as base, expect, type Locator, type Page } from '@playwright/test'

// The seed data in src/mocks/mock-data.ts is built relative to "now", so the
// browser clock is pinned to keep the same doses due and overdue on every run.
// A Wednesday at noon: Metformin (06:00) is overdue, the evening doses are not.
const NOW = new Date('2026-03-11T12:00:00Z')

// The mock store lives in browser memory and resets on every full page load.
// Inside a test, move between pages with the nav links, not page.goto().
export const test = base.extend<{ pinnedClock: void }>({
pinnedClock: [
async ({ page }, run) => {
await page.clock.setFixedTime(NOW)
await run()
},
{ auto: true },
],
})

export { expect }

/** The "Active" or "Inactive" group on the Medications page. */
export function medicationSection(page: Page, name: 'Active' | 'Inactive'): Locator {
return page
.locator('section')
.filter({ has: page.getByRole('heading', { name, exact: true }) })
}

/** One medication's card: the innermost element holding both its schedule and its actions. */
export function medicationCard(page: Page, name: string): Locator {
return page
.locator('div')
.filter({ has: page.getByRole('region', { name: `Schedule for ${name}`, exact: true }) })
.filter({ has: page.getByRole('button', { name: 'Delete' }) })
.last()
}
46 changes: 46 additions & 0 deletions e2e/log-intake.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { test, expect } from './fixtures'

test('logging an overdue dose clears it from the dashboard', async ({ page }) => {
await page.goto('/')

const overdue = page.getByRole('region', { name: 'Overdue medications' })
const metformin = page.getByRole('listitem').filter({ hasText: 'Metformin' })
await expect(overdue).toContainText('Metformin')

await metformin.getByRole('button', { name: 'Log' }).click()

const dialog = page.getByRole('dialog', { name: 'Log Intake' })
await expect(dialog.getByRole('combobox', { name: 'Medication' })).toContainText('Metformin')
await expect(dialog.getByRole('button', { name: 'Taken' })).toHaveAttribute('aria-pressed', 'true')
await dialog.getByRole('button', { name: 'Log Intake' }).click()

await expect(page.getByText('Intake logged')).toBeVisible()
await expect(metformin).toContainText('Taken')
await expect(metformin.getByRole('button', { name: 'Edit Metformin log' })).toBeVisible()
await expect(overdue).toBeHidden()
})

test('an injection logged on the dashboard shows up on the calendar', async ({ page }) => {
await page.goto('/')

await page
.getByRole('listitem')
.filter({ hasText: 'Insulin Glargine' })
.getByRole('button', { name: 'Log' })
.click()

// An injection cannot be saved until a site is picked on the body map.
const dialog = page.getByRole('dialog', { name: 'Log Intake' })
const save = dialog.getByRole('button', { name: 'Log Intake' })
await expect(save).toBeDisabled()
await dialog.getByRole('button', { name: /^Abdominal Left/ }).click()
await save.click()
await expect(page.getByText('Intake logged')).toBeVisible()

await page.getByRole('link', { name: 'Calendar' }).click()

const dayDetail = page.getByRole('region', { name: 'Day detail' })
await expect(dayDetail.getByRole('heading', { name: 'March 11, 2026' })).toBeVisible()
await expect(dayDetail).toContainText('Insulin Glargine')
await expect(dayDetail).toContainText('Abdominal Left')
})
58 changes: 58 additions & 0 deletions e2e/medications.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { test, expect, medicationCard, medicationSection } from './fixtures'

test.beforeEach(async ({ page }) => {
await page.goto('/medications')
await expect(medicationSection(page, 'Active')).toContainText('Metformin')
})

test('adding a medication puts it in the Active list', async ({ page }) => {
await page.getByRole('button', { name: 'Add Medication' }).click()

const form = page.getByRole('dialog', { name: 'Add Medication' })
await form.getByLabel('Name').fill('Aspirin')
await form.getByLabel('Dosage').fill('100 mg')
await form.getByRole('combobox', { name: 'Frequency' }).click()
await page.getByRole('option', { name: 'Daily' }).click()
await form.getByRole('combobox', { name: 'Method' }).click()
await page.getByRole('option', { name: 'Pill' }).click()
await form.getByLabel('Instructions').fill('Take with food.')
await form.getByRole('button', { name: 'Save' }).click()

await expect(form).toBeHidden()
await expect(page.getByText('Aspirin saved')).toBeVisible()

const card = medicationCard(page, 'Aspirin')
await expect(medicationSection(page, 'Active')).toContainText('Aspirin')
await expect(card).toContainText('100 mg')
await expect(card).toContainText('Take with food.')
})

test('a weekly medication asks for its scheduled day', async ({ page }) => {
await page.getByRole('button', { name: 'Add Medication' }).click()

const form = page.getByRole('dialog', { name: 'Add Medication' })
await expect(form.getByRole('combobox', { name: 'Scheduled Day' })).toBeHidden()

await form.getByRole('combobox', { name: 'Frequency' }).click()
await page.getByRole('option', { name: 'Weekly', exact: true }).click()

await expect(form.getByRole('combobox', { name: 'Scheduled Day' })).toBeVisible()
})

test('switching a medication off moves it to Inactive', async ({ page }) => {
await medicationCard(page, 'Ibuprofen').getByRole('switch', { name: 'Active' }).click()

await expect(medicationSection(page, 'Inactive')).toContainText('Ibuprofen')
await expect(medicationSection(page, 'Active')).not.toContainText('Ibuprofen')
})

test('deleting a medication removes it after confirmation', async ({ page }) => {
await medicationCard(page, 'Ibuprofen').getByRole('button', { name: 'Delete' }).click()

const confirm = page.getByRole('dialog', { name: 'Delete medication?' })
await expect(confirm).toContainText('Ibuprofen')
await confirm.getByRole('button', { name: 'Delete' }).click()

await expect(page.getByText('Ibuprofen deleted')).toBeVisible()
await expect(page.getByRole('main')).not.toContainText('Ibuprofen')
})
19 changes: 19 additions & 0 deletions e2e/navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test, expect } from './fixtures'

test('the sidebar reaches every page', async ({ page }) => {
await page.goto('/')
await expect(page.getByRole('heading', { level: 1, name: 'Good afternoon, Alex' })).toBeVisible()

for (const name of ['Medications', 'Calendar', 'Analytics']) {
await page.getByRole('link', { name }).click()
await expect(page.getByRole('heading', { level: 1, name })).toBeVisible()
}

await page.getByRole('link', { name: 'Home' }).click()
await expect(page.getByRole('heading', { name: "Today's Schedule" })).toBeVisible()
})

test('a page opens directly from its URL', async ({ page }) => {
await page.goto('/calendar')
await expect(page.getByRole('heading', { level: 1, name: 'Calendar' })).toBeVisible()
})
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading