Files
FitOS/app/test/e2e/calendar.spec.ts

115 lines
4.2 KiB
TypeScript

import { test, expect } from './fixtures';
import { mockApi } from './mock-api';
test('dzień treningowy zapisany jako lokalna północ renderuje się w prawidłowej komórce', async ({
page,
}) => {
const now = new Date();
const localMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const month = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
const dayNumber = now.getDate();
mockApi(page);
// API zwraca datę jako ISO (UTC) lokalnej północy — np. 2026-08-24T00:00+02:00 → 2026-08-23T22:00Z.
// Wycięcie prefiksu z ISO przesunęłoby dzień o jeden w strefach przed UTC (np. Polska).
page.route(`**/api/v1/calendar?month=${month}`, (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
month,
days: [
{
id: 'day-cal',
date: localMidnight.toISOString(),
status: 'PLANNED',
dayOfWeek: 1,
exercises: [{ name: 'Przysiady', muscle: 'legs' }],
},
],
}),
}),
);
await page.goto('/login');
await page.locator('input[type="email"]').fill('test@fitos.pl');
await page.locator('input[type="password"]').fill('haslo123');
await page.getByRole('button', { name: 'Zaloguj' }).click();
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
await page.getByRole('link', { name: 'Mój kalendarz' }).click();
const chip = page.getByText('Zaplanowany: 1 ćw.').first();
await expect(chip).toBeVisible();
// Chip musi być w komórce o numerze dnia równym dzisiejszemu dniu LOKALNEMU.
const cell = chip.locator('xpath=..');
await expect(cell.locator('div').first()).toHaveText(String(dayNumber));
});
test('przesunięcie dnia z kalendarza: akcja w topmenu, dialog i PATCH move', async ({ page }) => {
const now = new Date();
const localMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const month = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
let moveBody: Record<string, unknown> | null = null;
mockApi(page);
page.route(`**/api/v1/calendar?month=${month}`, (route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
month,
days: [
{
id: 'day-cal',
date: localMidnight.toISOString(),
status: 'PLANNED',
dayOfWeek: 1,
planId: 'plan-cal',
planTitle: 'Plan testowy',
planStartDate: null,
moves: 0,
exercises: [{ name: 'Przysiady', muscle: 'legs' }],
},
],
}),
}),
);
page.route('**/api/v1/plans/plan-cal/days/day-cal/move', (route) => {
moveBody = JSON.parse(route.request().postData() ?? '{}');
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
day: { id: 'day-cal', date: localMidnight.toISOString(), status: 'PLANNED', dayOfWeek: 1 },
swappedWith: null,
}),
});
});
await page.goto('/login');
await page.locator('input[type="email"]').fill('test@fitos.pl');
await page.locator('input[type="password"]').fill('haslo123');
await page.getByRole('button', { name: 'Zaloguj' }).click();
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
await page.getByRole('link', { name: 'Mój kalendarz' }).click();
await page.getByText('Zaplanowany: 1 ćw.').first().click();
// akcja przesunięcia jest w topmenu (nie w treści karty dnia)
await expect(page.getByRole('button', { name: 'Przesuń dzień' })).toBeVisible();
await page.getByRole('button', { name: 'Przesuń dzień' }).click();
const dialog = page.getByRole('dialog');
await expect(
dialog.getByRole('heading', { name: 'Przesunięcie dnia treningowego' }),
).toBeVisible();
await expect(dialog.locator('input[type="date"]')).toBeVisible();
await dialog.getByRole('button', { name: 'Przesuń' }).click();
await expect(dialog).toBeHidden();
await expect
.poll(() => moveBody)
.toEqual(expect.objectContaining({ date: expect.stringMatching(/^\d{4}-\d{2}-\d{2}$/) }));
});