- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침 - 확인: 이 묶음 헬퍼를 쓰는 시험 233 개 전 233 통과 → 후 233 통과 (시험별 junit 대조 · 어긋남 0) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
222 lines
7.8 KiB
JavaScript
222 lines
7.8 KiB
JavaScript
/* 다단 흙막이 ↔ 흙막이 컨테이너(PLAN 54-10) 단위검증 헬퍼 — TS 를 그 자리에서 트랜스파일해 Node 로 돌린다.
|
|
* ① 폼 → 다단 그림(`applyPipeOptionsToCache`) ② 밖에서 정한 개수보다 많은 컨테이너 값은 가리기만(`createSpecForm`).
|
|
* 결과는 표준출력에 JSON 한 벌. 짝 = `test_54_10_soil_tiers.py`.
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
|
|
const CATALOG = require("./helper_322_catalog_module.cjs"); // 구조물 표(322-1)
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
|
|
// ── 화면 그릇 흉내 — 태그 · 클래스 · data 만 ─────────────────────────────────
|
|
class FakeNode {
|
|
constructor(tag) {
|
|
this.tagName = tag.toUpperCase();
|
|
this.children = [];
|
|
this.dataset = {};
|
|
this.style = {};
|
|
this._classes = new Set();
|
|
this._text = "";
|
|
this.value = "";
|
|
const self = this;
|
|
this.classList = {
|
|
add: (...n) => n.forEach((c) => self._classes.add(c)),
|
|
remove: (...n) => n.forEach((c) => self._classes.delete(c)),
|
|
toggle: (c, f) =>
|
|
(f ?? !self._classes.has(c)) ? self._classes.add(c) : self._classes.delete(c),
|
|
contains: (c) => self._classes.has(c),
|
|
};
|
|
}
|
|
set className(v) {
|
|
this._classes = new Set(String(v).split(/\s+/).filter(Boolean));
|
|
}
|
|
set textContent(v) {
|
|
this._text = String(v);
|
|
this.children = [];
|
|
}
|
|
get textContent() {
|
|
return this._text + this.children.map((c) => c.textContent ?? "").join("");
|
|
}
|
|
append(...kids) {
|
|
kids.forEach((k) => this.children.push(typeof k === "string" ? { textContent: k } : k));
|
|
}
|
|
replaceChildren(...kids) {
|
|
this.children = [];
|
|
this.append(...kids);
|
|
}
|
|
add(kid) {
|
|
this.children.push(kid);
|
|
}
|
|
setAttribute(n, v) {
|
|
this[n] = v;
|
|
}
|
|
addEventListener() {}
|
|
closest() {
|
|
return null;
|
|
}
|
|
matches(sel) {
|
|
return sel.split(",").some((s) => {
|
|
s = s.trim();
|
|
return s.startsWith(".") ? this._classes.has(s.slice(1)) : this.tagName === s.toUpperCase();
|
|
});
|
|
}
|
|
querySelectorAll(sel) {
|
|
const found = [];
|
|
const walk = (n) =>
|
|
(n.children ?? []).forEach((k) => {
|
|
if (k.matches?.(sel)) found.push(k);
|
|
walk(k);
|
|
});
|
|
walk(this);
|
|
return found;
|
|
}
|
|
querySelector(sel) {
|
|
return this.querySelectorAll(sel)[0] ?? null;
|
|
}
|
|
}
|
|
globalThis.document = { createElement: (t) => new FakeNode(t) };
|
|
globalThis.queueMicrotask = (fn) => fn(); // 폼 되돌림을 바로 받아 봄
|
|
globalThis.Option = function (text, value) {
|
|
const o = new FakeNode("option");
|
|
o.textContent = text;
|
|
o.value = value;
|
|
return o;
|
|
};
|
|
|
|
const toasts = [];
|
|
const STUBS = {
|
|
"@ui/ui_template_elements": { showToast: (msg) => toasts.push(msg) },
|
|
"@config/config_frontend": { FORD_MANNING_N: 0.03, FORD_SLOPE: 0.02 },
|
|
"./ui_template_checkbox.css": {},
|
|
"./B06_Section_UI_Page_Ford_Controls": {
|
|
applyFordFormOptions: () => {},
|
|
applyBoxFormOptions: () => {},
|
|
},
|
|
"../../B05_Profile/B05_Profile_UI_Structures_Summary_Row": { buildSummaryRow: () => null },
|
|
};
|
|
|
|
const { loadTs } = makeLoader({
|
|
root: ROOT,
|
|
requireFor: (full) => (request) => {
|
|
if (CATALOG.isCatalogRequest(request)) return CATALOG;
|
|
if (STUBS[request]) return STUBS[request];
|
|
if (request.startsWith("@util/"))
|
|
return loadTs(path.join(ROOT, "common_util", `${request.slice(6)}.ts`));
|
|
return loadTs(path.join(path.dirname(full), `${request}.ts`));
|
|
},
|
|
});
|
|
|
|
const out = {};
|
|
|
|
// ── ① 폼 → 다단 그림 ──────────────────────────────────────────────────────
|
|
const { applyPipeOptionsToCache } = loadTs(
|
|
path.join(ROOT, "B06_Section", "B06_Section_UI_Page_Pipe_Options.ts"),
|
|
);
|
|
const adjusts = {};
|
|
const updates = [];
|
|
const tiers = [];
|
|
const overrides = [];
|
|
const section = {
|
|
chainage_m: 100,
|
|
culvert: { diameter_m: 1, hidden_pipe: false, inlet: {}, outlet: { revet_form: "돌쌓기(찰)" } },
|
|
};
|
|
const ctx = {
|
|
detail: () => ({ cross_sections: [section] }),
|
|
ford: {},
|
|
box: {},
|
|
revetOffset: {
|
|
adjustFor: (_s, role) => adjusts[role] ?? { x: 0, d: null, h: null, m: null },
|
|
update: (_c, role, patch) => {
|
|
updates.push({ role, ...patch });
|
|
const now = adjusts[role] ?? { x: 0, d: null, h: null, m: null };
|
|
const m = patch.m === undefined ? now.m : patch.m;
|
|
// 기하 되받기(syncApplied) 흉내 — 형태별 높이 한도 없음(54-42 · 입력 높이 그대로)
|
|
const h = patch.h === undefined ? now.h : patch.h;
|
|
adjusts[role] = { ...now, h, m };
|
|
},
|
|
},
|
|
structureSpan: {
|
|
tierValuesFor: () => ({ lengthM: 10, beforeM: 5, afterM: 5 }),
|
|
updateTier: (_s, key, patch) => tiers.push({ key, ...patch }),
|
|
},
|
|
soilTiers: () => 2,
|
|
overrideOptions: (_c, values) => overrides.push(values),
|
|
refreshCard: () => {},
|
|
};
|
|
applyPipeOptionsToCache(ctx, 100, {
|
|
soil_add_1_form: "콘크리트",
|
|
soil_add_1_height: 1.8,
|
|
soil_add_1_length: 8,
|
|
soil_add_1_before: 3,
|
|
soil_add_1_after: 5,
|
|
soil_add_2_form: "돌쌓기(메)",
|
|
soil_add_2_height: 2.5,
|
|
soil_add_3_height: 1.2, // 지형이 못 세운 단 — 그림에 안 감
|
|
});
|
|
out.filled = { updates: updates.splice(0), tiers: tiers.splice(0), overrides: overrides.splice(0) };
|
|
out.toasts = toasts.splice(0);
|
|
// 같은 값을 다시 보내면 다시 그리지 않음
|
|
applyPipeOptionsToCache(ctx, 100, {
|
|
soil_add_1_form: "콘크리트",
|
|
soil_add_1_height: 1.8,
|
|
soil_add_2_form: "돌쌓기(메)",
|
|
soil_add_2_height: 2.5,
|
|
});
|
|
out.same = { updates: updates.splice(0), tiers: tiers.splice(0) };
|
|
// 그림이 안 서는 높이(0 이하)만 하한 0.1 에서 멈춰 폼에 되돌림 · 토스트 없음(54-51)
|
|
applyPipeOptionsToCache(ctx, 100, {
|
|
soil_add_1_form: "콘크리트",
|
|
soil_add_1_height: 0,
|
|
soil_add_2_form: "돌쌓기(메)",
|
|
soil_add_2_height: 2.5,
|
|
});
|
|
out.floor = { updates: updates.splice(0), overrides: overrides.splice(0) };
|
|
out.toasts.push(...toasts.splice(0));
|
|
// 비운 칸 = 자동(높이 · 형태) · 구간값은 그대로
|
|
applyPipeOptionsToCache(ctx, 100, {});
|
|
out.cleared = { updates: updates.splice(0), tiers: tiers.splice(0) };
|
|
// 독립 기슭막이(관 숨김)는 다단을 안 만짐
|
|
section.culvert.hidden_pipe = true;
|
|
applyPipeOptionsToCache(ctx, 100, { soil_add_1_height: 1.0 });
|
|
out.hidden = updates.splice(0);
|
|
|
|
// ── ② 개수보다 많은 컨테이너 값은 가리기만 · 값은 남김 ───────────────────────
|
|
const { createSpecForm } = loadTs(
|
|
path.join(ROOT, "A00_Common", "design", "design_structure_form.ts"),
|
|
);
|
|
const { PIPE_SPEC } = loadTs(
|
|
path.join(ROOT, "A00_Common", "design", "logic", "design_structure_pipe.ts"),
|
|
);
|
|
let count = 1;
|
|
const form = createSpecForm(null, { count: (c) => (c.id === "soil_add" ? count : undefined) });
|
|
form.write(PIPE_SPEC, {
|
|
pipe_diameter_mm: 1000,
|
|
soil_add_1_form: "콘크리트",
|
|
soil_add_2_form: "돌망태",
|
|
soil_add_2_height: 1.5,
|
|
chute_add_1_structure: "돌붙임",
|
|
});
|
|
// 상자 이름표 단추(136-3) — 글 「삭제」 + title
|
|
out.remove = form.root
|
|
.querySelectorAll("button")
|
|
.filter((b) => b.dataset.specRemove)
|
|
.map((b) => ({ id: b.dataset.specRemove, text: b.textContent, title: b.title }));
|
|
const boxes = () =>
|
|
form.root.children.filter((k) => k.dataset?.specContainer === "soil_add").length;
|
|
const soilKeys = () =>
|
|
Object.keys(form.read())
|
|
.filter((k) => k.startsWith("soil_add_"))
|
|
.sort();
|
|
out.form = { shown1: boxes(), keys1: soilKeys() };
|
|
count = 0; // 단 수 0 저장 — 옛 흙막이 값도 남음
|
|
form.recount();
|
|
out.form.shown0 = boxes();
|
|
out.form.keys0 = soilKeys();
|
|
count = 3;
|
|
form.recount();
|
|
out.form.shown3 = boxes();
|
|
out.form.keys3 = soilKeys();
|
|
|
|
process.stdout.write(JSON.stringify(out));
|