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

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

assert.match(
  source,
  /function\s+orderPendingProductSummary\s*\(/,
  "sales order dropdown should build a pending product summary"
);

assert.match(
  source,
  /orderPendingProductSummary\(order\.order_id\)/,
  "sales order dropdown should show pending product names next to the pending quantity"
);

assert.doesNotMatch(
  source,
  /:disabled="[^"]*totalAllocatedQty\s*<\s*Number\(deliveryForm\.delivery_qty\s*\|\|\s*0\)[^"]*"/,
  "sales out submit button should not be disabled by insufficient stock, otherwise the error message cannot show"
);

assert.match(
  source,
  /本次要发[\s\S]*可发[\s\S]*缺/,
  "sales out validation should explain requested quantity, available quantity, and shortage"
);

console.log("sales out drawer feedback checks passed");
