"""EST 테스트 앱 발췌근거(원본 barbtnColumn — 가격 출처 열 이름·보이기, 숨긴 출처는 단가 고르기에서 제외).""" import json import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parents[2] FILES = [ "native-math.js", "native-formula.js", "native-machine.js", "native-rows.js", "native-text.js", "native-quantity.cjs", "native-wonga.js", "native-sources.js", "native-engine.js", "native-model.js", ] def run_js(code: str): runner = f""" const fs = require('fs'), vm = require('vm'); const ctx = vm.createContext({{ structuredClone, console }}); for (const f of {json.dumps(FILES)}) vm.runInContext(fs.readFileSync('tools/est-test/' + f, 'utf8'), ctx, {{ filename: f }}); process.stdout.write(JSON.stringify(vm.runInContext({json.dumps(code)}, ctx))); """ return json.loads(subprocess.check_output(["node", "-e", runner], cwd=ROOT).decode("utf-8")) def test_hidden_source_leaves_price_choice_and_labels(): out = run_js( r"""(() => { const p = EstNative.empty(); p.options.SourceRefresh = false; p.tables.StuffcDat = [{ Code: 'M1', Name: '철근', Cost1: 100, Cost2: 80, Cost3: 120, ValueIndex: 0 }, { Code: 'M2', Name: '모래', Cost1: 100, Cost2: 80, Cost3: 120, ValueIndex: 2 }]; const tc = (q) => EstNative.calculate(q).tables.StuffcDat.map((r) => r.GC); const before = tc(p); const list = EstSources.get(p.options, 'StuffcDat'); list[1] = { caption: '물가자료', page: '120', visible: false }; list[2] = { caption: '유통물가', page: '', visible: false }; EstSources.set(p.options, 'StuffcDat', list); const after = tc(p); let dup = ''; try { EstSources.set(p.options, 'StuffcDat', list.map(() => ({ caption: '가격정보' }))); } catch (e) { dup = e.message; } EstSources.set(p.options, 'LaborcDat', list.map(() => ({ caption: '같음' }))); return { before, after, dup, label: EstSources.label(p.options, 'StuffcDat', 'Cost2'), other: EstSources.label(p.options, 'EstMainDat', 'Cost2'), cols: EstSources.columns(p.options, 'StuffcDat', ['Code', 'Cost1', 'Cost2', 'Cost3', 'TC']) }; })()""" ) assert out["before"] == [80, 120] assert out["after"] == [100, 100] assert out["dup"] == "같은 발췌근거가 있습니다." assert out["label"] == "물가자료 (120)" assert out["other"] == "" assert out["cols"] == ["Code", "Cost1", "TC"]