feat: 改造了组件的渲染逻辑

This commit is contained in:
2026-06-04 10:57:28 +08:00
parent 19b97fc326
commit e5ec442500
5 changed files with 267 additions and 219 deletions

View File

@@ -0,0 +1,43 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
const source = await readFile(
resolve("src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue"),
"utf8"
);
const forbiddenCompatibilitySnippets = [
"valueObj.image_url",
"valueObj.image,",
"valueObj.image_id",
"valueObj.content_image",
"valueObj.sopt_name",
"valueObj.name",
"valueObj.title",
"valueObj.sopt_description",
"valueObj.description",
"valueObj.desc",
"valueObj.sopt_longitude",
"valueObj.longitude",
"valueObj.lng",
"valueObj.sopt_latitude",
"valueObj.latitude",
"valueObj.lat",
"valueObj.sopt_tag",
"valueObj.tag",
"valueObj.type",
"value?.questions",
"value?.items",
"value?.list",
];
for (const snippet of forbiddenCompatibilitySnippets) {
assert.equal(
source.includes(snippet),
false,
`ParsedValueView should not guess compatibility field: ${snippet}`
);
}
console.log("ParsedValueView strict field checks passed");

View File

@@ -0,0 +1,54 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
const source = await readFile(resolve("src/utils/longTextCard.js"), "utf8");
const moduleUrl = `data:text/javascript;base64,${Buffer.from(source).toString("base64")}`;
const longTextCard = await import(moduleUrl);
const {
parseLongTextDisplayValue,
sanitizeLongTextDisplayValue,
hasLongTextDisplayValue,
formatLongTextDisplayValue,
} = longTextCard;
assert.deepEqual(
parseLongTextDisplayValue('[ "see bridge", "hear water" ]'),
["see bridge", "hear water"],
"serialized arrays should be parsed for display"
);
assert.deepEqual(
parseLongTextDisplayValue('{"spot_name":"bridge","spot_longitude:":107.712345}'),
{ spot_name: "bridge", "spot_longitude:": 107.712345 },
"serialized objects should be parsed for display"
);
assert.deepEqual(
sanitizeLongTextDisplayValue(
{
content: "hidden",
components: ["hidden"],
view_section_items: '[ "check piers", "count arches" ]',
nested: {
title: "keep",
},
},
["content", "components"]
),
{
view_section_items: ["check piers", "count arches"],
nested: {
title: "keep",
},
},
"sanitizing should parse JSON-like strings and ignore configured keys"
);
assert.equal(hasLongTextDisplayValue('["follow up"]'), true);
assert.equal(hasLongTextDisplayValue({ a: "", b: [" ", null] }), false);
assert.equal(formatLongTextDisplayValue(true), "\u662f");
assert.equal(formatLongTextDisplayValue({ title: "bridge" }), '{"title":"bridge"}');
console.log("longTextCard display helpers passed");