diff --git a/scripts/test-ParsedValueView-strict.mjs b/scripts/test-ParsedValueView-strict.mjs new file mode 100644 index 0000000..32c6c14 --- /dev/null +++ b/scripts/test-ParsedValueView-strict.mjs @@ -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"); diff --git a/scripts/test-longTextCard.mjs b/scripts/test-longTextCard.mjs new file mode 100644 index 0000000..9972902 --- /dev/null +++ b/scripts/test-longTextCard.mjs @@ -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"); diff --git a/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue b/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue index 7a76361..aa0f706 100644 --- a/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue +++ b/src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue @@ -1,52 +1,53 @@