const assert = require('node:assert/strict'); const { readFileSync } = require('node:fs'); const { test } = require('node:test'); const ts = require('typescript'); // 网关健康状态列:后台定时探活只落最近一次结果,列表直接展示,不保留历史。 const source = ts.createSourceFile( 'gateways-page', readFileSync(`${__dirname}/../src/pages/gateways/index.tsx`, 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX, ); const code = source.getFullText(); test('网关列表展示最近一次健康检查结果', () => { assert.match(code, /健康状态/, '应有健康状态列'); assert.match(code, /dataIndex: 'health_status'/, '应绑定 health_status 字段'); assert.match(code, /gateway\.last_check_reason/, '应展示最近一次检查原因'); assert.match(code, /gateway\.last_checked_at/, '应展示最近一次检查时间'); assert.match(code, /online|在线/, '健康应展示为在线'); assert.match(code, /offline|离线/, '不健康应展示为离线'); }); test('健康状态未检查时不误报异常', () => { // 未检查(unchecked)必须落在独立的静默分支,不允许与离线混用同一个颜色/文案。 const render = code.match(/function HealthCell[\s\S]*?\n}/); assert.ok(render, '应有独立的 HealthCell 组件'); assert.match(render[0], /未检查/, '应存在未检查文案'); const branches = render[0].match(/status === '[a-z]+'/g) ?? []; assert.ok(branches.includes("status === 'healthy'"), '应判断 healthy'); assert.ok(branches.includes("status === 'unhealthy'"), '应判断 unhealthy'); }); test('检查原因与时间收进 Tooltip,不挤占表格密度', () => { const render = code.match(/function HealthCell[\s\S]*?\n}/); assert.ok(render, '应有独立的 HealthCell 组件'); assert.match(render[0], /Tooltip/, '原因与时间应放 Tooltip'); assert.doesNotMatch(render[0], /Typography\.Text type="secondary"/, '不应在单元格内平铺长文本'); });