55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
// The branding module's messages: both languages, the same keys, every key asked for, and no string
|
|
// or colour literal in its components.
|
|
|
|
import { readdirSync, readFileSync } from "node:fs"
|
|
import { join } from "node:path"
|
|
import { buildRegistry } from "@conusai-kit/core"
|
|
import { lintUiStrings } from "@conusai-kit/i18n"
|
|
import { describe, expect, it } from "vitest"
|
|
import { appModules } from "../../index.js"
|
|
import { brandFormLabels } from "../ui/labels.js"
|
|
|
|
// The messages as the app has them: from the manifest, flattened and merged by the kit.
|
|
const catalogues = buildRegistry([...appModules]).catalogues
|
|
const en = catalogues.en?.branding ?? {}
|
|
const lt = catalogues.lt?.branding ?? {}
|
|
|
|
function keysUsed(): string[] {
|
|
const asked: string[] = []
|
|
brandFormLabels((key) => {
|
|
asked.push(key)
|
|
return key
|
|
}, "failed")
|
|
return asked
|
|
}
|
|
|
|
describe("the branding catalogues", () => {
|
|
it("hold the same keys in English and in Lithuanian", () => {
|
|
expect(Object.keys(lt).sort()).toEqual(Object.keys(en).sort())
|
|
})
|
|
|
|
it("hold every key the form asks for, and nothing it does not (the page asks for title and intro itself)", () => {
|
|
const asked = new Set([...keysUsed(), "title", "intro"])
|
|
for (const key of asked) {
|
|
expect(en[key as keyof typeof en], `en ${key}`).toBeTruthy()
|
|
expect(lt[key as keyof typeof lt], `lt ${key}`).toBeTruthy()
|
|
}
|
|
expect(Object.keys(en).filter((key) => !asked.has(key))).toEqual([])
|
|
})
|
|
})
|
|
|
|
describe("the components", () => {
|
|
const dir = new URL("../ui/", import.meta.url).pathname
|
|
const sources = readdirSync(dir)
|
|
.filter((name) => name.endsWith(".tsx"))
|
|
.map((name) => ({ name, text: readFileSync(join(dir, name), "utf8") }))
|
|
|
|
it("carry no hard-coded user-facing string and no colour literal", () => {
|
|
expect(sources.length).toBeGreaterThanOrEqual(3)
|
|
for (const { name, text } of sources) {
|
|
expect(lintUiStrings(text, name), name).toEqual([])
|
|
expect(text, name).not.toMatch(/#[0-9a-fA-F]{3,8}\b|\brgb\(|\bhsl\(|\boklch\(/)
|
|
}
|
|
})
|
|
})
|