"""263-1 「운반 단가」 모달 = 고른 항목 입력만 + 거리 자동 — 사이클 손 칸 · 8-2-8 표 고르기 없음 · [변경] = 단가연결 한 목록 · 거리 칸(운반거리 · Cm · 사이클시간 · t2) = 거리에서 · 손 값 이김 · 옛 `cycle` = 서버 읽기 그대로(모달 [적용]하면 지움).""" import json import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT)) from B08_Quantity.B08_Quantity_Haul_Cycle import FILL, cycle_time, fill_given # noqa: E402 from B09_Estimation.B09_Estimation_Sangeun import _input_names, hand_sources # noqa: E402 DIST = {"L1": 23.8, "L2": 10.5} def _src(name: str) -> str: return (ROOT / name).read_text(encoding="utf-8") def test_왼쪽_칸_고른_로직_입력만(): modal = _src("B09_Estimation/B09_Estimation_UI_Haul_Modal.ts") for gone in ("data-haul-cycle", "CC000054", "사이클시간 입력", "표에서 고르기", "다른 종류", "numberField", "loadTable"): # fmt: skip assert gone not in modal, gone # 칸 = 로직 입력 하나에 한 줄(createValueControl) · 사이클 줄 = 거리 칸 있을 때만 assert "st.inputs.map((input) =>" in modal and "createValueControl(" in modal # 277 — 거리 칸 · 사이클 칸 = 거리 칸 받는 로직만(test_277_1) assert "want.some((n) => n in CYCLE_FILL) ? [distBox(o.dist, input)]" in modal # 거리 받는 마스터 로직 = 거리 칸 하나씩 for code, want in (("GF000284", "운반거리"), ("GF000134", "Cm"), ("GF000283", "사이클시간")): names = _input_names(code) assert [n for n in names if n in FILL] == [want], (code, names) def test_변경_한_목록(): modal = _src("B09_Estimation/B09_Estimation_UI_Haul_Modal.ts") assert "openPriceLink({ ...o, onPick: usePicked })" in modal and "importLib(o, {" in modal link = _src("B09_Estimation/B09_Estimation_UI_Tabs_Bill_Link.ts") assert "o.onPick ??" in link and "openHaulModal({ ...link, ref" in link milestone = _src("B08_Quantity/B08_Quantity_UI_Milestone.ts") assert "other:" not in milestone # 276 = 연결 없음은 옛 길(openPriceLink) — test_276_1 def test_거리_칸_자동_손_값_이김(): ref = {"given": {"재료": "토사"}, "cycle": {}, "own": []} got = fill_given(ref, _input_names("GF000284"), DIST) assert got["운반거리"] == 34.3 # L1 + L2 cm = cycle_time(DIST)["cm"] assert fill_given(ref, ["Cm"], DIST)["Cm"] == cm assert fill_given(ref, ["사이클시간", "t2"], DIST) == { "재료": "토사", "사이클시간": cm, "t2": cycle_time(DIST)["t2"]} # fmt: skip mine = {"given": {"운반거리": 5}, "own": ["운반거리"]} assert fill_given(mine, ["운반거리"], DIST)["운반거리"] == 5 def test_ts_짝_사이클_비움(): """모달 = cycle {} · 옛 own L1 · L2 · t1 뺌 → TS fillGiven = 파이썬과 같음.""" calc = ROOT / "B08_Quantity" / "B08_Quantity_Haul_Cycle.ts" ref = {"given": {"qt": 15}, "cycle": {}, "own": []} body = ( f"\nconsole.log(JSON.stringify(fillGiven({json.dumps(ref)}, ['Cm', '운반거리']," f" {json.dumps(DIST)})));" ) result = subprocess.run( ["node", "--experimental-strip-types", "--no-warnings", "--input-type=module-typescript", "-e", calc.read_text(encoding="utf-8") + body], capture_output=True, text=True, encoding="utf-8", timeout=60, ) # fmt: skip assert result.returncode == 0, result.stderr assert json.loads(result.stdout) == fill_given(ref, ["Cm", "운반거리"], DIST) modal = _src("B09_Estimation/B09_Estimation_UI_Haul_Modal.ts") assert ( "cycle: {}, given: st.given" in modal and 'OLD_OWN = new Set(["L1", "L2", "t1"])' in modal ) assert "cycle: st.cycle" not in modal # [적용] 새 연결에 cycle 없음 def test_옛_cycle_서버_읽기_그대로(): old = {"tab": "logic", "code": "GF000134", "given": {"Cm": 1}, "cycle": {"V1": 20}} user = {"haul_refs": {"haul:r-u1": old}, "haul_dist": {"haul:r-u1": DIST}} ((_k, _u, src),) = hand_sources(user) assert src["given"]["Cm"] == cycle_time({**DIST, "V1": 20})["cm"] new = {**old, "cycle": None} user["haul_refs"]["haul:r-u1"] = new ((_k, _u, src),) = hand_sources(user) assert src["given"]["Cm"] == cycle_time(DIST)["cm"]