const assert = require("assert");
const fs = require("fs");
const path = require("path");

const componentPath = path.resolve(
  __dirname,
  "../../src/views/ccdiProject/components/detail/DetailQuery.vue"
);
const source = fs.readFileSync(componentPath, "utf8");

assert(
  source.includes("<el-dialog"),
  "详情应改为 el-dialog 弹窗展示"
);

assert(
  !source.includes("<el-drawer"),
  "详情不应再使用抽屉展示"
);

[
  'class="detail-dialog"',
  'class="detail-overview-grid"',
  'class="detail-dialog-footer"',
  "formatCounterpartyName(detailData)",
  "formatOriginalFileName(detailData)",
  'width="980px"',
].forEach((token) => {
  assert(
    source.includes(token),
    `详情弹窗缺少关键结构或方法: ${token}`
  );
});

[
  "命中异常标签",
  "detail-hit-tag-section",
  "detailData.hitTags",
  "当前流水未命中异常标签",
  "mapRiskLevelToTagType(tag.riskLevel)",
].forEach((token) => {
  assert(source.includes(token), `详情弹窗缺少异常标签结构: ${token}`);
});

const tableBlockMatch = source.match(/<el-table[\s\S]*?class="result-table"[\s\S]*?>/m);
assert(tableBlockMatch, "未找到流水明细列表表格");
assert(
  !/\sborder(\s|>)/.test(tableBlockMatch[0]),
  "流水明细列表不应再启用表格边框"
);
assert(
  !/\sstripe(\s|>)/.test(tableBlockMatch[0]),
  "流水明细列表不应再启用斑马纹"
);

console.log("detail-query-detail-dialog test passed");
