feat(notice): urgent notices centered on every ERP screen until acknowledged
- Super admin only: /notice/ page (title, body with images, show time KST, all or picked people,
preview, edit with optional re-show, cancel/undo, per-person acknowledgement status)
- Shown on every ERP page (erp_base, main, admin) dead center; [확인] only (no Esc/backdrop close),
queue in order, ack failure keeps the dialog, closes when acked/cancelled elsewhere
- project_db migration 024 (urgent_notices, targets, acks, images as bytea); shares ProjectStore.pool
- Body sanitized like task descriptions, images restricted to /notice/images/{id}, type sniffed
- Entry points: ERP sidebar foot and Project options dialog (super admin)
- Docs (NOTICE_MODULE, DEPLOYMENT 024, overview, CLAUDE.md); tests (DB-less, real PostgreSQL, jsdom)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// 긴급 공지 화면(static/erp-notice.js) — jsdom. 가운데 창·차례대로·[확인] 전엔 안 닫힘·확인 실패 유지·다른 곳 확인 반영.
|
||||
// NODE_PATH=<jsdom 경로> 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("<!doctype html><body><main>화면</main></body>", { 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, "서버 점검", '<p>오늘 <b>18시</b></p><img src="/notice/images/3">'), 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); });
|
||||
Reference in New Issue
Block a user