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

const approvalTemplate = readFileSync(
  fileURLToPath(new URL('../src/views/ApprovalCenterView.vue', import.meta.url)),
  'utf8'
)
const approvalScript = readFileSync(
  fileURLToPath(new URL('../src/views/scripts/ApprovalCenterView.js', import.meta.url)),
  'utf8'
)
const detailTemplate = readFileSync(
  fileURLToPath(new URL('../src/views/TravelRequestDetailView.vue', import.meta.url)),
  'utf8'
)
const detailScript = readFileSync(
  fileURLToPath(new URL('../src/views/scripts/TravelRequestDetailView.js', import.meta.url)),
  'utf8'
)

test('approval center reuses reimbursement detail view instead of its old detail shell', () => {
  assert.match(approvalTemplate, /<TravelRequestDetailView/)
  assert.match(approvalTemplate, /back-label="返回审批列表"/)
  assert.match(approvalTemplate, /approval-mode/)
  assert.doesNotMatch(approvalTemplate, /class="approval-detail"/)
  assert.doesNotMatch(approvalTemplate, /<ReturnReasonDialog/)
  assert.doesNotMatch(approvalTemplate, /<ConfirmDialog/)

  assert.match(approvalScript, /import TravelRequestDetailView from '\.\.\/TravelRequestDetailView\.vue'/)
  assert.match(approvalScript, /fetchApprovalWorkbenchItems/)
  assert.doesNotMatch(approvalScript, /fetchExpenseClaims/)
  assert.doesNotMatch(approvalScript, /import ConfirmDialog/)
  assert.doesNotMatch(approvalScript, /import ReturnReasonDialog/)

  assert.match(detailScript, /backLabel:/)
  assert.match(detailTemplate, /\{\{ backLabel \}\}/)
})
