import { afterEach, describe, expect, it, vi } from "vitest"; import { render, screen } from "@testing-library/react"; import { GameProfileModal } from "@/components/game-profile-modal"; import { getDictionary } from "@/lib/i18n/get-dictionary"; import { profileFixture } from "@/test/fixtures"; afterEach(() => { vi.unstubAllGlobals(); }); describe("GameProfileModal", () => { it("loads and renders the game profile", async () => { vi.stubGlobal( "fetch", vi.fn(async () => ({ ok: true, json: async () => profileFixture() }) as Response), ); const dict = getDictionary("en"); render( {}} />, ); expect(await screen.findByText("Test Game")).toBeDefined(); expect(screen.getByText("A test game")).toBeDefined(); }); it("shows no-game-data without retry on deterministic miss", async () => { const deterministic = profileFixture({ steamId: null, steamUrl: null, sources: { igdb: false, steam: false, itad: false }, }); vi.stubGlobal( "fetch", vi.fn(async () => ({ ok: true, json: async () => deterministic }) as Response), ); const dict = getDictionary("en"); render( {}} />, ); expect(await screen.findByText(dict.discord.gameModal.noGameData)).toBeDefined(); expect(screen.queryByText(dict.discord.gameModal.retry)).toBeNull(); }); it("shows the error state with retry", async () => { vi.stubGlobal( "fetch", vi.fn(async () => ({ ok: false, status: 500 }) as Response), ); const dict = getDictionary("en"); render( {}} />, ); expect(await screen.findByText(dict.discord.gameModal.loadError)).toBeDefined(); }); });