feat(vacation): 휴가 신청 날짜 칸 — 프로젝트와 같은 아사나식 날짜 팝업
- 공용 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>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""휴가 신청 화면(form.html)을 진짜 ERP 셸(erp_base.html)로 렌더 — 날짜 팝업 브라우저 테스트용(2026-10-27).
|
||||
|
||||
python tests/js/render_vacation.py # → tests/js/.out/vac_form.html
|
||||
|
||||
DB 없이 화면 데이터만 만든다(공휴일 = 휴가 설정 공휴일 모양 {날짜: 이름}).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import jinja2
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.insert(0, ROOT)
|
||||
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
|
||||
|
||||
from app.modules.vacation.store import HALF_LABELS, HALVES, VACATION_TYPES # noqa: E402
|
||||
|
||||
|
||||
def main() -> None:
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader([
|
||||
os.path.join(ROOT, "app", "templates"), os.path.join(ROOT, "app", "modules", "vacation", "templates")]), autoescape=True)
|
||||
ctx = {"user": {"email": "kim@test.local", "name": "김철수", "picture": ""}, "is_admin": False, "is_approver": False,
|
||||
"nav_items": [], "page_title": "휴가 신청", "page_subtitle": "", "mode": "new", "req": None,
|
||||
"default_date": "2026-10-27", "vacation_types": list(VACATION_TYPES), "halves": list(HALVES),
|
||||
"half_labels": HALF_LABELS, "holidays": {"2026-10-03": "개천절", "2026-10-09": "한글날", "2026-12-25": "성탄절"}}
|
||||
html = env.get_template("vacation/form.html").render(**ctx)
|
||||
with open(os.path.join(OUT_DIR, "vac_form.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,124 @@
|
||||
// 휴가 신청 날짜 칸 = 프로젝트와 같은 아사나식 날짜 팝업(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); });
|
||||
@@ -197,6 +197,9 @@ class Store:
|
||||
self.req.update(status="반려", reject_reason=reason); return dict(self.req)
|
||||
def list_mail_log(self, request_id):
|
||||
return []
|
||||
def list_holidays(self, year=None):
|
||||
return [{"holiday_date": f"{year}-10-09", "name": "한글날", "is_red": True},
|
||||
{"holiday_date": f"{year}-05-01", "name": "근로자의날(회사)", "is_red": False}]
|
||||
|
||||
st = Store()
|
||||
|
||||
@@ -264,6 +267,15 @@ def body(c):
|
||||
# 관리자는 승인자 목록에 없어도 승인
|
||||
who["u"] = admin
|
||||
assert c.post("/vacation/r1/approve").status_code == 303 and sent[-1][:2] == ("approved", "admin@test.local")
|
||||
# 휴가 신청 화면 — 날짜 칸 = 공용 날짜 팝업(erp-datepop), 공휴일(빨강만) 작년~내년을 화면에
|
||||
import json, re
|
||||
from app.timezone import today_kst
|
||||
r = c.get("/vacation/new")
|
||||
assert r.status_code == 200, r.status_code
|
||||
assert "/static/erp-datepop.js" in r.text and "/static/erp-datepop.css" in r.text and "material-symbols.css" in r.text
|
||||
hol = json.loads(re.search(r'<script type="application/json" id="vac-holidays">(.*?)</script>', r.text, re.S).group(1))
|
||||
y = today_kst().year
|
||||
assert hol == {f"{yy}-10-09": "한글날" for yy in (y - 1, y, y + 1)}, hol
|
||||
# Gmail 연결 — 저장소(입출고 DB)가 없으면 옵션으로 돌아와 안내
|
||||
who["u"] = kim
|
||||
r = c.get("/vacation/gmail/connect")
|
||||
|
||||
Reference in New Issue
Block a user