import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";

const __dirname = dirname(fileURLToPath(import.meta.url));
const source = readFileSync(join(__dirname, "QualityInspectionView.vue"), "utf8");

describe("QualityInspectionView layout and release flow", () => {
  it("places the pending/completed switch beside the page title", () => {
    assert.match(source, /class="quality-title-row"/);
    assert.match(source, /class="inventory-tabbar quality-title-tabbar"/);
  });

  it("does not keep inspection remark as a persistent pending-panel field", () => {
    assert.doesNotMatch(source, /class="form-field quality-note"/);
  });

  it("opens a remark confirmation dialog before releasing or rejecting a batch", () => {
    assert.match(source, /openInspectionRemarkDialog\(row,\s*'PASS'\)/);
    assert.match(source, /openInspectionRemarkDialog\(row,\s*'REJECT'\)/);
    assert.match(source, /showInspectionRemarkDialog/);
    assert.match(source, /确认放行/);
  });

  it("renders the inspection dialog as a formal quality document", () => {
    assert.match(source, /<DocumentPaper[\s\S]*title="质量校验单"/);
    assert.match(source, /<DocumentGrid :fields="inspectionDocumentHeaderFields"/);
    assert.match(source, /<DocumentLineTable title="质检明细"/);
  });

  it("exposes quality inspection archive actions in the completed list", () => {
    assert.match(source, /<th class="quality-archive-col">归档<\/th>/);
    assert.match(source, /<DocumentArchiveActions/);
    assert.match(source, /previewDocumentArchive\('quality-inspection', row\.receipt_item_id\)/);
    assert.match(source, /downloadDocumentArchive\('quality-inspection', row\.receipt_item_id/);
    assert.match(source, /regenerateDocumentArchive\('quality-inspection', row\.receipt_item_id\)/);
  });
});
