import test from 'node:test' import assert from 'node:assert/strict' import { readSource } from './helpers.ts' /** 对齐旧版 .btn-sm:asin 域 5 页已像素复刻,行内操作(编辑/删除/配置)用原生 btn btn-sm 实心小按钮(非 EP 按钮)。 */ // 断言单个 el-button 标签同时含 btn-sm 与目标 @click,且不含 link/text 修饰(action 含正则元字符需转义)。 const escapeRe = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') const OLD_BTN = (action: string) => new RegExp(`class="btn btn-sm[^"]*"[^>]*@click="${escapeRe(action)}`) const NO_LINK = (action: string) => new RegExp(`]*link[^>]*@click="${escapeRe(action)}`) const NO_TEXT = (action: string) => new RegExp(`]*text[^>]*@click="${escapeRe(action)}`) const NO_EL = (action: string) => new RegExp(`]*@click="${escapeRe(action)}`) function assertOldRowButton(source: string, action: string, page: string) { assert.match(source, OLD_BTN(action), `${page} ${action} 为 btn-sm 实心按钮`) assert.doesNotMatch(source, NO_LINK(action), `${page} ${action} 不再 link`) assert.doesNotMatch(source, NO_TEXT(action), `${page} ${action} 不再 text`) assert.doesNotMatch(source, NO_EL(action), `${page} ${action} 不再用 EP 按钮`) } test('align_invalid_asin_row_buttons_old_btn', () => { const s = readSource('src/pages/asin/AsinInvalidPage.vue') assertOldRowButton(s, 'openEdit(row)', '不符合ASIN') assertOldRowButton(s, 'remove(row)', '不符合ASIN') assert.match(s, /window\.confirm\(invalidAsinDeleteText\(row\)\)/, '删除确认原生 confirm 对齐旧版') }) test('align_query_asin_config_old_btn', () => { assertOldRowButton(readSource('src/pages/asin/QueryAsinPage.vue'), 'openConfig(row.item as QueryAsinItem)', '查询ASIN') }) test('align_skip_price_config_old_btn', () => { assertOldRowButton(readSource('src/pages/asin/SkipPricePage.vue'), 'openConfig(row.item as SkipPriceItem)', '最低价ASIN') }) test('align_product_category_row_buttons_old_btn', () => { const s = readSource('src/pages/asin/ProductCategoryPage.vue') assertOldRowButton(s, 'openEdit(row.node)', '商品类目树视图') assertOldRowButton(s, 'openEdit(row)', '商品类目搜索视图') assert.match(s, /btn-sm btn-danger"[^>]*@click="removeCategory/, '删除为 btn-sm btn-danger') }) test('align_product_category_no_indigo_left', () => { const s = readSource('src/pages/asin/ProductCategoryPage.vue') assert.doesNotMatch(s, /#6366f1|#eef0fe|6366f1|eef0fe/, '靛蓝色点已清') assert.match(s, /--admin-primary-soft/, '折叠钮改用蓝白主色 soft token') }) test('align_product_category_load_more_old_class', () => { // 类目「加载更多」行按钮沿用 btn-sm btn-secondary(旧版小组按钮样式)。 const s = readSource('src/pages/asin/ProductCategoryPage.vue') assert.match(s, /class="btn btn-sm btn-secondary"[^>]*loadMoreChildren/, '加载更多为旧版 btn-sm btn-secondary') }) test('align_dedupe_registry_row_buttons_old_btn', () => { const s = readSource('src/pages/asin/DedupeRegistryPage.vue') assert.match(s, /class="btn btn-sm"[^>]*@click="openEdit\(row\)"/, '编辑用旧版 btn-sm 实心小按钮') assert.match(s, /class="btn btn-sm btn-danger"[^>]*@click="removeRow\(row\)"/, '删除用旧版 btn-sm btn-danger') assert.doesNotMatch(s, /el-button/, '去重汇总已自绘,无 EP 按钮') assert.match(s, /window\.confirm\(`确定删除总数据/, '删除确认文案对齐旧版(原生 confirm)') }) test('align_asin_actions_cell_spacing', () => { // 反馈:查询ASIN操作按钮要有间距——asin-col-actions 统一 flex + gap 8px(对齐全站 ops-cell)。 for (const page of ['src/pages/asin/QueryAsinPage.vue', 'src/pages/asin/SkipPricePage.vue']) { const s = readSource(page) assert.match(s, /\.asin-col-actions\s*\{[^}]*gap:\s*8px/, `${page} 操作列按钮间距 8px`) } })