77cf46c859
- 공용 erp-datepop.js/css(project.js openDatePopover·enhanceDateInput·.pj-datepop CSS 를 떼어 낸 같은 모양·동작) - 시작일·종료일 = 숨긴 input + 날짜 버튼 둘(enhanceRange), 어느 쪽을 눌러도 같은 기간 팝업(누른 칸 먼저, 시작 → 종료 → 닫힘), 반차는 하루짜리, 직접 입력(Enter), Esc·바깥 클릭 닫힘 - 공휴일 = 휴가 설정 공휴일(빨강, 작년~내년) — 팝업 빨강·이름, 예상 일수에서도 제외(서버 compute_days 와 같게) - 테스트: vacation_datepop.browser.test.js(render_vacation.py), 휴가 신청 화면 공휴일·스크립트 렌더 확인 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
125 lines
8.8 KiB
JavaScript
125 lines
8.8 KiB
JavaScript
// 휴가 신청 날짜 칸 = 프로젝트와 같은 아사나식 날짜 팝업(2026-10-27, erp-datepop.js) — 실제 브라우저(Chromium).
|
|
// python tests/js/render_vacation.py
|
|
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/vacation_datepop.browser.test.js
|
|
// 브라우저 기본 달력 없음(숨긴 input = 값 저장소), 시작일·종료일 날짜 버튼 → 기간 팝업(누른 칸이 먼저), 날짜를 고르면 시작 → 종료로 넘어가고
|
|
// 종료를 고르면 닫힘, 공휴일 빨강·이름, 직접 입력(Enter), 반차 = 하루짜리, 제출하면 고른 날짜가 그대로 서버로.
|
|
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: 1300, 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: "<p>saved</p>" }); }
|
|
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", "vac_form.html"), "utf8") });
|
|
});
|
|
await p.goto("http://erp.test/vacation/new");
|
|
await p.waitForTimeout(200);
|
|
const state = function () {
|
|
return p.evaluate(function () {
|
|
const s = document.getElementById("vac-start"), e = document.getElementById("vac-end");
|
|
return { start: s.value, end: e.value, startShown: getComputedStyle(s).display !== "none", endShown: getComputedStyle(e).display !== "none",
|
|
btns: Array.from(document.querySelectorAll(".erp-date-btn")).map(function (b) { return b.textContent.replace("calendar_month", "").trim(); }),
|
|
want: [ErpDatePop.fmt(s.value), ErpDatePop.fmt(e.value)],
|
|
days: document.getElementById("vac-days-out").textContent, pop: !!document.querySelector(".pj-datepop") };
|
|
});
|
|
};
|
|
const s0 = await state();
|
|
// 버튼 글자 = 프로젝트 날짜 버튼과 같은 규칙(오늘·내일·어제, 아니면 mm/dd(요일)) — 오늘 날짜에 따라 달라서 같은 함수로 비교
|
|
const fmtCheck = await p.evaluate(function () {
|
|
return [ErpDatePop.fmt("2026-10-29"), ErpDatePop.fmt("2027-01-04")];
|
|
});
|
|
check("기본 달력 input 숨김 · 날짜 버튼 두 개(시작·종료)", !s0.startShown && !s0.endShown && s0.btns.length === 2 &&
|
|
JSON.stringify(s0.btns) === JSON.stringify(s0.want) && s0.want[0] !== "", s0);
|
|
check("날짜 글자 mm/dd(요일), 다른 해는 연도", ["10/29(목)", "오늘", "내일", "어제"].indexOf(fmtCheck[0]) >= 0 &&
|
|
["2027/01/04(월)", "01/04(월)"].indexOf(fmtCheck[1]) >= 0, fmtCheck);
|
|
// 시작일 버튼 → 기간 팝업(시작일 칸 활성)
|
|
await p.click('.erp-date-btn[data-kind="start"]');
|
|
const pop = await p.evaluate(function () {
|
|
const el = document.querySelector(".pj-datepop");
|
|
const f = Array.from(el.querySelectorAll(".pj-dp-field")).map(function (x) { return [x.placeholder, x.value, x.classList.contains("is-active")]; });
|
|
const hol = el.querySelector('.pj-dp-day[data-iso="2026-10-09"]');
|
|
return { fields: f, title: el.querySelector(".pj-dp-title").textContent, hol: hol && hol.classList.contains("is-sun") && hol.textContent,
|
|
clear: !!el.querySelector(".pj-dp-clear"), parent: el.parentElement === document.body,
|
|
sat: document.querySelector('.pj-dp-day[data-iso="2026-10-24"]').classList.contains("is-sat") };
|
|
});
|
|
check("시작일 버튼 → 기간 팝업(시작일·종료일 칸, 시작일 활성, body 에, 지우기 없음)", pop.parent && !pop.clear &&
|
|
JSON.stringify(pop.fields) === '[["시작일","10월 27일",true],["종료일","10월 27일",false]]' && pop.title === "2026년 10월", pop);
|
|
check("공휴일 빨강 + 이름(한글날), 토요일 파랑", pop.hol === "9한글날" && pop.sat, pop);
|
|
// 시작일 10/29 → 종료일(10/27)이 더 빨라 10/29 로 맞춤, 종료일 칸으로 넘어감(팝업 그대로)
|
|
await p.click('.pj-dp-day[data-iso="2026-10-29"]');
|
|
const s1 = await state();
|
|
const act = await p.evaluate(function () { const a = document.querySelector(".pj-dp-field.is-active"); return a && a.dataset.kind; });
|
|
check("시작일 고름 → 시작·종료 10/29, 팝업은 열린 채 종료일 칸으로", s1.start === "2026-10-29" && s1.end === "2026-10-29" && s1.pop && act === "due", [s1, act]);
|
|
await p.click('.pj-dp-day[data-iso="2026-11-02"]');
|
|
await p.waitForTimeout(50);
|
|
const s2 = await state();
|
|
check("종료일 고름 → 11/02, 팝업 닫힘, 버튼 글자·예상 일수(주말 빼고 3)", s2.end === "2026-11-02" && !s2.pop &&
|
|
s2.btns[1] === s2.want[1] && s2.days === "3", s2);
|
|
// 종료일 버튼 → 종료일 칸이 먼저, 기간 칸 옅은 파랑
|
|
await p.click('.erp-date-btn[data-kind="due"]');
|
|
const pop2 = await p.evaluate(function () {
|
|
const a = document.querySelector(".pj-dp-field.is-active");
|
|
return { active: a && a.dataset.kind, inrange: document.querySelectorAll(".pj-dp-day.is-inrange").length,
|
|
selected: Array.from(document.querySelectorAll(".pj-dp-day.is-selected")).map(function (b) { return b.dataset.iso; }) };
|
|
});
|
|
// 종료일 달(11월)이 보인다 — 11/1 이 일요일이라 10월 날짜는 이 달력에 없음: 기간 = 11/1, 선택 = 11/2
|
|
check("종료일 버튼 → 종료일 칸 활성·종료일 달, 기간 표시", pop2.active === "due" && pop2.inrange === 1 &&
|
|
JSON.stringify(pop2.selected) === '["2026-11-02"]', pop2);
|
|
// 예상 일수는 휴가 설정 공휴일도 뺀다 — 10/8~10/12 = 8·9(한글날)·10·11(주말)·12 → 2일
|
|
await p.click('.erp-date-btn[data-kind="start"]');
|
|
await p.fill('.pj-dp-field[data-kind="start"]', "10/8");
|
|
await p.press('.pj-dp-field[data-kind="start"]', "Enter");
|
|
await p.fill('.pj-dp-field[data-kind="due"]', "10/12");
|
|
await p.press('.pj-dp-field[data-kind="due"]', "Enter");
|
|
const sh = await state();
|
|
check("예상 일수 = 주말·공휴일(한글날) 빼고 2", sh.start === "2026-10-08" && sh.end === "2026-10-12" && sh.days === "2", sh);
|
|
await p.click('.erp-date-btn[data-kind="due"]');
|
|
// 직접 입력 — 종료일 칸에 11/3 Enter
|
|
await p.fill('.pj-dp-field[data-kind="due"]', "11/3");
|
|
await p.press('.pj-dp-field[data-kind="due"]', "Enter");
|
|
const s3 = await state();
|
|
check("직접 입력 11/3 Enter → 종료일 11/03, 닫힘", s3.end === "2026-11-03" && !s3.pop, s3);
|
|
// Esc 로 닫기
|
|
await p.click('.erp-date-btn[data-kind="start"]');
|
|
await p.waitForTimeout(50);
|
|
await p.keyboard.press("Escape");
|
|
check("Esc → 닫힘", !(await state()).pop);
|
|
// 반차 — 종료일 칸 숨김, 날짜 버튼 하나로 하루짜리 팝업(시작=종료)
|
|
await p.selectOption("#vac-type", "오전반차");
|
|
await p.click('.erp-date-btn[data-kind="start"]');
|
|
const half = await p.evaluate(function () {
|
|
return Array.from(document.querySelectorAll(".pj-dp-field")).map(function (x) { return x.placeholder; });
|
|
});
|
|
await p.click('.pj-dp-day[data-iso="2026-11-05"]');
|
|
const s4 = await state();
|
|
check("반차 → 날짜 칸 하나 팝업, 고르면 시작=종료=11/05, 0.5일", JSON.stringify(half) === '["날짜"]' &&
|
|
s4.start === "2026-11-05" && s4.end === "2026-11-05" && !s4.pop && s4.days === "0.5", [half, s4]);
|
|
// 제출 — 고른 날짜가 그대로 폼으로
|
|
await p.selectOption("#vac-type", "연차");
|
|
await p.click('button[name="action"][value="submit"]');
|
|
await p.waitForTimeout(200);
|
|
check("제출 → start_date·end_date 가 고른 날짜로 전송", posts.length === 1 && /start_date=2026-11-05/.test(posts[0]) && /end_date=2026-11-05/.test(posts[0]), posts);
|
|
} 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); });
|