/** * @file Vérifie le mode mobile de dépannage de Sokko TCG sans navigateur : adresses des sections, règle de * redirection des téléphones, liens internes des panneaux et textes des onglets. * * Attention : le parcours dans un téléphone simulé est dans e2e/nebula-cards-mobile.spec.js. * @see DESIGN_SYSTEM.md (section 24, « Mode mobile de dépannage ») */ import assert from "node:assert/strict"; import { readdir, readFile } from "node:fs/promises"; import { join } from "node:path"; import test from "node:test"; import { CARDS_BASE, MOBILE_CARDS_BASE, MOBILE_SECTIONS, cardsRoute, isMobileCardsRoute, mobileRedirectTarget, parseMobileCardsRoute } from "../website/src/features/cards/cardsRoutes.js"; const phone = { phone: true, fullVersion: false }; test("section routes share their shape between the full version and the mobile mode", () => { assert.equal(cardsRoute(CARDS_BASE), "/cards"); assert.equal(cardsRoute(CARDS_BASE, "home"), "/cards"); assert.equal(cardsRoute(MOBILE_CARDS_BASE, "packs"), "/mobile/cards/packs"); assert.equal(cardsRoute(MOBILE_CARDS_BASE, "expeditions", "abc-123"), "/mobile/cards/expeditions/abc-123"); assert.equal(isMobileCardsRoute("/mobile/cards"), true); assert.equal(isMobileCardsRoute("/mobile/cards/guild"), true); assert.equal(isMobileCardsRoute("/mobile/cardsx"), false); assert.equal(isMobileCardsRoute("/cards/guild"), false); assert.deepEqual(parseMobileCardsRoute("/mobile/cards"), { section: "", subsection: "" }); assert.deepEqual(parseMobileCardsRoute("/mobile/cards/expeditions/abc-123"), { section: "expeditions", subsection: "abc-123" }); }); test("a phone opening a game section offered on mobile goes to the same section in the mobile mode", () => { assert.equal(mobileRedirectTarget("/cards", phone), "/mobile/cards"); assert.equal(mobileRedirectTarget("/cards/packs", phone), "/mobile/cards/packs"); assert.equal(mobileRedirectTarget("/cards/daily", phone), "/mobile/cards/daily"); // Lien d'invitation à une expédition de groupe : le complément d'adresse suit. assert.equal(mobileRedirectTarget("/cards/expeditions/abc-123", phone), "/mobile/cards/expeditions/abc-123"); // Ancienne adresse du recyclage, aujourd'hui dans la Collection. assert.equal(mobileRedirectTarget("/cards/recycling", phone), "/mobile/cards/recycling"); }); test("sections kept on the computer, the rest of the site and other devices are never redirected", () => { for (const route of ["/cards/account", "/cards/history", "/cards/admin", "/cards/admin/guild/team", "/cards/unknown"]) assert.equal(mobileRedirectTarget(route, phone), "", route); for (const route of ["/", "/toolboxes", "/toolbox/abc", "/receive/abc", "/games/mhwilds", "/cardsx", "/mobile/cards"]) assert.equal(mobileRedirectTarget(route, phone), "", route); assert.equal(mobileRedirectTarget("/cards/packs", { phone: false, fullVersion: false }), ""); assert.equal(mobileRedirectTarget("/cards/packs", { phone: true, fullVersion: true }), ""); }); test("every mobile section is a player section, and every tab has its label", async () => { const page = await readFile("website/src/features/cards/CardsPage.jsx", "utf8"); const navigation = JSON.parse(page.match(/const PLAYER_NAVIGATION = (\[.+\]);/)[1]); const subsections = Object.keys(JSON.parse(page.match(/const SUBSECTION_PARENTS = (\{.+\});/)[1].replace(/(\w+):/g, "\"$1\":"))); const playerSections = new Set([...navigation.flat(), ...subsections]); for (const section of MOBILE_SECTIONS) assert.ok(playerSections.has(section), `${section} is not a player section`); for (const section of ["account", "history"]) assert.equal(MOBILE_SECTIONS.has(section), false, `${section} stays on the computer`); const layout = await readFile("website/src/features/cards/mobile/MobileCardsLayout.jsx", "utf8"); const tabs = JSON.parse(layout.match(/const MOBILE_TABS = (\[.+\]);/)[1]); const site = JSON.parse(await readFile("website/public/data/site.json", "utf8")); for (const tab of tabs) { assert.ok(MOBILE_SECTIONS.has(tab), `tab ${tab} is not offered on mobile`); assert.ok(site.cards.mobile.tabs[tab], `tab ${tab} has no label`); } }); test("player panels never hard-code a #/cards link, so a phone player stays in the mobile mode", async () => { const root = "website/src/features/cards"; const files = (await readdir(root, { recursive: true })).filter((path) => /\.jsx?$/.test(path) && !path.startsWith("admin")); const offenders = []; for (const path of files) { const lines = (await readFile(join(root, path), "utf8")).split("\n"); lines.forEach((line, index) => { // Un lien interne commence par « #/cards » dans une chaîne ; l'administration garde sa propre adresse. // Les liens à partager (`${origin}/#/cards/...`) ne sont pas concernés : la redirection s'occupe des téléphones. if (/^\s*(\*|\/\/|\/\*)/.test(line)) return; if (/["'`]#\/cards(?!\/admin)/.test(line)) offenders.push(`${path}:${index + 1}`); }); } assert.deepEqual(offenders, [], "use useCardsHref() (website/src/features/cards/useCardsHref.js) instead"); });