Files
YGChatCS/scripts/test-ParsedValueView-strict.mjs
2026-06-08 12:50:56 +08:00

201 lines
5.1 KiB
JavaScript

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 styleSource = await readFile(
resolve("src/pages/ChatMain/ChatLongAnswer/styles/ParsedValueView.scss"),
"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}`
);
}
const requiredStrictRenderingSnippets = [
"LONG_TEXT_KEYS.sceneImage",
"LONG_TEXT_KEYS.contentImage",
"LONG_TEXT_KEYS.commodityList",
"LONG_TEXT_KEYS.photoList",
"LONG_TEXT_KEYS.aigcComponet",
"shouldRenderSpotLocate",
"shouldRenderQuestionSuggest",
"shouldRenderCommodityList",
"shouldRenderPhotoList",
"shouldRenderAigcComponet",
"getRenderEntriesForObject",
"commodity.commodity_id",
"commodity.commodity_name",
"commodity.commodity_price",
"commodity.commodity_tag",
"commodity.commodity_photo",
"<swiper",
"<swiper-item",
"photo.photo_name",
"photo.photo_description",
"photo.photo_url",
"aigc.background",
"aigc.title",
"aigc.description",
"aigc.jumpUrl",
"jumpAigcClick",
"getAccessToken",
"navigateTo",
"content-body-list-card",
];
for (const snippet of requiredStrictRenderingSnippets) {
assert.equal(
source.includes(snippet),
true,
`ParsedValueView should render exact strict field: ${snippet}`
);
}
const requiredSingleCommodityOverviewSnippets = [
':scroll-x="!isSingleCommodity"',
"'overview-combo-card': isSingleCommodity",
'v-if="isSingleCommodity"',
'class="overview-combo-body"',
'class="overview-combo-cover"',
'class="overview-combo-info"',
'class="overview-combo-name"',
'class="overview-combo-desc"',
'class="overview-combo-price"',
'class="overview-combo-currency"',
'class="overview-combo-button"',
];
for (const snippet of requiredSingleCommodityOverviewSnippets) {
assert.equal(
source.includes(snippet),
true,
`ParsedValueView single commodity should use overview combo layout: ${snippet}`
);
}
const requiredSingleCommodityOverviewStyleSnippets = [
".overview-combo-card",
".overview-combo-body",
"display: flex;",
".overview-combo-cover",
"width: 78px;",
"height: 78px;",
".overview-combo-info",
".overview-combo-name",
".overview-combo-desc",
".overview-combo-price",
".overview-combo-currency",
".overview-combo-button",
"height: 40px;",
];
for (const snippet of requiredSingleCommodityOverviewStyleSnippets) {
assert.equal(
styleSource.includes(snippet),
true,
`ParsedValueView single commodity should define overview combo style: ${snippet}`
);
}
const removedInnerSpecialEntrySnippets = [
"createSpecialFieldEntry",
"entry.type === 'question-suggest'",
"entry.type === 'photo-list'",
"entry.type === 'aigc-componet'",
"entry.type === 'commodity-list'",
"entry.type === 'spot-locate'",
];
for (const snippet of removedInnerSpecialEntrySnippets) {
assert.equal(
source.includes(snippet),
false,
`ParsedValueView should keep special fields at the top level only: ${snippet}`
);
}
const removedFlatFieldSnippets = [
"preparationSectionTitle",
"preparationSectionItems",
"sectionSuggestionTitle",
"sectionSuggestionContent",
"pitfallSectionTitle",
"pitfallSectionItems",
"viewSectionTitle",
"viewSectionItems",
"suggestionSectionTitle",
"suggestionSectionContent",
"lightReminderTitle",
"lightReminderItems",
];
for (const snippet of removedFlatFieldSnippets) {
assert.equal(
source.includes(`LONG_TEXT_KEYS.${snippet}`),
false,
`ParsedValueView should not reference removed flat field: ${snippet}`
);
}
const removedStructuredConfigSnippets = [
"STRUCTURED_SECTION_CONFIG",
"isGenericObjectSectionField",
"content-body-section-dot",
"content-body-section-list",
"LONG_TEXT_KEYS.preparationSection",
"LONG_TEXT_KEYS.sectionSuggestion",
"LONG_TEXT_KEYS.pitfallSection",
"LONG_TEXT_KEYS.viewSection",
"LONG_TEXT_KEYS.suggestionSection",
"LONG_TEXT_KEYS.lightReminder",
"LONG_TEXT_KEYS.photoSpotSection",
"LONG_TEXT_KEYS.phoneSection",
"LONG_TEXT_KEYS.decisionSection",
"LONG_TEXT_KEYS.routeWarning",
"LONG_TEXT_KEYS.tourRoutes",
"LONG_TEXT_KEYS.facilitiesAlongTheWay",
];
for (const snippet of removedStructuredConfigSnippets) {
assert.equal(
source.includes(snippet),
false,
`ParsedValueView should use generic section rendering instead of configured field: ${snippet}`
);
}
console.log("ParsedValueView strict field checks passed");