import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

const source = fs.readFileSync(path.resolve("src/views/DeliveryManagementView.vue"), "utf8");

assert.match(
  source,
  /const deliveryLedgerRows = computed\(\(\) =>/,
  "delivery ledger should build sales-order-level aggregate rows"
);

assert.match(
  source,
  /v-for="group in paginatedDeliveryGroups"/,
  "main delivery ledger table should render aggregated sales-order groups"
);

assert.doesNotMatch(
  source,
  /v-for="delivery in paginatedDeliveries"/,
  "main delivery ledger table should not render one row per delivery order"
);

assert.match(
  source,
  /function buildDeliveryLedgerRows\(/,
  "delivery ledger should have a dedicated aggregation helper"
);

assert.match(
  source,
  /发货单流水/,
  "sales-order detail drawer should show delivery order flow"
);

assert.match(
  source,
  /发货明细流水/,
  "sales-order detail drawer should show delivery item flow"
);

assert.match(
  source,
  /const activeDeliveryGroup = computed\(\(\) =>/,
  "detail drawer should be driven by the selected sales-order group"
);

console.log("delivery ledger order aggregation checks passed");
