mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
test(achievements): coverage for evaluators + UI states
Three new layers of coverage for the v1.4.18 expansion set: - Unit (expansion-metrics.test.ts) — drives synthetic data through every new evaluator (count by type, mood mean improvement, weekend warrior, hidden Easter-egg triggers including the Berlin TZ classifier for night-owl / early-bird) and the earnability flag builder. 13 new assertions. - Integration (achievements-expansion.test.ts) — round-trips real prisma rows (MoodEntry's YYYY-MM-DD `date` string, Measurement type discrimination, audit log row) through `buildExpansionMetricValues` so a schema drift in any of the row shapes surfaces here rather than at runtime. We don't drive the full HTTP route in this spec because of pre-existing medication_schedules.days_of_week migration drift. - E2E (achievements.spec.ts) — the existing sidebar smoke gets a sibling describe-block exercising all four card states (unlocked / locked-earnable / hidden-locked / hidden-unlocked) and asserting hidden-locked cards never leak their real strings to the rendered HTML, which is the entire point of the "hidden" state. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b88f2de865
commit
6912d4e2b6
3 files changed
+601
No files matched your search
@@ -11,6 +11,11 @@ import { STORAGE_STATE_PATH } from "./setup/global-setup";
|
||||
* `/api/gamification/achievements` so the assertion does not depend on
|
||||
* the seed user actually having any achievement data — the routing +
|
||||
* sidebar wiring is what matters here, not the data freshness.
|
||||
*
|
||||
* v1.4.18 — added a second describe-block exercising the four card
|
||||
* states (unlocked / locked-earnable / hidden-locked / hidden-unlocked)
|
||||
* and asserting that hidden cards never leak their real strings to the
|
||||
* DOM.
|
||||
*/
|
||||
test.describe("achievements page is reachable from the sidebar", () => {
|
||||
test.use({ storageState: STORAGE_STATE_PATH });
|
||||
@@ -84,3 +89,140 @@ test.describe("achievements page is reachable from the sidebar", () => {
|
||||
).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("achievements page renders all four card states", () => {
|
||||
test.use({ storageState: STORAGE_STATE_PATH });
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.route("**/api/gamification/achievements", (route) =>
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
summary: {
|
||||
unlockedCount: 2,
|
||||
totalCount: 4,
|
||||
earnedPoints: 43,
|
||||
totalPoints: 200,
|
||||
completionPercent: 50,
|
||||
nextAchievement: null,
|
||||
},
|
||||
achievements: [
|
||||
// Unlocked public
|
||||
{
|
||||
id: "intake-total-1",
|
||||
metric: "totalTakenIntakes",
|
||||
category: "medication",
|
||||
titleKey: "achievements.badges.intakeTotal1.title",
|
||||
descriptionKey:
|
||||
"achievements.badges.intakeTotal1.description",
|
||||
icon: "Pill",
|
||||
format: "count",
|
||||
target: 1,
|
||||
current: 5,
|
||||
points: 8,
|
||||
unlocked: true,
|
||||
progressPercent: 100,
|
||||
completedAt: "2026-04-15T12:00:00.000Z",
|
||||
isHidden: false,
|
||||
},
|
||||
// Locked-earnable public (mood streak — user has mood data)
|
||||
{
|
||||
id: "mood-streak-7",
|
||||
metric: "moodDayStreak",
|
||||
category: "mood",
|
||||
titleKey: "achievements.badges.moodStreak7.title",
|
||||
descriptionKey:
|
||||
"achievements.badges.moodStreak7.description",
|
||||
icon: "Smile",
|
||||
format: "days",
|
||||
target: 7,
|
||||
current: 3,
|
||||
points: 50,
|
||||
unlocked: false,
|
||||
progressPercent: 42,
|
||||
completedAt: null,
|
||||
isHidden: false,
|
||||
},
|
||||
// Hidden + locked → opaque placeholder
|
||||
{
|
||||
id: "hidden-night-owl",
|
||||
metric: "nightOwlCount",
|
||||
category: "hidden",
|
||||
titleKey: "achievements.badges.hiddenNightOwl.title",
|
||||
descriptionKey:
|
||||
"achievements.badges.hiddenNightOwl.description",
|
||||
icon: "Moon",
|
||||
format: "count",
|
||||
target: 1,
|
||||
current: 0,
|
||||
points: 25,
|
||||
unlocked: false,
|
||||
progressPercent: 0,
|
||||
completedAt: null,
|
||||
isHidden: true,
|
||||
},
|
||||
// Hidden + unlocked → real strings revealed
|
||||
{
|
||||
id: "hidden-doctor-pdf",
|
||||
metric: "doctorPdfCount",
|
||||
category: "hidden",
|
||||
titleKey: "achievements.badges.hiddenDoctorPdf.title",
|
||||
descriptionKey:
|
||||
"achievements.badges.hiddenDoctorPdf.description",
|
||||
icon: "FileText",
|
||||
format: "count",
|
||||
target: 1,
|
||||
current: 1,
|
||||
points: 35,
|
||||
unlocked: true,
|
||||
progressPercent: 100,
|
||||
completedAt: "2026-04-30T10:00:00.000Z",
|
||||
isHidden: true,
|
||||
},
|
||||
],
|
||||
metrics: {},
|
||||
},
|
||||
error: null,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test("renders unlocked, locked-earnable, hidden-locked and hidden-unlocked cards", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/achievements", { waitUntil: "domcontentloaded" });
|
||||
|
||||
// Page heading present
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Achievements" }),
|
||||
).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Unlocked public — title visible
|
||||
await expect(page.getByText("First intake")).toBeVisible();
|
||||
|
||||
// Locked-earnable public — title visible AND criterion hint
|
||||
// visible (3 / 7 days for mood-streak-7).
|
||||
await expect(page.getByText("Mood diarist 7d")).toBeVisible();
|
||||
|
||||
// Hidden-locked — opaque placeholder visible. The real title /
|
||||
// description must NOT appear in the rendered HTML.
|
||||
await expect(
|
||||
page.getByText("Hidden achievement").first(),
|
||||
).toBeVisible();
|
||||
const html = await page.content();
|
||||
expect(html).not.toContain("Night owl");
|
||||
expect(html).not.toContain("between 02:00");
|
||||
expect(html).not.toContain("nightOwlCount");
|
||||
|
||||
// Hidden-unlocked — title revealed once earned
|
||||
await expect(page.getByText("House call")).toBeVisible();
|
||||
|
||||
// The opaque hidden card carries the data-slot for E2E hooks
|
||||
await expect(
|
||||
page.locator('[data-slot="achievement-card-hidden"]'),
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user