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

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

assert.match(
  source,
  /promised_date_touched:\s*false/,
  "new sales order lines should track whether line promised date was manually edited"
);
assert.match(
  source,
  /@input="markSalesOrderItemPromisedDateTouched\(item\)"/,
  "line promised date input should mark the row as user-edited"
);
assert.match(
  source,
  /syncSalesOrderItemPromisedDatesFromHeader/,
  "header promised date changes should synchronize eligible line dates"
);
assert.match(
  source,
  /!item\.promised_date_touched/,
  "sync should only update untouched line promised dates"
);
assert.match(
  source,
  /promised_date:\s*item\.promised_date\s*\|\|\s*salesOrderForm\.promised_date\s*\|\|\s*null/,
  "submit should fall back empty line dates to the sales order promised date"
);

console.log("sales order line promised date default checks passed");
