import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import test from 'node:test' function read(relativePath: string) { return readFileSync(fileURLToPath(new URL(relativePath, import.meta.url)), 'utf8').replace( /\r\n/g, '\n', ) } const page = read('../src/pages/worker/WorkerConsignmentPage.tsx') const css = read('../src/styles/worker.css') test('模板驱动商品字段:选项超过 8 个必须改用带搜索的下拉,不能用按钮组', () => { assert.ok( page.includes('options.length > 8'), '必须按选项数量降级:地铁逃生 314 个商品全塞进 Radio.Group 会把页面横向撑爆', ) assert.ok(page.includes('optionFilterProp="label"'), '几百个商品名必须支持按名称搜索') assert.ok( page.includes('popupMatchSelectWidth={false}'), '下拉宽度要跟随内容,避免长商品名被固定窄列截断', ) assert.ok( page.includes("whiteSpace: 'normal'"), '选项文本要允许换行,长商品名不能被 nowrap 撑出弹层', ) }) test('少量选项仍保留按钮组,内置五字段体验不变', () => { assert.ok( page.includes(' 8') < page.indexOf(' { assert.ok(page.includes("' is-single'"), '单字段必须走 is-single') assert.ok(page.includes("' is-duo'"), '两字段必须走 is-duo') assert.ok( css.includes('.worker-consignment-spec-grid.is-single') && css.includes('grid-template-columns: minmax(0, 1fr);'), '单字段必须铺满整行,否则下拉只剩 168px', ) assert.ok( css.includes('.worker-consignment-spec-grid.is-duo') && css.includes('grid-template-columns: repeat(2, minmax(0, 1fr));'), '两字段必须两列等宽', ) }) test('按钮组兜底换行,避免异常配置再次把页面撑爆', () => { const chipsBlock = css.slice( css.indexOf('.worker-consignment-chips {'), css.indexOf('.worker-consignment-chips {') + 160, ) assert.ok(chipsBlock.includes('flex-wrap: wrap'), '按钮组必须允许换行兜底') })