// 휴가 옵션 잔여 연차 — 입사일 기준(2026-10-27, 12/31 소멸 없음) — 실제 브라우저(Chromium). // python tests/js/render_vacation.py // NODE_PATH= PJ_TEST_BROWSER= node tests/js/vacation_balances.browser.test.js // 이름 옆 입사일 날짜 버튼 → 근속·이번 연차 기간·생기는 연차(오늘까지 +앞으로)를 바로 계산, 사용·잔여·소멸은 "저장 후"(서버 계산), // 1년씩 이동, 저장하면 줄마다 email·hire·total·prior·memo. 오늘 = 2026-10-26(렌더 데이터에 고정). 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 } : {}); const posts = []; try { const p = await (await browser.newContext({ viewport: { width: 1500, height: 900 } })).newPage(); await p.route("**/*", function (r) { const req = r.request(), url = new URL(req.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 (req.method() === "POST") { posts.push(req.postData()); return r.fulfill({ status: 200, contentType: "text/html", body: "ok" }); } r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", "vac_options.html"), "utf8") }); }); await p.goto("http://erp.test/vacation/options"); await p.waitForTimeout(200); const rowState = function (email) { return p.evaluate(function (email) { const tr = document.querySelector('input[name="email"][value="' + email + '"]').closest("tr"); const btn = tr.querySelector(".vac-hire-btn"); const t = function (sel) { return tr.querySelector(sel).textContent.trim().replace(/\s+/g, " "); }; return { btn: btn && btn.textContent.replace("calendar_month", "").trim(), nextToName: !!btn && btn.parentElement === tr.querySelector(".vac-bal-person"), hire: tr.querySelector('input[name="hire"]').value, hireShown: getComputedStyle(tr.querySelector('input[name="hire"]')).display !== "none", years: t(".vac-bal-years-cell"), period: t(".vac-bal-period"), legal: t(".vac-bal-legal"), placeholder: tr.querySelector('input[name="total"]').placeholder, remain: t(".vac-bal-remain"), expire: t(".vac-bal-expire"), stale: tr.classList.contains("is-stale") }; }, email); }; const lee = await rowState("lee@test.local"); check("입사일 = 이름 옆 날짜 버튼(연도까지), 이번 연차 기간·잔여·먼저 소멸(12/31 아님)", lee.nextToName && !lee.hireShown && lee.btn === "2020.03.02(월)" && lee.period === "26.03.02 ~ 27.03.01" && lee.legal === "17" && lee.remain === "12.5" && lee.expire === "27.03.01 · 12.5일", lee); const kim0 = await rowState("kim@test.local"); check("입사일 없음 = '입사일' 버튼, 기간·연차 —", kim0.btn === "입사일" && kim0.years === "—" && kim0.period === "—" && kim0.remain === "—", kim0); const head = await p.evaluate(function () { return Array.from(document.querySelectorAll(".vac-bal-table thead th")).map(function (x) { return x.textContent.trim(); }); }); check("표 머리 = 입사일 기준(연차 기간·생기는 연차·잔여·먼저 소멸), 해 이동 버튼 없음", head.indexOf("이번 연차 기간") >= 0 && head.indexOf("먼저 소멸") >= 0 && head.indexOf("시스템 전 사용") >= 0 && !(await p.$('a[href*="year="]')), head); // 김철수 입사일 2026-10-12(오늘 10/26) → 근속 0년 · 기간 26.10.12 ~ 27.10.11 · 오늘까지 0 (+11) await p.click('tr:has(input[value="kim@test.local"]) .vac-hire-btn'); const pop = await p.evaluate(function () { const el = document.querySelector(".pj-datepop"); return el && { navs: el.querySelectorAll(".pj-dp-navbtn").length, field: el.querySelector(".pj-dp-field").placeholder }; }); check("입사일 팝업 = 날짜 하나, « ‹ › »", !!pop && pop.navs === 4 && pop.field === "입사일", pop); await p.fill(".pj-dp-field", "2026-10-12"); await p.press(".pj-dp-field", "Enter"); const kim1 = await rowState("kim@test.local"); check("10/12 입사 → 이번 기간 26.10.12 ~ 27.10.11, 오늘까지 0 (+11), 잔여·소멸은 저장 후", kim1.btn === "2026.10.12(월)" && kim1.years === "0년" && kim1.period === "26.10.12 ~ 27.10.11" && kim1.legal === "0 (+11)" && kim1.placeholder === "11" && kim1.remain === "저장 후" && kim1.expire === "저장 후" && kim1.stale, kim1); // 2025-03-01 로 바꾸면 근속 1년 · 26.03.01 ~ 27.02.28 · 15 await p.click('tr:has(input[value="kim@test.local"]) .vac-hire-btn'); await p.fill(".pj-dp-field", "2025.3.1"); await p.press(".pj-dp-field", "Enter"); const kim2 = await rowState("kim@test.local"); check("2025-03-01 입사 → 근속 1년 · 26.03.01 ~ 27.02.28 · 15일", kim2.years === "1년" && kim2.period === "26.03.01 ~ 27.02.28" && kim2.legal === "15" && kim2.placeholder === "15", kim2); const note = await p.evaluate(function () { return !document.querySelector(".vac-bal-note").hidden; }); check("바꾸면 '저장하면 다시 계산' 안내", note); await p.fill('tr:has(input[value="lee@test.local"]) input[name="prior"]', "3"); check("시스템 전 사용을 바꾸면 그 줄도 저장 후", (await rowState("lee@test.local")).remain === "저장 후"); // 1년씩 이동 await p.click('tr:has(input[value="lee@test.local"]) .vac-hire-btn'); const t0 = await p.textContent(".pj-dp-title"); await p.click('.pj-dp-navbtn[data-nav="-12"]'); const t1 = await p.textContent(".pj-dp-title"); check("« = 1년 전 달력", t0 === "2020년 3월" && t1 === "2019년 3월", [t0, t1]); await p.keyboard.press("Escape"); await p.click('button[type="submit"]:has-text("잔여 연차 저장")'); await p.waitForTimeout(200); const body = decodeURIComponent((posts[0] || "").replace(/\+/g, " ")); check("저장 → 줄마다 입사일·직접 입력·시스템 전 사용(연도 칸 없음)", /email=kim@test.local/.test(body) && /hire=2025-03-01/.test(body) && /hire=2020-03-02/.test(body) && /prior=3/.test(body) && (body.match(/hire=/g) || []).length === 2 && !/year=/.test(body), body); } finally { await browser.close(); } if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); } console.log("\nALL PASS"); })().catch(function (e) { console.error(e); process.exit(1); });