Files
fristydev/components/game-profile-modal.test.tsx
fristy 864b9226fc
Build & Push / Lint & Build (pull_request) Failing after 52s
Build & Push / Build & Push Image (pull_request) Skipped
Build & Push / Trigger Deploy (pull_request) Skipped
desloppify: code health overhaul plus abuse hardening (140 green, strict 87.2)
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.
2026-09-11 23:54:59 +03:00

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();
});
});