feat: 实现骨架屏的渲染
This commit is contained in:
129
scripts/regression-long-answer-section-skeleton.mjs
Normal file
129
scripts/regression-long-answer-section-skeleton.mjs
Normal file
@@ -0,0 +1,129 @@
|
||||
import assert from "assert";
|
||||
import { readFileSync } from "fs";
|
||||
import { dirname, resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||
const detailPagePath = resolve(
|
||||
scriptDir,
|
||||
"../src/pages/ChatMain/ChatLongAnswer/index.vue"
|
||||
);
|
||||
const parsedValuePath = resolve(
|
||||
scriptDir,
|
||||
"../src/pages/ChatMain/ChatLongAnswer/ParsedValueView.vue"
|
||||
);
|
||||
const detailStylePath = resolve(
|
||||
scriptDir,
|
||||
"../src/pages/ChatMain/ChatLongAnswer/styles/index.scss"
|
||||
);
|
||||
const skeletonComponentPath = resolve(
|
||||
scriptDir,
|
||||
"../src/pages/ChatMain/ChatLongAnswer/LongAnswerSectionSkeleton.vue"
|
||||
);
|
||||
|
||||
const detailPageSource = readFileSync(detailPagePath, "utf8");
|
||||
const parsedValueSource = readFileSync(parsedValuePath, "utf8");
|
||||
const detailStyleSource = readFileSync(detailStylePath, "utf8");
|
||||
const skeletonComponentSource = readFileSync(skeletonComponentPath, "utf8");
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/const\s+streamFinished\s*=\s*ref/,
|
||||
"long answer page should track whether the forwarded stream has finished"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/import\s+LongAnswerSectionSkeleton\s+from\s+"\.\/LongAnswerSectionSkeleton\.vue"/,
|
||||
"long answer page should use a sibling skeleton component"
|
||||
);
|
||||
|
||||
assert.doesNotMatch(
|
||||
detailPageSource,
|
||||
/DEFERRED_SPECIAL_SECTION_KEYS/,
|
||||
"long answer page should not use a special-key whitelist for section skeletons"
|
||||
);
|
||||
|
||||
assert.doesNotMatch(
|
||||
detailPageSource,
|
||||
/LONG_TEXT_KEYS\.(sceneImage|contentImage|spotLocate|questionSuggest|commodityList|photoList|aigcComponet)/,
|
||||
"section skeleton readiness should not be tied to named special keys"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/<LongAnswerSectionSkeleton\s+v-if="shouldRenderSectionSkeleton\(section\)"/,
|
||||
"each section should decide whether to show its own skeleton inside the contentSections loop"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/v-else-if="shouldUseParsedValueView\(section\)"/,
|
||||
"ParsedValueView should render after the per-section skeleton check"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/getSectionIndex\(section\)/,
|
||||
"section readiness should use the section position to know when the next key has started"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/hasSectionAfter\(section\)/,
|
||||
"a deferred section should become renderable when a later key arrives"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/isSectionReady\(section\)/,
|
||||
"long answer page should centralize when a structured section is ready to render"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/isNonStringSectionValue/,
|
||||
"structured skeletons should be driven by non-string parsed values"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/isPendingStructuredText/,
|
||||
"pending JSON-like section strings should use the skeleton until parsed"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
detailPageSource,
|
||||
/section\.parsedValue\s*!==\s*null\s*&&\s*isNonStringSectionValue\(section\.parsedValue\)/,
|
||||
"parsed non-string values should identify structured sections"
|
||||
);
|
||||
|
||||
assert.doesNotMatch(
|
||||
detailPageSource,
|
||||
/shouldRenderStreamingReceiver|class="long-answer-receiver"/,
|
||||
"long answer page should not use one global receiver box"
|
||||
);
|
||||
|
||||
assert.doesNotMatch(
|
||||
detailPageSource,
|
||||
/:defer-special-render=/,
|
||||
"ParsedValueView should not hide deferred sections internally"
|
||||
);
|
||||
|
||||
assert.doesNotMatch(
|
||||
parsedValueSource,
|
||||
/deferSpecialRender|shouldDeferSpecialRender/,
|
||||
"ParsedValueView should stay focused on rendering values, not streaming readiness"
|
||||
);
|
||||
|
||||
assert.match(
|
||||
skeletonComponentSource,
|
||||
/\.long-answer-section-skeleton\s*{/,
|
||||
"section skeleton styles should live in the sibling skeleton component"
|
||||
);
|
||||
|
||||
assert.doesNotMatch(
|
||||
detailStyleSource,
|
||||
/\.long-answer-section-skeleton\b|\.long-answer-receiver\b/,
|
||||
"long answer page styles should not contain skeleton implementation details"
|
||||
);
|
||||
Reference in New Issue
Block a user