import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'

const policiesViewPath = fileURLToPath(new URL('../src/views/PoliciesView.vue', import.meta.url))
const policiesView = readFileSync(policiesViewPath, 'utf8')

function testIngestTimeUsesDedicatedColumn() {
  assert.match(
    policiesView,
    /<th>状态<\/th>\s*<th>归纳时间<\/th>\s*<th>上传人<\/th>/,
    '知识库文件表需要在状态和上传人之间单独展示归纳时间列'
  )
  assert.match(
    policiesView,
    /<td data-label="状态">\s*<div class="state-cell">\s*<span class="state-tag"[^>]*>\{\{ doc\.state \}\}<\/span>\s*<\/div>\s*<\/td>\s*<td class="ingest-time-cell" data-label="归纳时间">\{\{ doc\.ingestTime \|\| '—' \}\}<\/td>/,
    '状态列只展示状态标签，归纳时间需要放到独立单元格'
  )
  assert.doesNotMatch(
    policiesView,
    /class="state-time"|归纳时间：\{\{ doc\.ingestTime \}\}/,
    '状态单元格下面不应再显示归纳时间'
  )
  assert.doesNotMatch(policiesView, /colspan="7"/)
  assert.match(policiesView, /colspan="8"/)
}

function run() {
  testIngestTimeUsesDedicatedColumn()
  console.log('policies view table tests passed')
}

run()
