import { expect, afterEach } from "vitest";
import { cleanup } from "@testing-library/react";
import * as jestDomMatchers from "@testing-library/jest-dom/matchers";

// Extend Vitest's expect with jest-dom matchers (toBeInTheDocument, etc.)
expect.extend(jestDomMatchers);

// Ensure React Testing Library cleans up after every test
afterEach(cleanup);

// Recharts and Fluent UI rely on ResizeObserver which jsdom does not provide.
class ResizeObserverStub {
  observe() {}
  unobserve() {}
  disconnect() {}
}

globalThis.ResizeObserver = ResizeObserverStub;

// jsdom does not implement scrollIntoView.
Element.prototype.scrollIntoView = () => {};

// Fluent UI animations rely on matchMedia.
Object.defineProperty(window, "matchMedia", {
  writable: true,
  value: (query: string) => ({
    matches: false,
    media: query,
    onchange: null,
    addListener: () => {},
    removeListener: () => {},
    addEventListener: () => {},
    removeEventListener: () => {},
    dispatchEvent: () => false,
  }),
});
