/* eslint-env node */ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const currentDir = path.dirname(fileURLToPath(import.meta.url)) const componentDir = path.join(currentDir, '..', 'components') const read = file => fs.readFileSync(path.join(componentDir, file), 'utf8') const pageSource = fs.readFileSync(path.join(currentDir, '..', 'index.vue'), 'utf8') const selectionRulesSource = fs.readFileSync(path.join(currentDir, '..', 'utils', 'selectionRules.ts'), 'utf8') const expectations = [ [ 'ledger tree excludes half-checked parents when collecting checked nodes', /getCheckedNodes\(\s*false\s*,\s*false\s*\)/, read('SteadyLedgerTree.vue') ], [ 'indicator tree excludes half-checked parents when collecting checked nodes', /getCheckedNodes\(\s*false\s*,\s*false\s*\)/, read('SteadyIndicatorTree.vue') ], [ 'selection rules expose the first selectable ledger resolver', /export const findFirstSelectableLedgerNode/, selectionRulesSource ], [ 'selection rules expose the first leaf indicator resolver', /export const findFirstLeafIndicator/, selectionRulesSource ], [ 'steady page applies default selected ledger keys after ledger tree load', /defaultLedgerCheckedKeys\.value\s*=/, pageSource ], [ 'steady page applies default selected indicator keys after indicator tree load', /defaultIndicatorCheckedKeys\.value\s*=/, pageSource ], ['ledger tree receives default checked keys', /defaultCheckedKeys/, read('SteadyLedgerTree.vue')], [ 'ledger tree renders level icons', / !pattern.test(source)) if (failures.length) { console.error('steadyTrend selection contract failed:') for (const [name] of failures) { console.error(`- ${name}`) } process.exit(1) } console.log('steadyTrend selection contract passed')