@smart-cloud/ai-kit-ui 1.5.11 → 1.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ import assert from "node:assert/strict";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import test from "node:test";
5
+ import { fileURLToPath } from "node:url";
6
+ import ts from "typescript";
7
+
8
+ const CHATBOT_DISCLOSURE =
9
+ "Answers from {name} are generated by AI and may contain mistakes. Check important information.";
10
+ const DOC_SEARCH_DISCLOSURE =
11
+ "This summary was generated by AI and may contain mistakes. Check important information.";
12
+
13
+ const importTypeScript = async (fileUrl: URL) => {
14
+ const source = await fs.readFile(fileUrl, "utf8");
15
+ const compiled = ts.transpileModule(source, {
16
+ compilerOptions: {
17
+ module: ts.ModuleKind.ESNext,
18
+ target: ts.ScriptTarget.ES2022,
19
+ },
20
+ }).outputText;
21
+ return import(
22
+ `data:text/javascript;base64,${Buffer.from(compiled).toString("base64")}`
23
+ );
24
+ };
25
+
26
+ test("formats every chatbot name placeholder", async () => {
27
+ const disclosures = await importTypeScript(
28
+ new URL("../../core/src/ai-disclosures.ts", import.meta.url),
29
+ );
30
+
31
+ assert.equal(disclosures.DEFAULT_CHATBOT_AI_DISCLOSURE, CHATBOT_DISCLOSURE);
32
+ assert.equal(
33
+ disclosures.formatAiDisclosure("{name}: ask {name}", "Support Bot"),
34
+ "Support Bot: ask Support Bot",
35
+ );
36
+ });
37
+
38
+ test("all supported languages contain alphabetized AI disclosures", async () => {
39
+ const directory = fileURLToPath(new URL("../src/i18n", import.meta.url));
40
+ const files = (await fs.readdir(directory))
41
+ .filter((file) => file.endsWith(".ts") && file !== "index.ts")
42
+ .sort();
43
+
44
+ assert.equal(files.length, 22);
45
+
46
+ for (const file of files) {
47
+ const module = await importTypeScript(
48
+ new URL(`../src/i18n/${file}`, import.meta.url),
49
+ );
50
+ const dictionary = Object.values(module).find(
51
+ (value) => typeof value === "object" && value !== null,
52
+ ) as Record<string, string> | undefined;
53
+
54
+ assert.ok(dictionary, `${file} must export a dictionary`);
55
+ assert.ok(
56
+ dictionary[CHATBOT_DISCLOSURE]?.includes("{name}"),
57
+ `${file} must preserve the chatbot name placeholder`,
58
+ );
59
+ assert.ok(
60
+ dictionary[DOC_SEARCH_DISCLOSURE]?.trim(),
61
+ `${file} must translate the DocSearch disclosure`,
62
+ );
63
+
64
+ const keys = Object.keys(dictionary);
65
+ assert.equal(
66
+ keys.indexOf(CHATBOT_DISCLOSURE),
67
+ keys.indexOf("An unknown error occurred.") + 1,
68
+ `${file} must keep the chatbot disclosure alphabetized`,
69
+ );
70
+ assert.equal(
71
+ keys.indexOf(DOC_SEARCH_DISCLOSURE),
72
+ keys.indexOf("Title") - 1,
73
+ `${file} must keep the DocSearch disclosure alphabetized`,
74
+ );
75
+ }
76
+ });
77
+
78
+ test("renders the chatbot disclosure beside status and outside the composer box", async () => {
79
+ const component = await fs.readFile(
80
+ new URL("../src/ai-chatbot/AiChatbot.tsx", import.meta.url),
81
+ "utf8",
82
+ );
83
+ const statusIndex = component.indexOf('className="ai-status-line"');
84
+ const disclosureIndex = component.indexOf(
85
+ 'className="ai-generated-content-disclosure ai-chatbot-generated-content-disclosure"',
86
+ );
87
+ const composerIndex = component.indexOf(
88
+ '<Stack className="ai-box ai-box-open">',
89
+ );
90
+
91
+ assert.ok(statusIndex >= 0, "chatbot status line must be rendered");
92
+ assert.ok(disclosureIndex > statusIndex, "disclosure must follow status");
93
+ assert.ok(
94
+ composerIndex > disclosureIndex,
95
+ "disclosure must be outside and above the composer box",
96
+ );
97
+ });