import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'

const view = await readFile(new URL('../src/views/TestConsole.vue', import.meta.url), 'utf8')
const api = await readFile(new URL('../src/api/tests.ts', import.meta.url), 'utf8')
const list = await readFile(new URL('../src/views/TestList.vue', import.meta.url), 'utf8')
const store = await readFile(new URL('../src/stores/tests.ts', import.meta.url), 'utf8')

assert.match(view, /function connectionStatusLabel\(status\?: string\)/)
assert.match(view, /status === 'ONLINE' \? '在线' : status === 'OFFLINE' \? '离线' : '-'/)
assert.match(view, /receptionState\.value !== '接收中'/)
assert.match(view, /liveState\.value = \{ \.\.\.liveState\.value, testStatus: 'COMPLETED', receptionStatus: 'ENDED',[^\r\n]+exceptions: \[\] \}/)
assert.doesNotMatch(view, /STOPPED: '结束'/)
assert.doesNotMatch(view, /FINISHED: '结束'/)
assert.match(view, /function exceptionTitle\(item: Record<string, unknown>\)/)
assert.match(view, /item\.exceptionId !== undefined && item\.exceptionId !== null/)
assert.match(view, /item\.sourceType === 'COLLECTOR' \? '采集器' : '检测柜'/)
assert.doesNotMatch(view, /`#\$\{item\.sourceId\}`/)
assert.doesNotMatch(view, /item\.sourceType === 'COLLECTOR' \? `采集器\$\{item\.collectorName/)
assert.match(api, /RUNNING_ABNORMAL: '检测中'/)
assert.doesNotMatch(api, /RUNNING_ABNORMAL: '检测中（异常）'/)
assert.doesNotMatch(list, /label: '检测中（异常）'/)
assert.doesNotMatch(store, /export type TestStatus =[^\r\n]*(检测中（异常）|完成确认中|已终止)/)

console.log('控制台在线状态与测试预警异常契约通过')
