Files
Aislo/resources/tester/test_709_pager_fit.py
T
eomsangdon 2e43011069 feat(709-1): 쪽 단추 부품 · 수평 구분선 부품 · 부품 모음 견본
- ui_template_pager.ts: M01 buildPager 이동 + 화면 높이 줄 수 셈(fitRows) · 첫 줄 유지(pageKeepFirst) · 화면 크기 알림(watchFit)
- ui_template_divider.ts + overlay.css .ui-divider: 수평 구분선
- M01 buildPager = 새 부품을 부르는 옛 이름(PickTable · M02 목록 그대로)
- 부품 모음 견본 두 줄 · 지킴 시험 test_709_pager_fit.py
2026-11-01 14:40:53 +09:00

78 lines
2.7 KiB
Python

"""709 쪽 단추 부품 지킴 시험 — 쪽 수 · 화면 높이 → 줄 수 · 쪽 크기 바뀔 때 첫 줄 유지(순수 함수).
`ui_template/ui_template_pager.ts` 의 「순수 셈」 구간만 떼어 node 로 돌림(화면 · 서버 없음).
부품 모음 견본 · 옛 이름 `buildPager` 가 새 부품을 부르는지도 글로 잡음.
"""
import json
import re
import shutil
import subprocess
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[2]
PAGER = ROOT / "ui_template" / "ui_template_pager.ts"
pytestmark = pytest.mark.skipif(shutil.which("node") is None, reason="node 가 없음")
def _pure() -> str:
text = PAGER.read_text(encoding="utf-8")
start = text.index("export const ROW_H")
end = text.index("/** 표 칸 위쪽")
return text[start:end]
def _run(body: str) -> object:
script = _pure() + "\n" + body
out = subprocess.run(
["node", "--experimental-strip-types", "--no-warnings",
"--input-type=module-typescript", "-e", script],
capture_output=True, text=True, encoding="utf-8", timeout=60,
) # fmt: skip
assert out.returncode == 0, out.stderr
return json.loads(out.stdout)
def test_쪽_수():
got = _run(
"console.log(JSON.stringify([pageCount(0,30), pageCount(30,30), pageCount(31,30), pageCount(1469,30)]));"
)
assert got == [1, 1, 2, 49]
def test_화면_높이_줄_수():
# 머리 40 + 줄 40 · 표 칸 위 200 · 쪽 단추 자리 56 → 1080: (824-40)/40=19 · 768: (512-40)/40=11
got = _run(
"console.log(JSON.stringify(["
"fitRows(1080-200-PAGER_ROOM), fitRows(768-200-PAGER_ROOM), "
"fitRows(100), fitRows(100000), fitRows(Number.NaN), fitRows(520, 36, 40)]));"
)
assert got == [19, 11, 5, 200, 5, 13]
def test_높이가_클수록_줄이_많음():
got = _run(
"const a=[]; for (let h=300; h<=1400; h+=50) a.push(fitRows(h)); "
"console.log(JSON.stringify(a.every((v,i)=>i===0||v>=a[i-1])));"
)
assert got is True
def test_쪽_크기_바뀌어도_첫_줄_유지():
# 30줄 쪽의 3쪽(첫 줄 61번째) → 20줄 쪽이면 4쪽(61~80) · 50줄 쪽이면 2쪽(51~100)
got = _run(
"console.log(JSON.stringify([pageKeepFirst(3,30,20), pageKeepFirst(3,30,50), pageKeepFirst(1,30,12)]));"
)
assert got == [4, 2, 1]
def test_옛_이름은_새_부품():
cells = (ROOT / "M01_MasterData" / "M01_MasterData_UI_Cells.ts").read_text(encoding="utf-8")
assert re.search(r"export const buildPager = createPager;", cells)
assert "createButton" not in cells
parts = (ROOT / "ui_template" / "ui_template_ui_kit_parts.ts").read_text(encoding="utf-8")
assert 'file: "ui_template_pager.ts"' in parts and 'file: "ui_template_divider.ts"' in parts