trails/e2e/profile-weekly-distance.test.ts
Ullrich Schäfer ceda9f1877
profile-weekly-distance: weekly distance bar chart on the profile
Implements the profile-weekly-distance change (specs/profile-weekly-distance):

- getWeeklyDistance(ownerId, { publicOnly, weeks=12 }) in activities.server.ts:
  one query that gap-fills in SQL — generate_series of week-starts LEFT JOINed
  to activities — so it returns exactly 12 contiguous { weekStart, distance }
  rows with matching Postgres week boundaries, viewer-scoped, no cache, no
  schema change.
- WeeklyDistanceChart: SVG bars normalized to the busiest week (empty weeks keep
  their slot as zero-height bars), per-bar title distance, localized label;
  renders nothing when there's no distance in the window. Mounted under the
  ProfileStats header.
- i18n journal.profileStats.weeklyDistance (en + de).

Tests: WeeklyDistanceChart component (jsdom: bar count incl. zero weeks, empty
→ hidden, normalization); e2e creates an activity with distance and asserts the
chart renders. typecheck + lint + unit (journal 321) green; verified in the
browser.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 07:46:06 +02:00

26 lines
1.2 KiB
TypeScript

import { test, expect, gotoHydrated } from "./fixtures/test";
import { setupVirtualAuthenticator, registerUser } from "./helpers/auth";
// GPX with geometry → the activity has a non-zero distance, so the weekly
// chart has a bar to draw (it hides when there's no distance in the window).
const GPX = "packages/fit/__fixtures__/alpine.gpx";
test.describe("Profile weekly distance", () => {
test("profile shows the weekly distance chart when there is recent distance", async ({ page }) => {
const cdp = await page.context().newCDPSession(page);
await setupVirtualAuthenticator(cdp);
const stamp = Date.now();
const username = `wd${stamp}`;
await registerUser(page, `wd-${stamp}@example.com`, username);
await gotoHydrated(page, "/activities/new");
await page.getByLabel("Name").fill("Weekly chart check");
await page.locator('input[name="gpx"]').setInputFiles(GPX);
await page.getByRole("button", { name: "Create Activity" }).click();
await expect(page).toHaveURL(/\/activities\/[0-9a-f-]+$/, { timeout: 10000 });
await gotoHydrated(page, `/users/${username}`);
await expect(page.getByText(/Weekly distance/)).toBeVisible();
});
});