Open History to see the last commit
1import { mFallback } from "gt-i18n";
2import type { M } from "gt-i18n";
3import { describe, expect, it } from "vite-plus/test";
4
5import {
6 decodeThirdPartyLicenseManifest,
7 filterThirdPartyLicenseEntries,
8 formatLicenseBundles,
9 thirdPartyLicenseEntryKey,
10 type ThirdPartyLicenseEntry,
11} from "./thirdPartyLicenses.js";
12
13const ENTRIES: ReadonlyArray<ThirdPartyLicenseEntry> = [
14 {
15 bundles: ["web"],
16 kind: "package",
17 license: "MIT",
18 name: "react",
19 noticeText: "React license",
20 sourceUrl: "https://react.dev",
21 version: "19.2.6",
22 },
23 {
24 bundles: ["assets", "mobile"],
25 kind: "custom",
26 license: "CC-BY-4.0",
27 name: "sample-icons",
28 noticeText: "Icon notice",
29 sourceUrl: null,
30 version: null,
31 },
32];
33
34describe("third-party license manifests", () => {
35 it("rejects unsafe source links", () => {
36 expect(() =>
37 decodeThirdPartyLicenseManifest({
38 schemaVersion: 1,
39 entries: [{ ...ENTRIES[0]!, sourceUrl: "javascript:alert(1)" }],
40 }),
41 ).toThrow("invalid shape");
42 });
43
44 it("uses distinct navigation keys when names and versions contain delimiters", () => {
45 const first = thirdPartyLicenseEntryKey({ ...ENTRIES[0]!, name: "a:1", version: null });
46 const second = thirdPartyLicenseEntryKey({ ...ENTRIES[0]!, name: "a", version: "1:custom" });
47
48 expect(first).not.toBe(second);
49 });
50
51 it("matches the translated bundle labels shown in each row", () => {
52 const german: Record<string, string> = { Assets: "Ressourcen", Mobile: "Mobil" };
53 const resolve = ((message: string) => {
54 const english = mFallback(message);
55 return german[english] ?? english;
56 }) as M;
57
58 expect(formatLicenseBundles(ENTRIES[1]!.bundles, resolve)).toBe("Ressourcen, Mobil");
59 expect(filterThirdPartyLicenseEntries(ENTRIES, "ressourcen", resolve)).toEqual([ENTRIES[1]]);
60 });
61});