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

const componentPath = path.resolve(
  __dirname,
  "../../src/views/ccdiCreditInfo/index.vue"
);
const detailComponentPath = path.resolve(
  __dirname,
  "../../src/views/ccdiCreditInfo/components/CreditInfoDetail.vue"
);
const source = fs.readFileSync(componentPath, "utf8");
assert(fs.existsSync(detailComponentPath), "征信详情展示组件未抽取");
const detailSource = fs.readFileSync(detailComponentPath, "utf8");

[
  "CreditInfoDetail",
  "<credit-info-detail",
  "detailDialogVisible",
  "detailForm",
  "normalizeCreditDetail",
  "getCreditInfoDetail(row.idCard)",
  "handleDetail",
  "handleDelete",
  "deleteCreditInfo",
  "确认删除该征信对象当前已维护的征信信息吗？",
].forEach((token) => {
  assert(source.includes(token), `详情或删除交互缺少关键结构: ${token}`);
});

[
  'name: "CreditInfoDetail"',
  "征信摘要",
  "负债信息",
  "负面信息",
  "detail.debtCount",
  "detail.debtTotalAmount",
  "detail.negativeInfo.civilCnt",
  "detail.negativeInfo.enforceCnt",
  "detail.negativeInfo.admCnt",
  "detail.debts || []",
].forEach((token) => {
  assert(detailSource.includes(token), `征信详情组件缺少关键结构: ${token}`);
});

console.log("credit-info-detail-ui test passed");
