import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const devicesPagePath = path.join(adminRoot, 'src/pages/nfc/devices/index.tsx'); const devicesLocalePath = path.join(adminRoot, 'src/pages/nfc/devices/locale/index.ts'); test('1. nfc/devices 页面必须请求 admin/nfc/device/page 并使用 Arco Table', () => { assert.ok(fs.existsSync(devicesPagePath), 'NFC 设备池页面必须存在'); const content = fs.readFileSync(devicesPagePath, 'utf-8'); assert.ok( content.includes('admin/nfc/device/page'), '必须请求 POST /api/admin/nfc/device/page' ); assert.ok(content.includes('Table'), '必须使用 Arco Table'); assert.ok( content.includes("from '@arco-design/web-react'"), '必须从 @arco-design/web-react 引入组件' ); assert.ok(content.includes('NFCRecord'), '必须使用 NFCRecord 类型'); assert.ok( content.includes('code === 1000') || content.includes('code ===1000'), '必须按 Cool-Admin code === 1000 判断成功' ); assert.ok(content.includes('Message.error'), '失败必须使用 Arco Message.error'); assert.ok(!content.includes('Mock.js') && !content.includes("from 'mockjs'"), '禁止用 Mock.js 假数据冒充成功'); assert.ok(!/\bany\b/.test(content), '禁止使用 any'); }); test('2. nfc/devices 必须复用 NFC 契约、筛选列与挂失/重置', () => { const content = fs.readFileSync(devicesPagePath, 'utf-8'); assert.ok(content.includes('NFCStatus'), '必须使用 NFCStatus 类型'); assert.ok(content.includes('NFCMaterial'), '必须使用 NFCMaterial 类型'); assert.ok(content.includes('NFCSceneMode'), '必须使用 NFCSceneMode 类型'); assert.ok(content.includes("from '@/types/omni'"), '必须复用 admin/src/types/omni.ts'); assert.ok(content.includes('Form'), '必须使用 Arco Form'); assert.ok(content.includes('Select'), '必须使用 Arco Select'); assert.ok(content.includes('Tag'), '必须使用 Arco Tag'); assert.ok(content.includes('Badge'), '必须使用 Arco Badge'); assert.ok(content.includes('Popconfirm'), '挂失/重置必须使用 Arco Popconfirm'); assert.ok(content.includes('lightColors'), '颜色必须引用 lightColors token'); assert.ok(!/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b/.test(content), '禁止硬编码颜色'); assert.ok(content.includes('uid'), '必须展示 uid'); assert.ok(content.includes('batchNo'), '必须展示 batchNo'); assert.ok(content.includes('material'), '必须展示 material'); assert.ok(content.includes('cardId'), '必须展示 cardId'); assert.ok(content.includes('status'), '必须展示 status'); assert.ok(content.includes('sceneMode'), '必须展示 sceneMode'); assert.ok(content.includes('lastScannedAt'), '必须展示 lastScannedAt'); assert.ok(content.includes('keyWord'), '筛选必须支持 keyWord'); for (const status of ['active', 'suspended', 'unbound']) { assert.ok(content.includes(`'${status}'`), `必须支持状态: ${status}`); } for (const material of ['wood', 'metal', 'pvc']) { assert.ok(content.includes(`'${material}'`), `必须支持材质: ${material}`); } assert.ok( content.includes('admin/nfc/security/freeze'), '必须请求 POST /api/admin/nfc/security/freeze' ); assert.ok( content.includes('admin/nfc/security/reset'), '必须请求 POST /api/admin/nfc/security/reset' ); assert.ok(content.includes('type="primary"'), '查询必须是主按钮'); assert.ok(content.includes('type="secondary"'), '挂失/重置必须是次按钮'); assert.ok(!content.includes(' { assert.ok(fs.existsSync(devicesLocalePath), 'NFC 设备池语言包必须存在'); const content = fs.readFileSync(devicesLocalePath, 'utf-8'); assert.ok(content.includes("'menu.nfc.devices'"), '页面语言包必须包含 menu.nfc.devices'); assert.ok(content.includes("'en-US'"), '必须包含英文案'); assert.ok(content.includes("'zh-CN'"), '必须包含中文案'); assert.ok(content.includes('nfcDevices.request.fail'), '必须包含失败提示文案'); assert.ok(content.includes('nfcDevices.status.active'), '必须包含状态文案'); assert.ok(content.includes('nfcDevices.material.wood'), '必须包含材质文案'); assert.ok(content.includes('nfcDevices.material.empty'), '必须包含材质空态文案'); assert.ok(content.includes('nfcDevices.action.freeze'), '必须包含挂失文案'); assert.ok(content.includes('nfcDevices.action.reset'), '必须包含重置文案'); assert.ok(!/\bany\b/.test(content), 'locale 禁止使用 any'); }); test('4. 材质列未知/空值显示空态,禁止默认 pvc;筛选与表单不预选 PVC', () => { const content = fs.readFileSync(devicesPagePath, 'utf-8'); const localeContent = fs.readFileSync(devicesLocalePath, 'utf-8'); assert.ok( content.includes("t['nfcDevices.material.empty']") || content.includes('t[`nfcDevices.material.empty`]'), '未知/缺失材质必须走 nfcDevices.material.empty' ); assert.ok( !content.includes("isNFCMaterial(value) ? value : 'pvc'"), '材质列禁止把无法识别的值默认成 pvc' ); assert.ok( !content.includes("? value : 'pvc'"), '禁止三元回退未知材质为 pvc' ); assert.ok( !/field=["']material["'][\s\S]{0,400}initialValue=["']pvc["']/.test(content), '筛选 Form.Item material 禁止 initialValue=pvc' ); assert.ok( !/field=["']material["'][\s\S]{0,400}defaultValue=["']pvc["']/.test(content), '筛选 Form.Item material 禁止 defaultValue=pvc' ); assert.ok( !/material:\s*['"]pvc['"]/.test(content), '禁止在 filters/表单状态里预填 material: pvc' ); assert.ok( !/defaultValue=["']pvc["']/.test(content) && !/initialValue=["']pvc["']/.test(content), '页面禁止任何 pvc 预选初始值' ); assert.ok( localeContent.includes("'nfcDevices.material.empty'"), 'locale 必须定义材质空态 key' ); for (const lang of ['en-US', 'zh-CN', 'ar-SA']) { assert.ok( localeContent.includes(`'${lang}'`), `locale 必须包含语言包: ${lang}` ); } });