Files
wordcloud/frontend/tests/product-archive-ui.test.mjs
broccoli 31e7053bb0
Build, Push and Deploy / build (push) Successful in 9s
Build, Push and Deploy / deploy (push) Successful in 24s
Add product wordcloud board links
2026-09-14 15:32:31 +08:00

93 lines
4.4 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import test from 'node:test';
test('design preview serializes the complete visible document before PNG upload', async () => {
const source = await readFile(new URL('../src/lib/designPreview.ts', import.meta.url), 'utf8');
assert.match(source, /serializeDocument\(document, stickers, \{ includeBackground: true \}\)/);
assert.match(source, /canvas\.toBlob/);
});
test('archive client submits document JSON and a PNG preview as multipart data', async () => {
const source = await readFile(new URL('../src/lib/productArchive.ts', import.meta.url), 'utf8');
assert.match(source, /form\.append\('document_json'/);
assert.match(source, /form\.append\('preview'/);
});
test('canvas offers a product archive action and reports detected source count', async () => {
const canvas = await readFile(new URL('../src/pages/CanvasStudio.tsx', import.meta.url), 'utf8');
const dialog = await readFile(new URL('../src/components/ProductArchiveDialog.tsx', import.meta.url), 'utf8');
assert.match(canvas, /加入产品列表/);
assert.match(dialog, /已检测到.*份画布词云/);
assert.match(dialog, /将作为产品封面/);
});
test('archive dialog states the server scan is authoritative and covers zero-source drafts', async () => {
const dialog = await readFile(new URL('../src/components/ProductArchiveDialog.tsx', import.meta.url), 'utf8');
assert.match(dialog, /(以服务端扫描为准|服务端扫描为最终依据|最终归档数量以服务端为准)/);
assert.match(dialog, /无词云归档数据/);
});
test('archive success hides raw identifiers and reports the archived count', async () => {
const canvas = await readFile(new URL('../src/pages/CanvasStudio.tsx', import.meta.url), 'utf8');
assert.match(canvas, /已归档至产品/);
assert.match(canvas, /份词云位置数据已长期保存/);
assert.doesNotMatch(canvas, /已归档至产品.*\{product\.product_id\}/);
});
test('archive status styles cover archived, empty and pending cleanup states', async () => {
const styles = await readFile(new URL('../src/styles.css', import.meta.url), 'utf8');
assert.match(styles, /\.product-status-archived/);
assert.match(styles, /\.product-status-empty/);
assert.match(styles, /\.product-status-pending-cleanup/);
});
test('new product creation archives with the created product id instead of a draft id', async () => {
const dialog = await readFile(new URL('../src/components/ProductArchiveDialog.tsx', import.meta.url), 'utf8');
assert.match(dialog, /await createManualProduct\(token, \{ name, sku, specification \}\)/);
assert.match(dialog, /archiveProductVersion\(token, product\.product_id, document, previewBlob\)/);
});
test('app routes to product archives and list keeps IDs out of primary cells', async () => {
const app = await readFile(new URL('../src/App.tsx', import.meta.url), 'utf8');
const page = await readFile(new URL('../src/pages/ProductArchivePage.tsx', import.meta.url), 'utf8');
assert.match(app, /'products'/);
assert.match(page, /产品档案/);
assert.match(page, /产品名称/);
assert.doesNotMatch(page, /<td>\{product\.product_id\}<\/td>/);
});
test('product archive page exposes restore and soft delete actions', async () => {
const page = await readFile(new URL('../src/pages/ProductArchivePage.tsx', import.meta.url), 'utf8');
assert.match(page, /恢复产品/);
assert.match(page, /软删除/);
assert.match(page, /系统信息/);
assert.match(page, /待清理 · 将于/);
});
test('product archive links use Product IDs and a configurable board origin', async () => {
const links = await readFile(new URL('../src/lib/wordcloudBoard.ts', import.meta.url), 'utf8');
const page = await readFile(new URL('../src/pages/ProductArchivePage.tsx', import.meta.url), 'utf8');
assert.match(links, /VITE_WORDCLOUD_BOARD_BASE_URL/);
assert.match(links, /http:\/\/114\.55\.99\.6:47880/);
assert.match(links, /encodeURIComponent\(productId\)/);
assert.match(links, /'cloud' \| 'screen' \| 'control'/);
assert.match(page, /product-archive-board-links/);
assert.match(page, /个人查找/);
assert.match(page, /现场大屏/);
assert.match(page, /手机控制/);
assert.match(page, /canOpenWordCloudBoard/);
assert.match(page, /disabled/);
assert.match(page, /target="_blank"/);
assert.match(page, /rel="noopener noreferrer"/);
assert.match(page, /detail\.product_id/);
});