Honest baseline after removing 45 gaming suppressions. Structural: lib/game plus root hooks extraction, CORS origin echo, DEV_ORIGINS layering. Fixes: error-cause binding, discord 5xx split, null-cache guard, co-located tests, rejecting-fetch coverage, naming and typing cleanup, socket controller, cache bound, cascade helpers, latch resets. Hardening: per-IP rate limit on API routes, deterministic-miss UX, retry cooldown plus cap. Suite 140 green, build plus lint clean.
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
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(
|
|
<GameProfileModal
|
|
applicationId="1"
|
|
heroSeed={0}
|
|
lang="en"
|
|
iconUrl={null}
|
|
fallbackName="Fallback"
|
|
fallbackGameUrl="https://example.com"
|
|
dict={dict.discord.gameModal}
|
|
onClose={() => {}}
|
|
/>,
|
|
);
|
|
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(
|
|
<GameProfileModal
|
|
applicationId="1"
|
|
heroSeed={0}
|
|
lang="en"
|
|
iconUrl={null}
|
|
fallbackName="Fallback"
|
|
fallbackGameUrl="https://example.com"
|
|
dict={dict.discord.gameModal}
|
|
onClose={() => {}}
|
|
/>,
|
|
);
|
|
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(
|
|
<GameProfileModal
|
|
applicationId="1"
|
|
heroSeed={0}
|
|
lang="en"
|
|
iconUrl={null}
|
|
fallbackName="Fallback"
|
|
fallbackGameUrl="https://example.com"
|
|
dict={dict.discord.gameModal}
|
|
onClose={() => {}}
|
|
/>,
|
|
);
|
|
expect(await screen.findByText(dict.discord.gameModal.loadError)).toBeDefined();
|
|
});
|
|
});
|