import { config } from "@vue/test-utils";
import { setupServer } from "msw/node";
import { handlers } from "./src/test/mocks/handlers.js";

config.global.stubs = {
  // Stub router-link and router-view by default in component tests
  "router-link": true,
  "router-view": true,
};

// Mock localStorage for stores that use it
const storage = new Map();
global.localStorage = {
  getItem: (key) => storage.get(key) ?? null,
  setItem: (key, value) => storage.set(key, value),
  removeItem: (key) => storage.delete(key),
  clear: () => storage.clear(),
};

// Start MSW server before tests
const server = setupServer(...handlers);
server.listen({ onUnhandledRequest: "bypass" });

// Clean up after each test
afterEach(() => {
  server.resetHandlers();
  storage.clear();
});
