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

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

[
  "涉疑交易明细",
  "预警类型",
  "全部预警类型",
  "员工规则命中",
  "外部人员预警",
  "本方账户",
  "对方账户",
  "关联员工",
  "摘要 / 交易类型",
  "异常标签",
  "<pagination",
  "const DEFAULT_SUSPICIOUS_PAGE_SIZE = 10;",
  "const DEFAULT_RISK_DETAIL_PAGE_SIZE = 5;",
  "suspiciousPageSize: DEFAULT_SUSPICIOUS_PAGE_SIZE",
  "employeeCreditNegativePageSize: DEFAULT_RISK_DETAIL_PAGE_SIZE",
  "abnormalAccountPageSize: DEFAULT_RISK_DETAIL_PAGE_SIZE",
  "this.suspiciousPageSize = DEFAULT_SUSPICIOUS_PAGE_SIZE;",
  "RISK_DETAIL_PAGE_SIZE_OPTIONS = [5, 10, 20, 50]",
  ":page-sizes=\"riskDetailPageSizeOptions\"",
  "layout=\"total, sizes, prev, pager, next, jumper\"",
  "pageSize: this.suspiciousPageSize",
].forEach((token) => assert(source.includes(token), token));

[
  "label=\"可疑规则\"",
  "label=\"可疑人员\"",
  "prop=\"suspiciousPersonName\"",
  "label=\"关联人\"",
  "prop=\"relatedPersonName\"",
  "label=\"关系\"",
  "prop=\"relationType\"",
].forEach((token) => assert(!source.includes(token), token));

assert(
  /\.suspicious-filter-select\s*\{[\s\S]*width:\s*240px;/m.test(source),
  "命中模型筛选框宽度应能容纳较长模型名称"
);
assert(
  /\.suspicious-type-select\s*\{[\s\S]*width:\s*240px;/m.test(source),
  "预警类型筛选框宽度应能容纳外部人员可疑关系"
);
assert(
  /\.suspicious-filter-form :deep\(\.el-button\)\s*\{[\s\S]*min-width:\s*88px;/m.test(source),
  "涉疑交易查询按钮应保持稳定宽度"
);

const riskDetailAmountIndex = source.indexOf('label="交易金额"');
const riskDetailTagIndex = source.indexOf('label="异常标签"');
assert.notStrictEqual(riskDetailAmountIndex, -1, "涉疑交易明细应保留交易金额列");
assert.notStrictEqual(riskDetailTagIndex, -1, "涉疑交易明细应保留异常标签列");
assert(
  riskDetailAmountIndex < riskDetailTagIndex,
  "涉疑交易明细中交易金额列应展示在异常标签列前面"
);
assert(
  source.includes('label="交易金额" width="120"') &&
    source.includes('label="异常标签" min-width="220"'),
  "涉疑交易明细金额列和异常标签列应保持紧凑宽度"
);
