62 lines
2.3 KiB
TypeScript
62 lines
2.3 KiB
TypeScript
// The workspace page's strings as one record (F10): `load` hands over the message of a count only the browser
|
|
// knows with its placeholder in, and the view's `formatMessage` picks the language's plural form.
|
|
|
|
import { Container } from "@conusai-kit/core"
|
|
import { createI18n } from "@conusai-kit/i18n"
|
|
import { formatMessage } from "@conusai-kit/i18n/format"
|
|
import { describe, expect, it } from "vitest"
|
|
import { en } from "../i18n/en.js"
|
|
import { lt } from "../i18n/lt.js"
|
|
import { notesWorkspacePage, WORKSPACE_LABEL_KEYS } from "../ui/workspace-page.js"
|
|
|
|
const slugs = { org: "acme", workspace: "main" }
|
|
const projects = [
|
|
{ slug: "alpha", name: "Alpha" },
|
|
{ slug: "beta", name: "Beta" },
|
|
]
|
|
const load = (locale: "en" | "lt", search: Record<string, string> = {}) =>
|
|
notesWorkspacePage.load({
|
|
slugs,
|
|
segments: [],
|
|
search,
|
|
caller: { call: async () => ({ projects }) } as never,
|
|
i18n: createI18n(locale, {
|
|
en: { notes: { ...en, "workspace.selected": en.workspace.selected } },
|
|
lt: { notes: { ...lt, "workspace.selected": lt.workspace.selected } },
|
|
} as never),
|
|
container: new Container(),
|
|
})
|
|
|
|
describe("the workspace page's labels", () => {
|
|
it("cross the loader as plain strings, with the count's placeholder still in", async () => {
|
|
const data = await load("en")
|
|
expect(Object.keys(data.labels)).toEqual([...WORKSPACE_LABEL_KEYS])
|
|
expect(JSON.parse(JSON.stringify(data))).toEqual(data)
|
|
expect(data.labels.selected).toBe(en.workspace.selected)
|
|
})
|
|
|
|
it("filter on the server by `search`", async () => {
|
|
const data = await load("en", { q: " BET " })
|
|
expect(data.projects.map((project) => project.slug)).toEqual(["beta"])
|
|
expect(data.query).toBe(" BET ")
|
|
})
|
|
|
|
it.each([
|
|
[0, "0 projects selected"],
|
|
[1, "1 project selected"],
|
|
[2, "2 projects selected"],
|
|
])("read %d in English", (count, text) => {
|
|
expect(formatMessage(en.workspace.selected, { count }, "en")).toBe(text)
|
|
})
|
|
|
|
it.each([
|
|
[1, "Pasirinktas 1 projektas"],
|
|
[21, "Pasirinktas 21 projektas"],
|
|
[3, "Pasirinkti 3 projektai"],
|
|
[10, "Pasirinkta 10 projektų"],
|
|
[0, "Pasirinkta 0 projektų"],
|
|
])("read %d in Lithuanian", (count, text) => {
|
|
expect(formatMessage(lt.workspace.selected, { count }, "lt")).toBe(text)
|
|
})
|
|
})
|