2026-09-04 19:06:19 +02:00
|
|
|
|
import '@testing-library/jest-dom/vitest';
|
2026-10-17 09:58:42 +02:00
|
|
|
|
import { afterEach, beforeAll } from 'vitest';
|
2026-09-04 19:06:19 +02:00
|
|
|
|
import { cleanup } from '@testing-library/react';
|
2026-10-17 09:58:42 +02:00
|
|
|
|
import i18n from '../src/i18n';
|
|
|
|
|
|
|
|
|
|
|
|
// testy jednostowe zawsze PL (jsdom ma navigator.language en-US, więc init
|
|
|
|
|
|
// z detekcji ustawiłby EN) — wymuszamy po inicjalizacji modułu i18n.
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
|
await i18n.changeLanguage('pl');
|
|
|
|
|
|
});
|
2026-09-04 19:06:19 +02:00
|
|
|
|
|
2026-10-17 09:19:57 +02:00
|
|
|
|
// recharts (ResponsiveContainer) wymaga ResizeObserver, którego jsdom nie dostarcza.
|
|
|
|
|
|
// Stub wywołuje callback z fikcyjnym rozmiarem — wykresy renderują się w stałym 800×600.
|
|
|
|
|
|
class ResizeObserverStub {
|
|
|
|
|
|
private cb: (entries: { contentRect: { width: number; height: number } }[]) => void;
|
|
|
|
|
|
constructor(cb: (entries: { contentRect: { width: number; height: number } }[]) => void) {
|
|
|
|
|
|
this.cb = cb;
|
|
|
|
|
|
}
|
|
|
|
|
|
observe() {
|
|
|
|
|
|
this.cb([{ contentRect: { width: 800, height: 600 } }]);
|
|
|
|
|
|
}
|
|
|
|
|
|
unobserve() {}
|
|
|
|
|
|
disconnect() {}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (typeof globalThis.ResizeObserver === 'undefined') {
|
|
|
|
|
|
Object.defineProperty(globalThis, 'ResizeObserver', {
|
|
|
|
|
|
value: ResizeObserverStub,
|
|
|
|
|
|
configurable: true,
|
|
|
|
|
|
writable: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-04 19:06:19 +02:00
|
|
|
|
// vitest runs with globals:false, so RTL auto-cleanup is not registered
|
|
|
|
|
|
// automatically; clean the DOM after every test.
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
|
cleanup();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Node 25 exposes a built-in `localStorage` global whose methods are unavailable
|
|
|
|
|
|
// without a valid --localstorage-file, and vitest's jsdom environment does not
|
|
|
|
|
|
// copy window.localStorage (a prototype property) onto globalThis.
|
|
|
|
|
|
// Provide a working in-memory implementation before app code reads it at import time.
|
|
|
|
|
|
const memory = new Map<string, string>();
|
|
|
|
|
|
const storage: Storage = {
|
|
|
|
|
|
getItem: (key: string) => (memory.has(key) ? memory.get(key)! : null),
|
|
|
|
|
|
setItem: (key: string, value: string) => {
|
|
|
|
|
|
memory.set(key, String(value));
|
|
|
|
|
|
},
|
|
|
|
|
|
removeItem: (key: string) => {
|
|
|
|
|
|
memory.delete(key);
|
|
|
|
|
|
},
|
|
|
|
|
|
clear: () => {
|
|
|
|
|
|
memory.clear();
|
|
|
|
|
|
},
|
|
|
|
|
|
key: (index: number) => [...memory.keys()][index] ?? null,
|
|
|
|
|
|
get length() {
|
|
|
|
|
|
return memory.size;
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(globalThis, 'localStorage', {
|
|
|
|
|
|
value: storage,
|
|
|
|
|
|
configurable: true,
|
|
|
|
|
|
writable: true,
|
|
|
|
|
|
});
|