#/mobile/cards shows the game without the site shell: a title, a footer with the account and a discreet "Version complète" link, and a tab bar fixed at the bottom. Phones opening #/cards are sent to the same section in mobile mode unless the player chose the full version. Account, History and Administration point to the computer. The panels are the computer ones, adapted under .nebula-mobile (and body.nebula-mobile-body for dialogs) for a 393×852 reference phone: small cards with names under them when opening packs, a revealed card shown large on tap, tap-to-pick team recruitment with a single Recruit button and large stars, row lists for explorers and commons in the expedition pickers, a race track and circuit that read at phone size, and full-width actions throughout. Firefox no longer shows a mirrored back on a flipped card. Phone Playwright journeys check that every section fits the screen with no button wrapping, then open a pack, run an expedition and recruit a team by touch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
5 KiB
JavaScript
78 lines
5 KiB
JavaScript
/**
|
|
* @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");
|
|
});
|