Files
creator-hub/web/tests/works-gallery-card.test.cjs
T
rogee 6958330a5f
douyin-release-gate / verify (push) Failing after 3m9s
fix(web): hide title for untitled works
2026-09-28 12:56:43 +08:00

51 lines
1.8 KiB
JavaScript

const assert = require('node:assert/strict');
const { readFileSync } = require('node:fs');
const { test } = require('node:test');
const ts = require('typescript');
const source = ts.createSourceFile(
'WorksGallery.tsx',
readFileSync(`${__dirname}/../src/components/creator/WorksGallery.tsx`, 'utf8'),
ts.ScriptTarget.Latest,
true,
ts.ScriptKind.TSX,
);
test('作品卡片封面读本地缓存 /works/:id/cover(签名 URL 会过期)', () => {
assert.match(sourceText(), /cover`/);
assert.match(sourceText(), /fetchCreatorBinary/);
assert.doesNotMatch(sourceText(), /cover_url/);
});
test('观看/点赞/评论/分享四项指标全宽 GRID 贴封面下方', () => {
const grid = /function WorkStatsGrid/.exec(sourceText());
assert.ok(grid, '应有 WorkStatsGrid 组件');
const body = sourceText().slice(grid.index, grid.index + 1300);
for (const key of ['play_count', 'likes', 'comments_count', 'shares']) {
assert.match(body, new RegExp(key), `GRID 应包含指标 ${key}`);
}
// 四列均分占满整行:每列 flex:1,容器自带上下边框贴封面。
assert.match(body, /flex: 1/);
assert.match(body, /borderTop/);
assert.match(body, /borderBottom/);
});
test('无标题作品在卡片和详情中均不显示占位标题', () => {
const text = sourceText();
assert.match(text, /\{work\.title \? \(/);
assert.match(text, /\{detailWork\.title \? \(/);
assert.doesNotMatch(text, /work\.title \|\| '无标题'|detailWork\.title \|\| '无标题'/);
});
test('卡片展示作品描述(body 省略两行)', () => {
const card = /work\.body \? \(/.exec(sourceText());
assert.ok(card, '卡片应有 body 描述分支');
const body = sourceText().slice(card.index - 120, card.index + 200);
assert.match(body, /ellipsis=\{\{ rows: 2 \}\}/);
});
function sourceText() {
return source.getFullText();
}