Files
2026-11-16 04:21:21 -07:00

89 lines
5.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Project Management in French: a language change in the settings shows an open board again in the new language and
// closes its open menu. The controls, menus, card details, and All tasks show French text from the catalog
// (src/lib/i18n/messages.ts). Board names, list names, and card titles stay as the user typed them.
// A change back to English shows English again. New in RuneStone: the plugin had no translations.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke } from "../_harness/index.mjs";
import { column, loadWorkspace, openBoard, pane, setTheme } from "../_harness/pmFixture.mjs";
await runSmoke("features/pmLanguage", async ({ page }) => {
const output = await outputDir("features/pmLanguage");
await loadWorkspace(page);
await openBoard(page, "Roadmap");
const catalog = await page.evaluate(async () => (await import("/src/lib/i18n/messages.ts")).catalogs.fr);
/** The French text of a catalog key, with its values. */
const fr = (key, values = {}) => {
assert(Object.hasOwn(catalog, key), `The catalog has "${key}"`);
return catalog[key].replace(/\{(\w+)\}/g, (_, name) => values[name]);
};
const button = name => pane(page).getByRole("button", { name, exact: true });
const setLanguage = async language => {
await page.evaluate(value => window.__TEST__.writeSettings("language", value), language);
await page.waitForFunction(value => document.documentElement.lang === value, language);
};
// An open menu closes when the language changes. The board shows again in French.
await button("List actions for To do").click();
await page.getByRole("menu", { name: "List actions", exact: true }).waitFor();
await setLanguage("fr");
await page.locator(".rs-menu").waitFor({ state: "detached" });
await button(fr("More actions")).waitFor();
assert.equal(fr("More actions"), "Plus d’actions");
assert.equal(fr("Calendar"), "Calendrier");
const views = pane(page).getByRole("navigation", { name: fr("Project Management views"), exact: true });
assert.deepEqual(await views.getByRole("button").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label"))), [fr("Kanban"), fr("Gantt"), fr("Calendar")]);
for (const name of [fr("Search tasks"), fr("Manage labels"), fr("Add a list"), fr("Board scope: {name}", { name: "Roadmap" }),
fr("List actions for {name}", { name: "To do" }), fr("Collapse {name}", { name: "To do" }), fr("Actions for {name}", { name: "Card A" })]) {
assert.equal(await button(name).count() > 0, true, `The board has the control "${name}"`);
}
assert.equal(await column(page, "To do").getByRole("button", { name: fr("Add a card"), exact: true }).count(), 1);
assert.equal(await button("More actions").count(), 0, "No English control name stays");
// The text that the user typed stays unchanged.
assert.equal(await pane(page).locator(".pm-scope-label").innerText(), "Roadmap");
await page.getByRole("tab", { name: "Roadmap", exact: true }).waitFor();
assert.deepEqual(await column(page, "To do").locator(".pm-card-title").allInnerTexts(), ["Card A", "Card B", "Shared card"]);
assert.deepEqual(await pane(page).locator(".pm-column-heading h2").allInnerTexts(), ["To do", "In progress", "Done", "Review"]);
// The shared menus show French items.
await button(fr("List actions for {name}", { name: "To do" })).focus();
await page.keyboard.press("Enter");
const listMenu = page.getByRole("menu", { name: fr("List actions"), exact: true });
await listMenu.waitFor();
assert.deepEqual((await listMenu.getByRole("menuitem").allInnerTexts()).slice(0, 2), [fr("Edit list"), fr("Set list limit")]);
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await page.screenshot({ path: path.join(output, `board-menu-fr-${theme}.png`) });
}
await page.keyboard.press("Escape");
await listMenu.waitFor({ state: "detached" });
// The card details are in French. The card title stays.
await pane(page).locator(".pm-card-title", { hasText: /^Card A$/ }).click();
const editor = page.locator("dialog.pm-card-editor[open]");
await editor.waitFor();
assert.equal(await editor.getByRole("textbox", { name: fr("Title"), exact: true }).inputValue(), "Card A");
assert.ok((await editor.locator(".pm-created-at").innerText()).startsWith(fr("Created: {date}", { date: "" })));
await editor.getByRole("button", { name: fr("Save card"), exact: true }).waitFor();
await page.screenshot({ path: path.join(output, "card-fr-light.png") });
await editor.getByRole("button", { name: fr("Close card"), exact: true }).click();
await editor.waitFor({ state: "detached" });
// All tasks: the catalog name of a group without a board translates. Board names stay.
await pane(page).locator(".pm-scope").click();
await page.getByRole("menu", { name: fr("Board scope"), exact: true }).getByRole("menuitemradio", { name: fr("All tasks"), exact: true }).click();
await pane(page).locator(".pm-scope-label", { hasText: fr("All tasks") }).waitFor();
await page.getByRole("tab", { name: "Project Management", exact: true }).waitFor();
assert.deepEqual(await column(page, "To do").locator(".pm-board-group-heading").allInnerTexts(), ["Bugs · Roadmap", "Roadmap", fr("No active board")]);
await page.screenshot({ path: path.join(output, "all-tasks-fr-light.png") });
// A change back to English shows the open view in English at once.
await setLanguage("en");
await button("More actions").waitFor();
assert.equal(await pane(page).locator(".pm-scope-label").innerText(), "All tasks");
assert.deepEqual(await column(page, "To do").locator(".pm-board-group-heading").allInnerTexts(), ["Bugs · Roadmap", "Roadmap", "No active board"]);
assert.equal(await button(fr("More actions")).count(), 0);
console.log("PASS: French controls, menus, and card details, with the typed names unchanged");
}, { timeout: 15000 });