Files
dbx-main/tests/js/inout_datepop.browser.test.js
T
king b7e05f58aa feat(입출고): 발주 목록에 입고일 열 추가
입고 예정일과 발주 사이에 입고일을 보여 준다. 여러 날에 나눠 입고하면 칸 안에서
줄바꿈하고, 같은 날 여러 번 입고는 한 번만, 입고 전에는 - 로 표시한다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 14:45:33 +09:00

90 lines
5.9 KiB
JavaScript

// 입출고 날짜 칸 = ERP 공용 달력(2026-11-05) — 실제 브라우저(Chromium).
// python tests/js/render_inout.py
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/inout_datepop.browser.test.js
// 기본 달력 대신 날짜 버튼, 국경일·대체공휴일 빨강·이름·말풍선(title), 고르면 값 전송, 필수 칸은 지우기 없음, 잠긴 칸은 못 누름.
const fs = require("fs"), path = require("path");
const { chromium } = require("playwright");
const ROOT = path.join(__dirname, "..", "..");
const fails = [];
function check(name, cond, extra) {
if (cond) console.log("PASS " + name);
else { console.log("FAIL " + name + (extra !== undefined ? " → " + JSON.stringify(extra) : "")); fails.push(name); }
}
(async function () {
const exe = process.env.PJ_TEST_BROWSER;
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
try {
const p = await (await browser.newContext({ viewport: { width: 1400, height: 900 } })).newPage();
const errors = [];
p.on("pageerror", function (e) { errors.push(String(e)); });
await p.route("**/*", function (r) {
const url = new URL(r.request().url()).pathname;
if (url.startsWith("/static/")) {
const f = path.join(ROOT, "app", url);
if (!fs.existsSync(f)) return r.fulfill({ status: 404, body: "" });
const type = f.endsWith(".css") ? "text/css" : f.endsWith(".js") ? "application/javascript" : "font/woff2";
return r.fulfill({ status: 200, contentType: type, body: fs.readFileSync(f) });
}
if (!url.endsWith(".html")) return r.fulfill({ status: 200, contentType: "application/json", body: "{}" });
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", url.slice(1)), "utf8") });
});
await p.goto("http://erp.test/inout_form.html");
await p.waitForTimeout(200);
const order = p.locator('input[name="order_date"]'), due = p.locator('input[name="due_date"]');
check("기본 달력 칸은 숨김", !(await order.isVisible()) && !(await due.isVisible()));
const orderBtn = p.locator('input[name="order_date"] + button'), dueBtn = p.locator('input[name="due_date"] + button');
check("발주일 버튼 = yyyy.mm.dd(요일)", (await orderBtn.textContent()).includes("2026.10.05(월)"), await orderBtn.textContent());
await orderBtn.click();
const pop = p.locator(".pj-datepop");
check("달력이 열림", await pop.isVisible());
const hol = pop.locator('[data-iso="2026-10-09"]');
check("한글날 = 빨강 칸·이름·말풍선", (await hol.getAttribute("class")).includes("is-sun") && (await hol.getAttribute("title")) === "한글날" && (await hol.textContent()).includes("한글날"), await hol.getAttribute("title"));
check("필수 칸은 지우기 없음", (await pop.getByText("지우기").count()) === 0);
await p.waitForTimeout(200); // 등장 애니메이션 뒤에 찍는다
await p.screenshot({ path: path.join(__dirname, ".out", "inout_datepop.png") });
await pop.locator('[data-iso="2026-10-08"]').click();
await p.keyboard.press("Escape");
check("고른 날짜가 값으로", (await order.inputValue()) === "2026-10-08", await order.inputValue());
check("버튼 글자도 바뀜", (await orderBtn.textContent()).includes("2026.10.08(목)"));
await dueBtn.click();
check("선택 칸은 지우기 있음", (await pop.getByText("지우기").count()) === 1);
// 대체공휴일 — 2026-03-02 삼일절 대체(달을 넘겨 찾지 않고 표 값으로 확인)
const holidays = await p.evaluate(function () { return JSON.parse(document.getElementById("io-holidays").textContent); });
check("대체공휴일도 표에 있음", holidays["2026-03-02"] === "삼일절 대체", holidays["2026-03-02"]);
await p.keyboard.press("Escape");
await p.goto("http://erp.test/inout_list.html");
await p.waitForTimeout(200);
check("목록 필터 시작일 버튼", (await p.locator('input[name="from"] + button').textContent()).includes("2026.10.01(목)"));
const box = await p.locator('input[name="from"] + button').boundingBox();
const search = await p.locator('input[name="q"]').boundingBox();
check("필터 줄 높이가 맞음", Math.abs((box.y + box.height / 2) - (search.y + search.height / 2)) < 4, { box: box, search: search });
await p.screenshot({ path: path.join(__dirname, ".out", "inout_list.png") });
// 목록 입고일 열(2026-11-05) — 입고 예정일과 발주 사이, 여러 날은 한 칸에서 줄바꿈, 입고 전 "-"
const heads = await p.locator(".io-table thead th").allInnerTexts();
check("입고일 열 위치", heads.indexOf("입고일") === heads.indexOf("입고 예정일") + 1 && heads.indexOf("발주") === heads.indexOf("입고일") + 1, heads);
const col = heads.indexOf("입고일") + 1;
const cell = function (row) { return p.locator(".io-table tbody tr:nth-child(" + row + ") td:nth-child(" + col + ")"); };
const lines = await cell(1).locator("div").evaluateAll(function (els) {
return els.map(function (el) { return { text: el.textContent, top: el.getBoundingClientRect().top }; });
});
check("여러 날 = 줄바꿈", lines.length === 2 && lines[0].text === "2026.10.21(수)" && lines[1].text === "2026.10.23(금)" && lines[1].top > lines[0].top, lines);
check("하루 입고 = 한 줄", (await cell(2).innerText()).trim() === "2026.10.22(목)");
check("입고 전 = -", (await cell(3).innerText()).trim() === "-");
await p.goto("http://erp.test/inout_locked.html");
await p.waitForTimeout(200);
check("잠긴 입고일은 못 누름", await p.locator('input[name="receipt_date"] + button').isDisabled());
check("스크립트 오류 없음", errors.length === 0, errors);
} finally {
await browser.close();
}
if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); }
console.log("\nALL OK");
})();