Add "Уточняется" fallback helper + orange styling per TZ 4.1.23

This commit is contained in:
2026-04-21 23:49:10 +03:00
parent df83a587c2
commit b43c341fcb
12 changed files with 79 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import { tbdOr } from "./tbd.js";
describe("4.1.23-R: tbdOr fallback", () => {
const t = (k: string) => (k === "SHARED.TBD" ? "Уточняется" : k);
it("returns TBD string for null", () => {
expect(tbdOr(null, t)).toBe("Уточняется");
});
it("returns TBD string for undefined", () => {
expect(tbdOr(undefined, t)).toBe("Уточняется");
});
it("returns TBD string for empty string", () => {
expect(tbdOr("", t)).toBe("Уточняется");
});
it("returns TBD string for whitespace-only string", () => {
expect(tbdOr(" ", t)).toBe("Уточняется");
});
it("returns the value when non-empty string", () => {
expect(tbdOr("A320", t)).toBe("A320");
});
it("returns numeric value as-is", () => {
expect(tbdOr(42, t)).toBe(42);
});
it("returns non-string non-number values as-is", () => {
const obj = { code: "MOW" };
expect(tbdOr(obj, t)).toBe(obj);
});
it("returns 0 as-is (not treated as missing)", () => {
expect(tbdOr(0, t)).toBe(0);
});
});
+26
View File
@@ -0,0 +1,26 @@
/**
* "Уточняется" fallback per TZ §4.1.23.
*
* When a field is null / undefined / empty string / whitespace, returns
* the localized "Уточняется" label. Otherwise returns the value as-is.
*
* NOTE: Only apply to fields TZ explicitly enumerates for this fallback
* (gate, terminal, aircraft type, bag belt, dispatch type, etc.). Don't
* use as a blanket fallback for all nullable fields — Angular reference
* uses dashes/absent rendering for fields not listed in §4.1.23.
*
* Styling: callers are responsible for applying the orange color class
* (`.tbd-text` or equivalent) when rendering the fallback string.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type TFunction = (key: string, opts?: any) => string;
export function tbdOr<T>(
value: T | null | undefined,
t: TFunction,
): T | string {
if (value === null || value === undefined) return t("SHARED.TBD");
if (typeof value === "string" && value.trim() === "") return t("SHARED.TBD");
return value;
}