/**
 * Vitest global test setup for apps/pwa.
 *
 * This file runs before each test file, before module imports that trigger
 * module-level side effects (e.g. Zustand store initialisation calls
 * window.matchMedia at create() time).
 *
 * Polyfills required for jsdom:
 *   - window.matchMedia: used by calendarStore to resolve the default view
 *     from viewport width at store initialisation time.
 */

// Extend Vitest's expect with jest-dom matchers (toHaveTextContent, etc.)
import '@testing-library/jest-dom';

// Polyfill window.matchMedia for jsdom.
// jsdom does not implement the CSSOM MediaQueryList API.
// calendarStore.ts calls window.matchMedia during Zustand create(), so this
// must be set before the store module is imported in any test.
Object.defineProperty(window, 'matchMedia', {
  writable: true,
  value: (query: string) => ({
    matches: false, // tablet-desktop default — week-start-day tests are unaffected
    media: query,
    onchange: null,
    addListener: () => undefined,
    removeListener: () => undefined,
    addEventListener: () => undefined,
    removeEventListener: () => undefined,
    dispatchEvent: () => false,
  }),
});
