App: testy: stabilna data 'wczoraj' w ProfileOverview (rozbieznosc UTC/lokalna przy toISOString)
This commit is contained in:
@@ -8,6 +8,19 @@ import { useAuth } from '../src/store/auth';
|
||||
import { setAccessToken } from '../src/api/client';
|
||||
import type { User } from '../src/api/types';
|
||||
|
||||
// „Wczoraj" wg kalendarza lokalnego — wspólna podstawa mocków i oczekiwań,
|
||||
// żeby toISOString() (UTC) nie rozmijało się z toLocaleDateString (lokalna)
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
const YESTERDAY_ISO = `${yesterday.getFullYear()}-${String(yesterday.getMonth() + 1).padStart(2, '0')}-${String(
|
||||
yesterday.getDate(),
|
||||
).padStart(2, '0')}`;
|
||||
const YESTERDAY_PL = yesterday.toLocaleDateString('pl-PL', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
});
|
||||
|
||||
const USER: User = {
|
||||
id: 'u1',
|
||||
email: 'jan@test.local',
|
||||
@@ -57,7 +70,7 @@ function mockApi() {
|
||||
status: 'COMPLETED',
|
||||
startedAt: new Date(Date.now() - 86400000).toISOString(),
|
||||
endedAt: new Date(Date.now() - 86400000 + 3600000).toISOString(),
|
||||
date: new Date(Date.now() - 86400000).toISOString().slice(0, 10),
|
||||
date: YESTERDAY_ISO,
|
||||
dayOfWeek: 1,
|
||||
plan: 'Plan A',
|
||||
exercises: [
|
||||
@@ -194,11 +207,7 @@ describe('Profile overview — hero, statystyki i wiersze sekcji', () => {
|
||||
|
||||
// historia: liczba sesji (polska odmiana) + data ostatniej (wczoraj)
|
||||
const histRow = screen.getByRole('link', { name: /Historia treningów/ });
|
||||
const lastDate = new Date(Date.now() - 86400000).toLocaleDateString('pl-PL', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
});
|
||||
const lastDate = YESTERDAY_PL;
|
||||
expect(histRow).toHaveTextContent(`3 sesje · ostatnia ${lastDate}`);
|
||||
|
||||
// siłownie: nazwy (sidebar ma też link „Siłownie" — wiersz niesie nazwę siłowni)
|
||||
@@ -216,11 +225,7 @@ describe('Profile overview — hero, statystyki i wiersze sekcji', () => {
|
||||
// tytuł podstrony jest tylko w topmenu (nagłówek Layout)
|
||||
expect(await screen.findByRole('heading', { name: 'Profil — historia' })).toBeInTheDocument();
|
||||
// pełna sekcja na podstronie (nagłówek sesji: data · plan)
|
||||
const lastDate = new Date(Date.now() - 86400000).toLocaleDateString('pl-PL', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
});
|
||||
const lastDate = YESTERDAY_PL;
|
||||
expect(screen.getByText(`${lastDate} · Plan A`)).toBeInTheDocument();
|
||||
|
||||
// wstecz wraca na przegląd („Wstecz” jest w topmenu i w treści — oba prowadzą do /profile)
|
||||
|
||||
Reference in New Issue
Block a user