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

const pagePath = path.resolve(__dirname, "../../src/views/ccdiProject/index.vue");
const dialogPath = path.resolve(
  __dirname,
  "../../src/views/ccdiProject/components/ArchiveConfirmDialog.vue"
);
const pageSource = fs.readFileSync(pagePath, "utf8");
const dialogSource = fs.readFileSync(dialogPath, "utf8");

assert(
  pageSource.includes("await archiveProject(data.projectId)"),
  "确认归档后应调用真实归档接口"
);

assert(
  pageSource.includes('this.$modal.msgSuccess("项目归档成功")') ||
    pageSource.includes("this.$modal.msgSuccess('项目归档成功')"),
  "归档成功后应提示项目归档成功"
);

assert(
  pageSource.includes("项目归档失败，请稍后重试"),
  "归档失败时应有统一兜底提示"
);

[
  "自动生成项目报告PDF",
  "移入归档库，可随时查看",
  "同时删除项目相关数据",
  "归档后可从\"归档库\"中查看和恢复",
].forEach((token) => {
  assert(!dialogSource.includes(token), `归档弹窗不应保留超范围文案: ${token}`);
});

assert(
  !dialogSource.includes("deleteData"),
  "归档弹窗不应再保留删除数据状态"
);

console.log("project-list-archive-flow test passed");
