Files
Aislo/resources/tester/test_353_2_contour_lock.py
T

91 lines
3.5 KiB
Python

"""353-2 평면 등고선 자물쇠 — 규칙(`logic/B05_Profile_ContourLock.ts`)을 Node 로 돌려 판정 +
편집기 이음(고르기 막음 · 지형 바꿔도 같은 높이 · 호버 = 집기와 같은 hitPreparedLayer).
./venv/Scripts/python.exe -m pytest resources/tester/test_353_2_contour_lock.py -q
"""
import json
import subprocess
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[2]
B05 = ROOT / "B05_Profile"
LOGIC = B05 / "logic" / "B05_Profile_ContourLock.ts"
TS = ROOT / "config" / "node_modules" / "typescript"
DRIVER = r"""
const fs = require("fs");
const ts = require(process.argv[1]);
const js = ts.transpileModule(fs.readFileSync(process.argv[2], "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const m = { exports: {} };
new Function("exports", "module", js)(m.exports, m);
const L = m.exports;
const levels = [101, 102, 105, 102, null];
console.log(JSON.stringify({
hitPicked: L.lockButtonState(102, null, true),
hitOnly: L.lockButtonState(102, null, false),
hitNone: L.lockButtonState(null, null, true),
hitLocked: L.lockButtonState(102, 102, false),
hitOther: L.lockButtonState(105, 102, true),
lock: L.toggleLock(null, 102),
unlock: L.toggleLock(102, 105),
pickFree: L.canPickContour(null),
pickLocked: L.canPickContour(102),
again: L.featureOfLevel(levels, 102),
gone: L.featureOfLevel(levels, 110),
none: L.featureOfLevel(levels, null),
}));
"""
@pytest.fixture(scope="module")
def got() -> dict:
run = subprocess.run( # noqa: S603 — 고정 실행 파일
["node", "-e", DRIVER, str(TS), str(LOGIC)], capture_output=True, text=True, timeout=60
)
assert run.returncode == 0, run.stderr
return json.loads(run.stdout)
def test_안_잠김_단추는_고른_가닥을_누를_때만(got) -> None:
"""366-1 — 지나기만 · 고르지 않은 가닥 = 안 뜸."""
assert got["hitPicked"] == {"visible": True, "pressed": False}
assert got["hitOnly"]["visible"] is False
assert got["hitNone"]["visible"] is False
def test_잠김_단추는_잠근_높이_아무_가닥을_누를_때_풀기(got) -> None:
assert got["hitLocked"] == {"visible": True, "pressed": True}
assert got["hitOther"]["visible"] is False
def test_누르면_잠금_다시_누르면_풂(got) -> None:
assert got["lock"] == 102 and got["unlock"] is None
def test_잠긴_동안_고르기_막음(got) -> None:
assert got["pickFree"] is True and got["pickLocked"] is False
def test_지형_바꿔도_같은_높이를_다시_짚음(got) -> None:
assert got["again"] == 1 and got["gone"] == -1 and got["none"] == -1
def test_편집기_이음() -> None:
edit = (B05 / "B05_Profile_UI_RouteEdit.ts").read_text("utf-8")
assert "if (contourLock.canPick()) pickedContour = index;" in edit
assert "pickedContour = contourLock.reattach(contours?.layer ?? null);" in edit
lock = (B05 / "B05_Profile_UI_RouteEdit_ContourLock.ts").read_text("utf-8")
assert "hitPreparedLayer(" in lock and 'setAttribute("aria-pressed"' in lock
assert "sessionStorage" not in lock and "writeState" not in lock # 페이지 동안만
# 366-1 — 지나기(pointermove)로 안 띄움 · 뗀 자리 · 다음 클릭 · 휠 · 떠남에 숨김
assert '"pointermove"' not in lock
assert 'canvas.addEventListener("pointerup", showAt);' in lock
assert 'canvas.addEventListener("wheel", hide' in lock
assert 'canvas.addEventListener("pointerleave", hideLater);' in lock
assert "picked: pickedContour" in edit