62 lines
2.9 KiB
TypeScript
62 lines
2.9 KiB
TypeScript
import { createElement } from "react";
|
||
import { renderToStaticMarkup } from "react-dom/server";
|
||
import { describe, expect, it } from "vitest";
|
||
|
||
import { TakumiImageExport } from "@/components/public/takumi-image-export";
|
||
import { exportFixtures } from "@/lib/image-export/fixtures";
|
||
import { MaterialPoster } from "@/components/public/material-poster";
|
||
import { ConstellationImage } from "@/lib/image-export/templates/constellation";
|
||
import type { PublicGuide } from "@/lib/guides/queries";
|
||
|
||
describe("image export controls", () => {
|
||
it("always offers both export modes even without notes", () => {
|
||
const html = renderToStaticMarkup(<TakumiImageExport template={exportFixtures[0]} fileName="guide.png"/>);
|
||
expect(html).toContain("ส่งออกภาพ");
|
||
expect(html).toContain("ส่งออกภาพโดยไม่รวมโน้ต");
|
||
expect(html.match(/<button\b/gu)).toHaveLength(2);
|
||
});
|
||
|
||
it("shows only the Thai export button when no-note export is disabled", () => {
|
||
const html = renderToStaticMarkup(<TakumiImageExport template={exportFixtures[0]} fileName="guide.png" allowWithoutNotes={false}/>);
|
||
expect(html).toContain("ส่งออกภาพ");
|
||
expect(html).not.toContain("ส่งออกภาพโดยไม่รวมโน้ต");
|
||
expect(html.match(/<button\b/gu)).toHaveLength(1);
|
||
});
|
||
|
||
it("disables both modes when an export selection is empty", () => {
|
||
const html = renderToStaticMarkup(<TakumiImageExport template={exportFixtures[0]} fileName="guide.png" disabled/>);
|
||
expect(html.match(/\sdisabled=""/gu)).toHaveLength(2);
|
||
});
|
||
|
||
it.each(["English note", "โน้ตภาษาไทย"])("marks constellation notes for omission regardless of language: %s", (note) => {
|
||
const guide = { character: { name: "Raiden", splashImageUrl: "/splash.png" }, coverUrl: "/cover.png" } as PublicGuide;
|
||
const group = { rows: [], note } as unknown as PublicGuide["constellationGroups"][number];
|
||
const html = renderToStaticMarkup(createElement(ConstellationImage, { guide, group }));
|
||
expect(html).toContain("Raiden’s Constellations");
|
||
expect(html).toContain("Team Damage");
|
||
expect(html).toContain('data-export-note="true"');
|
||
expect(html).toContain(note);
|
||
});
|
||
});
|
||
|
||
|
||
describe("material poster text", () => {
|
||
const props = {
|
||
character: { name: "Raiden", nameCardImageUrl: null, baseStats: [], ascension: [], leveling: [] },
|
||
characterArtUrl: null,
|
||
artworkOffsetX: 0,
|
||
artworkOffsetY: 0,
|
||
artworkScale: 100,
|
||
topColors: ["#000000", "#000000"] as [string, string],
|
||
bottomColors: ["#000000", "#000000"] as [string, string],
|
||
};
|
||
|
||
it("always uses English, including on the website", () => {
|
||
const html = renderToStaticMarkup(<MaterialPoster {...props} />);
|
||
expect(html).toContain("MATERIALS");
|
||
expect(html).toContain("LV.90");
|
||
expect(html).not.toContain("วัสดุ");
|
||
expect(html).not.toContain("เลเวล 90");
|
||
});
|
||
});
|