Spaces:
Running

WorkPilot-AI / web /e2e /rtl.spec.ts
Aynkhn's picture
Deploy WorkPilot demo (part 2)
0776bd5 verified
Raw History Blame Contribute Delete
3.07 kB
import { expect, test } from "@playwright/test";
import { en, ur } from "../src/lib/i18n/messages";
import { login, seed } from "./helpers";
// Every owner page, keyed by the nav label that links to it.
const PAGES = [
["/inbox", "inbox"],
["/runs", "runs"],
["/workflows", "workflows"],
["/chat", "chat"],
["/orders", "orders"],
["/cod", "cod"],
["/analytics", "analytics"],
["/knowledge", "knowledge"],
["/memory", "memory"],
["/integrations", "integrations"],
["/rules", "rules"],
["/settings", "settings"],
] as const satisfies readonly (readonly [string, keyof typeof en.nav])[];
// English nav labels must never appear once the UI is in Urdu. "COD" is excluded: it is also a
// payment-method code shown as data (and inside Urdu sentences).
const ENGLISH_NAV = Object.values(en.nav).filter((v) => v !== "COD");
test("Urdu switches the whole app to RTL Nastaliq", async ({ page, request }) => {
const s = await seed(request);
await login(page, s, "/inbox");
await expect(page.locator("html")).toHaveAttribute("dir", "ltr");
// The header language switcher stores the choice; it survives navigation and reloads.
await page.getByTestId("locale-toggle").click();
await expect(page.locator("html")).toHaveAttribute("dir", "rtl");
await expect(page.locator("html")).toHaveAttribute("lang", "ur");
for (const [href, key] of PAGES) {
await test.step(href, async () => {
await page.goto(href);
const html = page.locator("html");
await expect(html).toHaveAttribute("dir", "rtl");
await expect(html).toHaveAttribute("lang", "ur");
const nav = page.getByRole("navigation", { name: ur.common.mainNav });
await expect(nav).toBeVisible();
// The inbox link also carries a pending-count badge, so match the label text, not the name.
const link = nav.locator(`a[href="${href}"]`);
await expect(link).toContainText(ur.nav[key]);
await expect(link).toHaveAttribute("aria-current", "page");
await expect(page.locator("h1").first()).toHaveText(/[؀-ۿ]/);
// Let data settle so late-rendering states are checked too.
await page.waitForLoadState("networkidle");
const english = await page.evaluate((labels) => {
const hits: string[] = [];
for (const el of document.body.querySelectorAll<HTMLElement>("*")) {
if (!el.getClientRects().length) continue;
const text = el.innerText?.trim();
if (text && labels.includes(text)) hits.push(`<${el.tagName.toLowerCase()}> ${text}`);
}
return hits;
}, ENGLISH_NAV);
expect(english, `English nav labels visible on ${href}`).toEqual([]);
});
}
// Back to English, and the layout flips back.
await page.getByTestId("locale-toggle").click();
await expect(page.locator("html")).toHaveAttribute("dir", "ltr");
await expect(
page.getByRole("navigation", { name: en.common.mainNav }).getByRole("link", { name: en.nav.settings }),
).toBeVisible();
});