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

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

assert(
  source.includes('index="upload"') &&
    source.includes(`:disabled="isArchiveLockedTab('upload')"`) &&
    source.includes('index="config"') &&
    source.includes(`:disabled="isArchiveLockedTab('config')"`),
  "上传数据和参数配置页签应支持归档态禁用"
);

assert(
  /isProjectArchived\(\)\s*\{\s*return String\(this\.projectInfo\.projectStatus\) === "2";\s*\}/.test(
    source
  ),
  "详情页应声明归档态判断"
);

assert(
  /initActiveTabFromRoute\(\)\s*\{[\s\S]*?this\.resolveAccessibleTab\(targetTab\)/.test(
    source
  ),
  "详情页应在路由初始化时校正归档态不可访问页签"
);

assert(
  /initActiveTabFromRoute\(\)\s*\{[\s\S]*?if\s*\(accessibleTab !== targetTab\)[\s\S]*?this\.syncRouteTab\(accessibleTab\)/.test(
    source
  ),
  "归档态命中禁用页签时应同步将地址栏回写到可访问页签"
);

assert(
  /handleMenuSelect\(index\)\s*\{[\s\S]*?if\s*\(this\.isArchiveLockedTab\(index\)\)\s*\{\s*return;\s*\}/.test(
    source
  ),
  "点击禁用页签时不应切换"
);

console.log("project-detail-archive-tab-lock test passed");
