Files
agent-desk-ng/web/lib/support-availability.locale-edge.test.mjs
mono 2f7a491666 feat: harden support, localize knowledge and add operator availability [skip ci]
Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.

Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.

Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.

Expected source tree: 0a4a7528e9.
2026-10-16 15:21:42 +00:00

54 lines
2.4 KiB
JavaScript

import assert from "node:assert/strict"
import { readFileSync } from "node:fs"
import test from "node:test"
import { loadTypeScriptModule } from "./test-support/load-typescript-module.mjs"
const helpers = loadTypeScriptModule(new URL("./support-availability.ts", import.meta.url), {}, { Date, Intl, Set })
function inTimezone(timezone, run) {
const previous = process.env.TZ
process.env.TZ = timezone
try { run() } finally {
if (previous === undefined) delete process.env.TZ
else process.env.TZ = previous
}
}
test("European vacation wall times reject the spring gap and preserve both autumn occurrences", () => {
inTimezone("Europe/Berlin", () => {
assert.equal(helpers.localDateTimeToISO("2026-03-29T02:30"), null)
assert.deepEqual(Array.from(helpers.localDateTimeCandidates("2026-10-25T02:30")), [
"2026-10-25T00:30:00.000Z", "2026-10-25T01:30:00.000Z",
])
})
})
test("half-hour DST overlaps expose both instants rather than assuming an hour", () => {
inTimezone("Australia/Lord_Howe", () => {
const values = Array.from(helpers.localDateTimeCandidates("2026-04-05T01:45"))
assert.deepEqual(values, ["2026-04-04T14:45:00.000Z", "2026-04-04T15:15:00.000Z"])
assert.equal(helpers.selectedLocalDateTimeISO("2026-04-05T01:45", values[1]), values[1])
})
})
function flatten(value, prefix = "") {
return Object.fromEntries(Object.entries(value).flatMap(([key, item]) => (
item && typeof item === "object" ? Object.entries(flatten(item, `${prefix}${key}.`)) : [[`${prefix}${key}`, item]]
)))
}
test("every availability translation and interpolation remains complete across Russian, English and Chinese", () => {
const catalogs = Object.fromEntries(["en-US", "ru-RU", "zh-CN"].map(locale => [
locale, flatten(JSON.parse(readFileSync(new URL(`../messages/${locale}.json`, import.meta.url), "utf8")).supportAvailability),
]))
const reference = catalogs["en-US"]
for (const [locale, catalog] of Object.entries(catalogs)) {
assert.deepEqual(Object.keys(catalog).sort(), Object.keys(reference).sort(), `${locale} availability keys`)
for (const [key, text] of Object.entries(catalog)) {
assert.equal(typeof text, "string", `${locale}: ${key}`)
assert.ok(text.trim(), `${locale}: ${key} is empty`)
assert.deepEqual((text.match(/\{[^}]+\}/g) ?? []).sort(), (reference[key].match(/\{[^}]+\}/g) ?? []).sort(), `${locale}: ${key} interpolation`)
}
}
})