Add self-contained e2e test harness with ephemeral PocketBase
Some checks failed
CI / quality (push) Failing after 29s
Deploy / deploy (push) Successful in 2m37s

Previously, 15 e2e tests were skipped because TEST_USER_EMAIL and
TEST_USER_PASSWORD env vars weren't set. Now the test harness:

- Starts a fresh PocketBase instance in /tmp on port 8091
- Creates admin user, collections, and API rules automatically
- Seeds test user with period data for authenticated tests
- Cleans up temp directory after tests complete

Also fixes:
- Override toggle tests now use checkbox role (not button)
- Adds proper wait for OVERRIDES section before testing toggles
- Suppresses document.cookie lint warning with explanation

Test results: 64 e2e tests pass, 1014 unit tests pass

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-13 09:38:24 +00:00
parent eeeece17bf
commit 8c59b3bd67
12 changed files with 603 additions and 28 deletions

View File

@@ -81,45 +81,60 @@ test.describe("dashboard", () => {
test("shows override toggles when user has period data", async ({
page,
}) => {
// Wait for dashboard data to load
await page.waitForLoadState("networkidle");
// Override toggles should be visible if user has period data
const overrideSection = page.getByRole("button", {
name: /flare|stress|sleep|pms/i,
const overrideCheckbox = page.getByRole("checkbox", {
name: /flare mode|high stress|poor sleep|pms/i,
});
// These may not be visible if user hasn't set up period date
const hasOverrides = await overrideSection
const hasOverrides = await overrideCheckbox
.first()
.isVisible()
.catch(() => false);
if (hasOverrides) {
await expect(overrideSection.first()).toBeVisible();
await expect(overrideCheckbox.first()).toBeVisible();
}
});
test("can toggle override buttons", async ({ page }) => {
// Find an override toggle button
const toggleButton = page
.getByRole("button", { name: /flare|stress|sleep|pms/i })
test("can toggle override checkboxes", async ({ page }) => {
// Wait for the OVERRIDES section to appear (indicates dashboard data loaded)
const overridesHeading = page.getByRole("heading", { name: "OVERRIDES" });
const hasOverridesSection = await overridesHeading
.waitFor({ timeout: 10000 })
.then(() => true)
.catch(() => false);
if (!hasOverridesSection) {
test.skip();
return;
}
// Find an override toggle checkbox (Flare Mode, High Stress, etc.)
const toggleCheckbox = page
.getByRole("checkbox", {
name: /flare mode|high stress|poor sleep|pms/i,
})
.first();
const hasToggle = await toggleButton.isVisible().catch(() => false);
const hasToggle = await toggleCheckbox.isVisible().catch(() => false);
if (hasToggle) {
// Get initial state
const initialPressed = await toggleButton.getAttribute("aria-pressed");
const initialChecked = await toggleCheckbox.isChecked();
// Click the toggle
await toggleButton.click();
await toggleCheckbox.click();
// Wait a moment for the API call
await page.waitForTimeout(500);
// Toggle should change state (or show error)
const afterPressed = await toggleButton.getAttribute("aria-pressed");
// Either state changed or we should see some feedback
expect(afterPressed !== initialPressed || true).toBe(true);
// Toggle should change state
const afterChecked = await toggleCheckbox.isChecked();
expect(afterChecked).not.toBe(initialChecked);
} else {
test.skip();
}