# -*- coding: utf-8 -*- """공용 틀 글 손 입력 · 기타 선택 컨테이너 · 기타 이름 = 집계 건 이름 — PLAN 52-14. 순수 규칙은 Node 헬퍼(`helper_52_structure_spec.cjs etc`)가 돌림 · 화면은 ORCA `ui_checks/52-10_노면공_기타.js`(52-14 덧). """ import json import os import re import subprocess import pytest from M02_MasterTemplete import M02_Table_Fill as fill from M02_MasterTemplete.M02_Table_Fill_Spec import SPEC_CONTAINERS, container_rows, etc_label from resources.tester.test_structures_summary_snapshot import ( # noqa: F401 — world 고정물 MS, RV, _save, world, ) HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(os.path.dirname(HERE)) @pytest.fixture(scope="module") def out(): proc = subprocess.run( ["node", os.path.join(HERE, "helper_52_structure_spec.cjs"), "etc"], capture_output=True, text=True, encoding="utf-8", timeout=60, ) assert proc.returncode == 0, proc.stderr return json.loads(proc.stdout) def test_기타_선택_컨테이너_상세_내용(out): assert out["same"] is True assert out["containers"] == [["detail", "상세 내용", False, "etc_detail", "getcdetail"]] assert out["items"] == [["note", "비고", "text"]] assert out["links"] == ["getcdetail1", "getcdetail2"] def test_글_저장_비우기_길이_상한(out): assert out["state"] == {"detail": [{"note": "옛 비고"}, {"note": "둘째"}]} # n 차례대로 당김 edited = out["edited"] assert edited["etc_detail_1_note"] == "새 비고" # 앞뒤 빈칸 뺌 assert edited["etc_detail_2_note"] == "" # 비운 인스턴스도 자리를 지킴(잇기 · 집계 줄) assert out["longLen"] == out["max"] == 100 assert out["keys"] == {"keys": [], "prefixes": ["etc_detail_"]} def test_이름_표에_글_항목(out): assert out["names"] == {"detail": "상세 내용", "detail.note": "비고"} def test_기타_이름이_집계_건_이름(): assert etc_label("etc", {"name": " 배수판 "}) == {"그룹": "배수판"} assert etc_label("etc", {"name": ""}) == {"그룹": "기타"} assert etc_label("etc", {}) == {"그룹": "기타"} assert etc_label("pipe", {"name": "x"}) == {} item = { "type_id": "etc", "options": {"name": "배수판", "etc_detail_1_note": "왼쪽", "etc_detail_2_note": ""}, "복사본": "st1", "그룹": "배수판", } rows = container_rows(item, {"getcdetail1": RV, "getcdetail2": MS}) assert [r["그룹"] for r in rows] == ["배수판 1", "배수판 2"] assert [r["복사본"] for r in rows] == ["st1__getcdetail1", "st1__getcdetail2"] assert [r["summary_item"] for r in rows] == [RV, MS] assert rows[0]["options"]["note"] == "왼쪽" def test_집계_모음에_기타_이름과_컨테이너_건(world): # noqa: F811 — 고정물 root = world["root"] etc = { "structure_id": "etc1", "type_id": "etc", "placement": "point", "chainage_m": 60.0, "options": {"name": "배수판", "etc_detail_1_note": "왼쪽"}, "group_items": {"getcdetail1": RV}, } blank = {**etc, "structure_id": "etc2", "chainage_m": 80.0, "options": {"name": ""}} _save(root, [etc, blank], []) items = {i["복사본"]: i for i in fill.collect_items(root)} assert items["etc1"]["그룹"] == "배수판" assert items["etc1__getcdetail1"]["그룹"] == "배수판 1" assert items["etc1__getcdetail1"]["summary_item"] == RV assert items["etc2"]["그룹"] == "기타" def test_서버_컨테이너_표는_기타_명세와_짝(): with open( os.path.join(ROOT, "A00_Common/design/design_structure_road.ts"), encoding="utf-8" ) as f: text = f.read() found = re.findall( r'title: "([^"]+)",\s*required: false,\s*prefix: "(\w+)",\s*link: "(\w+)"', text ) assert [(p, link, t) for t, p, link in found] == list(SPEC_CONTAINERS["etc"])