// 긴급 공지 화면(static/erp-notice.js) — jsdom. 가운데 창·차례대로·[확인] 전엔 안 닫힘·확인 실패 유지·다른 곳 확인 반영. // NODE_PATH= node tests/js/notice_ui.test.js const fs = require("fs"), path = require("path"); const { JSDOM } = require("jsdom"); const JS = fs.readFileSync(path.join(__dirname, "..", "..", "app", "static", "erp-notice.js"), "utf8"); 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); } } const settle = function () { return new Promise(function (r) { let i = 0; (function s() { if (i++ > 30) return r(); setImmediate(s); })(); }); }; function env(opts) { const dom = new JSDOM("
화면
", { runScripts: "dangerously", pretendToBeVisual: true, url: "http://localhost/cupang/" }); const w = dom.window; w.__ERP_NOTICE_TEST__ = true; const e = { w: w, d: w.document, calls: [], pending: opts.pending, ackStatus: 200 }; w.fetch = async function (url, o) { const method = (o && o.method) || "GET"; e.calls.push(method + " " + url); if (url === "/notice/api/pending") { if (opts.status) return { ok: false, status: opts.status, json: async function () { return {}; } }; return { ok: true, status: 200, json: async function () { return { notices: e.pending }; } }; } const m = /^\/notice\/api\/(\d+)\/ack$/.exec(url); if (m) { if (e.ackStatus >= 400) return { ok: false, status: e.ackStatus, json: async function () { return {}; } }; e.pending = e.pending.filter(function (n) { return String(n.id) !== m[1]; }); return { ok: true, status: 200, json: async function () { return { ok: true }; } }; } return { ok: true, status: 200, json: async function () { return {}; } }; }; w.eval(JS); return e; } (async function () { const N = function (id, title, body) { return { id: id, title: title, body_html: body || "", show_at: "2026-10-12T18:00+09:00", created_by: "king@dbxcorp.co.kr" }; }; { const e = env({ pending: [N(1, "서버 점검", '

오늘 18시

'), N(2, "두 번째")] }); await settle(); const box = e.d.querySelector(".erp-notice-backdrop"); check("[공지] 받을 공지가 있으면 body 에 가운데 창(배율 밖)", !!box && box.parentElement === e.d.body && !box.hidden); check("[공지] 제목·본문(서버가 정리한 HTML)·보낸 사람·시각·1/2", box.querySelector(".erp-notice-title").textContent === "서버 점검" && !!box.querySelector(".erp-notice-body b") && !!box.querySelector('.erp-notice-body img[src="/notice/images/3"]') && /King · 10\/12 18:00/.test(box.querySelector(".erp-notice-meta").textContent) && box.querySelector(".erp-notice-count").textContent === "1 / 2"); check("[공지] [확인]에 포커스", e.d.activeElement === box.querySelector(".erp-notice-ok")); box.dispatchEvent(new e.w.KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true })); box.click(); check("[공지] Esc·바깥 클릭으로 닫히지 않음", !box.hidden && box.querySelector(".erp-notice-title").textContent === "서버 점검"); e.ackStatus = 500; box.querySelector(".erp-notice-ok").click(); await settle(); check("[공지] 확인 저장 실패 — 창 유지·안내·다시 누를 수 있음", !box.hidden && !box.querySelector(".erp-notice-error").hidden && !box.querySelector(".erp-notice-ok").disabled && box.querySelector(".erp-notice-title").textContent === "서버 점검"); e.ackStatus = 200; box.querySelector(".erp-notice-ok").click(); await settle(); check("[공지] 확인 → 다음 공지(차례대로)", !box.hidden && box.querySelector(".erp-notice-title").textContent === "두 번째" && e.calls.indexOf("POST /notice/api/1/ack") >= 0 && box.querySelector(".erp-notice-count").hidden); // 다른 탭에서 확인 → 다음 확인 때 닫힘 e.pending = []; await e.w.__erpNotice.poll(); await settle(); check("[공지] 다른 곳에서 확인·취소되면 닫힘", box.hidden); } { const e = env({ pending: [], status: 503 }); await settle(); check("[공지] 024 미적용(503)이면 창 없이 조용히 멈춤", !e.d.querySelector(".erp-notice-backdrop") && e.w.__erpNotice.state().stopped); } console.log(fails.length ? fails.length + " FAIL" : "ALL PASS"); process.exit(fails.length ? 1 : 0); })().catch(function (err) { console.error(err); process.exit(1); });