81b1204693
권한(서버) - 공통 권한 모듈 access.py: 모든 판단을 "지금" 권한으로 — 내 작업·수신함·알림·멘션·검색·상세·공유 링크· 댓글·첨부·알림/메일 수신자에서 권한을 잃은 사람 제외(기록은 이력으로 보존) - 소유자 변경·남을 소유자로 지정한 생성은 관리자만, 새 소유자는 권한 있는 등록 사용자 - 삭제는 생성자 규칙 + 지금 권한(멤버에서 빠진 생성자 거절), 댓글 수정·삭제도 지금 권한 - @태그는 볼 수 있는 사람만(mention_skipped), 태그 후보 all-users?task_id=, 새 담당자 권한 검사 - 연결(멀티호밍) 작업은 연결된 프로젝트 멤버에게 읽기 전용(task_link_scope), 볼 수 없는 연결 프로젝트 숨김 저장·동기화(화면) - 작업 창 세대(taskGen)·블록 ctxSeq 로 늦은 A 응답이 B 를 덮지 않게(A→B, A→B→A, 이미지 업로드 중 전환) - 자동 저장 성공/실패 반환, 실패 칸 재시도, 닫기·전환 전 저장 확인(버리기/계속 편집), 미저장 이탈 경고 - 실시간 동기화 observed/applied 분리·실패 재시도·겹침 방지, snapshot?scope=all 로 전체 범위 반영·권한 회수 안내 - 한국시간 기준 오늘(kstTodayIso), 한글 조합 중 Enter 는 제출하지 않음, 댓글 연타·재전송 중복 방지(client_token) 기타 - 파일 댓글은 본문+파일 한 트랜잭션(POST /comments/files), 실패 파일 표시·유지, 작업 창 댓글에 첨부 표시 - 날짜 범위 검증(부분 수정은 최종 상태), 완료 섹션에 바로 만든 작업 완료 처리·알림 - 마감 알림 발송 기록+수신함 알림 원자적(실패 시 재시도), 권한 없는 수신자 제외 - 테스트: tests/test_project_module.py(로컬 PostgreSQL 11개), tests/js/project_ui.test.js(jsdom 51개) - 문서(PROJECT_MODULE 6-10·도움말·CLAUDE.md), project.js/css 캐시 버전 20260930g, 새 마이그레이션·환경변수 없음 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
426 lines
28 KiB
JavaScript
426 lines
28 KiB
JavaScript
// 프로젝트 관리 화면(project/project.html + static/project.js) UI 회귀 테스트 — jsdom.
|
|
// 서버 응답은 가짜(fetch 대체)로, 지연·실패·순서 역전을 직접 만든다. 실제 브라우저 레이아웃·입력기는 아니다.
|
|
//
|
|
// python tests/js/render_project.py # 템플릿 렌더 → tests/js/.out/project_render.html
|
|
// npm install jsdom # (최초 1회)
|
|
// TZ=America/Los_Angeles node tests/js/project_ui.test.js # 해외 시간대 브라우저 흉내
|
|
//
|
|
// 성공하면 마지막 줄 ALL PASS, 실패하면 항목명과 종료코드 1.
|
|
// Git Bash 는 윈도우 프로그램에 TZ 를 넘기지 않아 PJ_TEST_TZ 로도 받는다(날짜 객체를 만들기 전에 설정).
|
|
if (process.env.PJ_TEST_TZ) process.env.TZ = process.env.PJ_TEST_TZ;
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { JSDOM } = require("jsdom");
|
|
const WATCHDOG = setTimeout(function () { console.log("TIMEOUT — 어딘가에서 멈춤"); process.exit(2); }, 90000);
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
const html = fs.readFileSync(path.join(__dirname, ".out", "project_render.html"), "utf8");
|
|
const JS = fs.readFileSync(path.join(ROOT, "app", "static", "project.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); }
|
|
}
|
|
|
|
function deferred() {
|
|
let resolve, reject;
|
|
const p = new Promise(function (a, b) { resolve = a; reject = b; });
|
|
return { promise: p, resolve: resolve, reject: reject };
|
|
}
|
|
|
|
function makeEnv() {
|
|
const dom = new JSDOM(html, { runScripts: "dangerously", pretendToBeVisual: true, url: "http://localhost/project/p/1" });
|
|
const w = dom.window, d = w.document;
|
|
w.__PJ_TEST__ = true;
|
|
w.HTMLCanvasElement.prototype.getContext = function () { return null; };
|
|
w.URL.createObjectURL = function () { return "blob:x"; };
|
|
w.URL.revokeObjectURL = function () {};
|
|
w.Image = function () { const self = this; Object.defineProperty(self, "src", { set: function () { setTimeout(function () { if (self.onerror) self.onerror(); }, 0); } }); };
|
|
w.console.error = function () {};
|
|
let confirmAnswer = false;
|
|
w.erpConfirm = function () { env.confirms++; return Promise.resolve(confirmAnswer); };
|
|
w.erpAlert = function (m) { env.alerts.push(m); };
|
|
w.alert = function (m) { env.alerts.push(m); };
|
|
// 8초 이상 타이머(실시간 새로고침)는 붙잡아 두고 테스트가 직접 돌린다.
|
|
const realSetTimeout = w.setTimeout.bind(w);
|
|
const slow = [];
|
|
w.setTimeout = function (fn, ms) {
|
|
if (ms >= 8000) { slow.push({ fn: fn, ms: ms }); return 999000 + slow.length; }
|
|
return realSetTimeout(fn, ms);
|
|
};
|
|
const env = {
|
|
w: w, d: d, calls: [], routes: [], slow: slow, confirms: 0, alerts: [],
|
|
setConfirm: function (v) { confirmAnswer = v; },
|
|
route: function (method, re, fn) { env.routes.unshift({ method: method, re: re, fn: fn }); },
|
|
runSlow: async function () { const t = slow.shift(); if (t) { t.fn(); await settle(); } return t; },
|
|
};
|
|
w.fetch = async function (url, opts) {
|
|
const method = (opts && opts.method) || "GET";
|
|
let body = opts && opts.body;
|
|
if (typeof body === "string") { try { body = JSON.parse(body); } catch (_) {} }
|
|
env.calls.push({ method: method, url: String(url), body: body });
|
|
if (process.env.PJ_TEST_TRACE && method === "PUT") console.log(" TRACE PUT", url, new Error().stack.split("\n").slice(2, 7).join(" | "));
|
|
for (const r of env.routes) {
|
|
if (r.method === method && r.re.test(String(url))) {
|
|
const out = await r.fn(String(url), body);
|
|
if (out === "NETWORK") throw new TypeError("Failed to fetch");
|
|
const status = out.status || 200;
|
|
return { ok: status < 400, status: status, statusText: "x", json: async function () { return out.body; } };
|
|
}
|
|
}
|
|
return { ok: true, status: 200, statusText: "OK", json: async function () { return {}; } };
|
|
};
|
|
return env;
|
|
}
|
|
|
|
function settle(n) {
|
|
return new Promise(function (r) { let i = 0; (function spin() { if (i++ >= (n || 30)) return r(); setImmediate(spin); })(); });
|
|
}
|
|
|
|
function detail(id, title, extra) {
|
|
return Object.assign({ id: id, title: title, project_id: 1, stage_id: 11, description: "", priority: "normal",
|
|
assignee_email: "", subtasks: [], links: [], followers: [], access: "full", completed_at: null }, extra || {});
|
|
}
|
|
|
|
function baseRoutes(env) {
|
|
env.route("GET", /\/project\/api\/tasks\/\d+\/attachments/, function () { return { body: { attachments: [] } }; });
|
|
env.route("GET", /\/project\/api\/tasks\/\d+\/comments/, function () { return { body: { comments: [], events: [], features: {} } }; });
|
|
env.route("GET", /\/project\/api\/projects\/\d+\/members/, function () { return { body: { members: [{ user_email: "me@test.local" }] } }; });
|
|
env.route("GET", /\/project\/api\/projects$/, function () { return { body: { projects: [] } }; });
|
|
env.route("GET", /\/project\/api\/all-users/, function () { return { body: { users: [] } }; });
|
|
env.route("GET", /\/project\/api\/live-version/, function () { return { body: { ts: "v1" } }; });
|
|
env.route("GET", /\/project\/api\/tasks\/101$/, function () { return { body: { task: detail(101, "작업 A") } }; });
|
|
env.route("GET", /\/project\/api\/tasks\/102$/, function () { return { body: { task: detail(102, "작업 B") } }; });
|
|
}
|
|
|
|
async function boot(env) {
|
|
// jsdom 이 문서를 다 읽고 DOMContentLoaded 를 보낸 뒤에 넣는다 — 먼저 넣으면 초기화가 두 번 돈다.
|
|
if (env.d.readyState === "loading") {
|
|
await new Promise(function (r) { env.d.addEventListener("DOMContentLoaded", r); });
|
|
}
|
|
// jsdom 의 <select>·일부 입력은 내부 Proxy 라 value 를 재정의(enhance*)하면 쓰기가 막힌다(실제 브라우저는
|
|
// 문제없음, 기존 코드 그대로). 테스트에서는 버튼 보강을 건너뛰고 원래 입력칸으로 시험한다.
|
|
env.d.querySelectorAll("select").forEach(function (s) { s.dataset.pjEnhanced = "1"; });
|
|
env.d.querySelectorAll("input[type=date]").forEach(function (i) { i.dataset.pjDate = "1"; });
|
|
env.w.eval(JS);
|
|
env.d.dispatchEvent(new env.w.Event("DOMContentLoaded"));
|
|
await settle();
|
|
return env.w.__pjProject;
|
|
}
|
|
|
|
function taskOf(P, id) { return P.state().tasks.find(function (t) { return t.id === id && t.context_project_id === 1; }); }
|
|
function subsText(d) { // 하위 작업 제목은 입력칸 값이다
|
|
return Array.from(d.querySelectorAll("#pj-subtask-list .pj-subtask-title")).map(function (i) { return i.value; }).join("|") ||
|
|
d.getElementById("pj-subtask-list").textContent;
|
|
}
|
|
function wait(ms) { return new Promise(function (r) { setTimeout(r, ms); }); } // 창 닫기 애니메이션(0.32초) 대기
|
|
function titleVal(d) { return d.getElementById("pj-t-title").value; }
|
|
|
|
(async function () {
|
|
// ── [05] 한국시간 기준 오늘 ─────────────────────────────
|
|
{
|
|
const env = makeEnv(); baseRoutes(env); await boot(env);
|
|
const H = env.w.__pjHelpers;
|
|
const kst = function (y, m, d, hh, mm) { return Date.UTC(y, m - 1, d, hh - 9, mm); };
|
|
check("[05] KST 00:00 → 그날", H.kstTodayIso(kst(2026, 9, 30, 0, 0)) === "2026-09-30");
|
|
check("[05] KST 08:59(UTC 전날) → 그날", H.kstTodayIso(kst(2026, 9, 30, 8, 59)) === "2026-09-30");
|
|
check("[05] KST 09:00 → 그날", H.kstTodayIso(kst(2026, 9, 30, 9, 0)) === "2026-09-30");
|
|
check("[05] KST 23:59 → 그날", H.kstTodayIso(kst(2026, 9, 30, 23, 59)) === "2026-09-30");
|
|
const realNow = env.w.Date.now;
|
|
env.w.Date.now = function () { return kst(2026, 9, 30, 8, 30); };
|
|
const y = H.dueInfo("2026-09-29", false), t = H.dueInfo("2026-09-30", false);
|
|
check("[05] 해외 시간대(" + (process.env.TZ || "기본") + ")·한국 오전에도 전날 마감=지남", y.cls === "is-overdue" && y.text === "어제", y);
|
|
check("[05] 오늘 마감은 지남이 아님", t.cls === "is-soon" && t.text === "오늘", t);
|
|
env.w.Date.now = realNow;
|
|
}
|
|
|
|
// ── [09] A→B 전환 중 늦은 A 응답이 B 를 덮지 않는다 ───────────
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
const dA = deferred();
|
|
env.route("GET", /\/project\/api\/tasks\/101$/, function () { return dA.promise; });
|
|
env.route("GET", /\/project\/api\/tasks\/102$/, function () { return { body: { task: detail(102, "작업 B", { subtasks: [{ id: 902, title: "B-sub", project_id: 1 }] }) } }; });
|
|
const P = await boot(env); const d = env.d;
|
|
await P.openTaskModal(taskOf(P, 101));
|
|
await P.openTaskModal(taskOf(P, 102));
|
|
await settle();
|
|
dA.resolve({ body: { task: detail(101, "작업 A", { subtasks: [{ id: 901, title: "A-sub", project_id: 1 }] }) } });
|
|
await settle();
|
|
check("[09] 늦은 A 상세가 B 의 하위 작업 목록을 덮지 않음", subsText(d).includes("B-sub") && !subsText(d).includes("A-sub"), subsText(d));
|
|
env.route("POST", /\/project\/api\/projects\/1\/tasks$/, function (u, b) { return { status: 201, body: { task: detail(903, b.title, { parent_task_id: b.parent_task_id }) } }; });
|
|
d.getElementById("pj-subtask-input").value = "새 하위";
|
|
d.getElementById("pj-subtask-add").click();
|
|
await settle();
|
|
const post = env.calls.filter(function (c) { return c.method === "POST" && /projects\/1\/tasks$/.test(c.url); }).pop();
|
|
check("[09] B 화면에서 추가한 하위 작업은 B 에 붙음", post && post.body.parent_task_id === 102, post && post.body);
|
|
}
|
|
// A→B→A — 같은 작업을 다시 열어도 이전 요청은 버린다
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
const dOld = deferred(); let n = 0;
|
|
env.route("GET", /\/project\/api\/tasks\/101$/, function () {
|
|
n++;
|
|
if (n === 1) return dOld.promise;
|
|
return { body: { task: detail(101, "작업 A", { subtasks: [{ id: 911, title: "A-new", project_id: 1 }] }) } };
|
|
});
|
|
const P = await boot(env); const d = env.d;
|
|
await P.openTaskModal(taskOf(P, 101));
|
|
await P.openTaskModal(taskOf(P, 102));
|
|
await P.openTaskModal(taskOf(P, 101));
|
|
await settle();
|
|
dOld.resolve({ body: { task: detail(101, "작업 A", { subtasks: [{ id: 910, title: "A-old", project_id: 1 }] }) } });
|
|
await settle();
|
|
check("[09] A→B→A 에서 첫 A 의 늦은 응답은 버림", subsText(d).includes("A-new") && !subsText(d).includes("A-old"), subsText(d));
|
|
}
|
|
// 이미지 업로드 중 A→B 전환 — 업로드가 끝나 A 설명에 들어가고 저장된 뒤에 B 가 열린다
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
const up = deferred();
|
|
env.route("POST", /\/project\/api\/tasks\/101\/attachments$/, function () { return up.promise; });
|
|
env.route("PUT", /\/project\/api\/tasks\/101$/, function (u, b) { return { body: { task: Object.assign(detail(101, "작업 A"), b) } }; });
|
|
const P = await boot(env); const d = env.d;
|
|
await P.openTaskModal(taskOf(P, 101));
|
|
await settle();
|
|
const box = d.getElementById("pj-t-desc");
|
|
const file = new env.w.File(["x"], "a.png", { type: "image/png" });
|
|
const ev = new env.w.Event("paste", { bubbles: true, cancelable: true });
|
|
Object.defineProperty(ev, "clipboardData", { value: { items: [{ type: "image/png", getAsFile: function () { return file; } }], getData: function () { return ""; } } });
|
|
box.dispatchEvent(ev);
|
|
await settle();
|
|
const switching = P.openTaskModal(taskOf(P, 102));
|
|
await settle();
|
|
check("[09] 업로드 중에는 B 로 넘어가지 않고 기다림", d.getElementById("pj-t-id").value === "101");
|
|
up.resolve({ status: 201, body: { attachment: { id: 55 } } });
|
|
await switching; await settle();
|
|
const put = env.calls.filter(function (c) { return c.method === "PUT" && /tasks\/101$/.test(c.url) && c.body.description; }).pop();
|
|
check("[09] 업로드된 이미지는 A 설명에 넣어 A 에 저장", !!put && put.body.description.includes("/attachments/55/inline"), put && put.body);
|
|
check("[09] 그 다음 B 가 열리고 B 설명엔 이미지 없음", d.getElementById("pj-t-id").value === "102" && !box.innerHTML.includes("/attachments/55/"));
|
|
}
|
|
|
|
// ── [10] 저장 실패 후 닫기 — 유실 없이 재시도/버리기 선택 ─────────
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
let putStatus = 500; const puts = [];
|
|
env.route("PUT", /\/project\/api\/tasks\/101$/, function (u, b) {
|
|
puts.push(b);
|
|
return putStatus >= 400 ? { status: putStatus, body: { detail: "서버 오류" } } : { body: { task: Object.assign(detail(101, "작업 A"), b) } };
|
|
});
|
|
const P = await boot(env); const d = env.d; const modal = d.getElementById("pj-modal-task");
|
|
await P.openTaskModal(taskOf(P, 101)); await settle();
|
|
const ta = d.getElementById("pj-t-title");
|
|
ta.value = "작업 A2"; ta.dispatchEvent(new env.w.Event("blur")); await settle();
|
|
check("[10] 실패한 칸 기록 + '저장 실패 · 다시 시도' 표시", P.state().failed.includes("title") && d.getElementById("pj-autosave-state").textContent.includes("저장 실패"), P.state().failed);
|
|
check("[10] 저장 안 된 상태면 페이지 이탈 경고 대상", P.state().unsaved === true);
|
|
env.setConfirm(false); // 계속 편집
|
|
await P.attemptClose(); await settle();
|
|
check("[10] 닫기 때 재시도해도 실패 → 묻고, '계속 편집'이면 창·입력 유지", !modal.hidden && titleVal(d) === "작업 A2" && env.confirms === 1);
|
|
putStatus = 200;
|
|
await P.attemptClose(); await settle(); await wait(400);
|
|
check("[10] 다시 닫기 → 재시도 성공 후 닫힘", modal.hidden && puts[puts.length - 1].title === "작업 A2", { hidden: modal.hidden, last: puts[puts.length - 1] });
|
|
check("[10] 저장된 상태에서는 이탈 경고 없음", P.state().unsaved === false);
|
|
}
|
|
{
|
|
// 403·지연 + Escape + 버리기, A 실패가 B 상태를 오염시키지 않음
|
|
const env = makeEnv(); baseRoutes(env);
|
|
const dPut = deferred();
|
|
env.route("PUT", /\/project\/api\/tasks\/101$/, function () { return dPut.promise; });
|
|
const P = await boot(env); const d = env.d; const modal = d.getElementById("pj-modal-task");
|
|
await P.openTaskModal(taskOf(P, 101)); await settle();
|
|
d.getElementById("pj-t-priority").value = "high";
|
|
d.getElementById("pj-t-priority").dispatchEvent(new env.w.Event("change")); await settle();
|
|
d.dispatchEvent(new env.w.KeyboardEvent("keydown", { key: "Escape", bubbles: true })); await settle();
|
|
check("[10] 저장 중 Esc → 저장이 끝날 때까지 창 유지", !modal.hidden);
|
|
env.setConfirm(true); // 버리고 넘어가기
|
|
const opening = P.openTaskModal(taskOf(P, 102)); await settle();
|
|
dPut.resolve({ status: 403, body: { detail: "권한 없음" } });
|
|
await opening; await settle();
|
|
check("[10] 403 실패 → 버리기 선택 후 B 열림", d.getElementById("pj-t-id").value === "102" && !modal.hidden);
|
|
check("[10] A 의 실패가 B 상태를 오염시키지 않음", P.state().failed.length === 0 && d.getElementById("pj-autosave-state").textContent === "", P.state().failed);
|
|
}
|
|
{
|
|
// 네트워크 단절 → 계속 편집, 복구 후 표시줄 클릭으로 재시도
|
|
const env = makeEnv(); baseRoutes(env);
|
|
let net = false; const puts = [];
|
|
env.route("PUT", /\/project\/api\/tasks\/101$/, function (u, b) { puts.push(b); return net ? { body: { task: Object.assign(detail(101, "작업 A"), b) } } : "NETWORK"; });
|
|
const P = await boot(env); const d = env.d;
|
|
await P.openTaskModal(taskOf(P, 101)); await settle();
|
|
d.getElementById("pj-t-due").value = "2026-10-10";
|
|
d.getElementById("pj-t-due").dispatchEvent(new env.w.Event("change")); await settle();
|
|
check("[10] 네트워크 오류 → 마감일 칸 실패로 남음", P.state().failed.includes("due"));
|
|
net = true;
|
|
const stEl = d.getElementById("pj-autosave-state");
|
|
const stBefore = stEl.dataset.state;
|
|
stEl.click(); await settle();
|
|
check("[10] '다시 시도' → 같은 값으로 재전송 성공", P.state().failed.length === 0 && puts[puts.length - 1].due_date === "2026-10-10",
|
|
{ stBefore: stBefore, failed: P.state().failed, puts: puts });
|
|
}
|
|
|
|
// ── [16] 한글 조합 Enter ─────────────────────────────────
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
const dPost = deferred();
|
|
env.route("POST", /\/project\/api\/tasks\/101\/comments$/, function () { return dPost.promise; });
|
|
const P = await boot(env); const d = env.d;
|
|
await P.openTaskModal(taskOf(P, 101)); await settle();
|
|
const inp = d.getElementById("pj-comment-input");
|
|
inp.value = "안녕하세요";
|
|
inp.dispatchEvent(new env.w.KeyboardEvent("keydown", { key: "Enter", isComposing: true, bubbles: true, cancelable: true }));
|
|
const ev229 = new env.w.KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true });
|
|
Object.defineProperty(ev229, "keyCode", { value: 229 });
|
|
inp.dispatchEvent(ev229);
|
|
await settle();
|
|
const posts = function () { return env.calls.filter(function (c) { return c.method === "POST" && /101\/comments$/.test(c.url); }); };
|
|
check("[16] 조합 중 Enter(isComposing·229)는 댓글 전송 안 함", posts().length === 0);
|
|
inp.dispatchEvent(new env.w.KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
|
|
inp.dispatchEvent(new env.w.KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
|
|
await settle();
|
|
check("[16] 조합이 끝난 Enter 연타 → 한 번만 전송", posts().length === 1 && posts()[0].body.client_token, posts().length);
|
|
dPost.resolve({ status: 201, body: { comment: { id: 1, body: "안녕하세요" }, mention_skipped: [] } }); await settle();
|
|
const sub = d.getElementById("pj-subtask-input");
|
|
await settle(); sub.value = "하위";
|
|
sub.dispatchEvent(new env.w.KeyboardEvent("keydown", { key: "Enter", isComposing: true, bubbles: true, cancelable: true })); await settle();
|
|
check("[16] 하위 작업 칸도 조합 중 Enter 는 추가 안 함", !env.calls.some(function (c) { return c.method === "POST" && /projects\/1\/tasks$/.test(c.url); }));
|
|
const cm = d.getElementById("pj-cm-input");
|
|
env.w.__pjChat.open(101); await settle();
|
|
cm.value = "채팅";
|
|
cm.dispatchEvent(new env.w.KeyboardEvent("keydown", { key: "Enter", isComposing: true, bubbles: true, cancelable: true })); await settle();
|
|
check("[16] 댓글 대화창도 조합 중 Enter 는 전송 안 함", posts().length === 1);
|
|
}
|
|
|
|
// ── [03] 파일 댓글 — 실패 파일 표시·유지, 성공 시 비움 ───────────
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
let mode = "fail";
|
|
env.route("POST", /\/project\/api\/tasks\/101\/comments\/files$/, function () {
|
|
if (mode === "fail") return { status: 400, body: { detail: { message: "보낼 수 없는 파일이 있어 댓글을 등록하지 않았습니다.", failed: [{ index: "1", name: "b.png", reason: "빈 파일" }] } } };
|
|
if (mode === "net") return "NETWORK";
|
|
return { status: 201, body: { comment: { id: 5, body: "" }, attachments: [], mention_skipped: [] } };
|
|
});
|
|
const P = await boot(env); const d = env.d;
|
|
env.w.__pjChat.open(101); await settle();
|
|
const cm = d.getElementById("pj-cm-input");
|
|
function pasteImg(name, content) {
|
|
const f = new env.w.File(content, name, { type: "image/png" });
|
|
const ev = new env.w.Event("paste", { bubbles: true, cancelable: true });
|
|
Object.defineProperty(ev, "clipboardData", { value: { items: [{ type: "image/png", getAsFile: function () { return f; } }], getData: function () { return ""; } } });
|
|
cm.dispatchEvent(ev);
|
|
}
|
|
pasteImg("a.png", ["aaa"]); pasteImg("b.png", []);
|
|
await settle();
|
|
d.getElementById("pj-cm-send").click(); await settle();
|
|
const chips = function () { return Array.from(d.querySelectorAll("#pj-cm-pending .pj-chat-pending-chip")); };
|
|
check("[03] 서버가 거절한 파일만 빨간 표시, 두 파일 모두 남음", chips().length === 2 && chips()[1].classList.contains("is-failed") && !chips()[0].classList.contains("is-failed"));
|
|
const sent = env.calls.filter(function (c) { return /comments\/files$/.test(c.url); });
|
|
check("[03] 파일은 본문과 한 요청으로(빈 댓글을 먼저 만들지 않음)", sent.length === 1 && !env.calls.some(function (c) { return c.method === "POST" && /101\/comments$/.test(c.url); }));
|
|
mode = "net";
|
|
d.getElementById("pj-cm-send").click(); await settle();
|
|
check("[03] 네트워크 오류 → 파일·입력 유지", chips().length === 2);
|
|
const tok1 = env.calls.filter(function (c) { return /comments\/files$/.test(c.url); }).pop().body.get("client_token");
|
|
mode = "ok";
|
|
d.getElementById("pj-cm-send").click(); await settle();
|
|
const tok2 = env.calls.filter(function (c) { return /comments\/files$/.test(c.url); }).pop().body.get("client_token");
|
|
check("[03] 응답을 못 받은 재전송은 같은 client_token(서버가 한 번만 만듦)", tok1 && tok1 === tok2);
|
|
check("[03] 성공하면 대기 파일 비움", chips().length === 0);
|
|
}
|
|
|
|
// ── [14] 작업 창 댓글에 파일 표시 ─────────────────────────
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
env.route("GET", /\/project\/api\/tasks\/101\/comments/, function () {
|
|
return { body: { comments: [{ id: 7, body: "", author_email: "me@test.local", created_at: "2026-09-30T10:00" },
|
|
{ id: 8, body: "답글", parent_id: 7, author_email: "me@test.local", created_at: "2026-09-30T10:01" }],
|
|
events: [], features: { replies: true } } };
|
|
});
|
|
env.route("GET", /\/project\/api\/tasks\/101\/attachments/, function () {
|
|
return { body: { attachments: [{ id: 70, comment_id: 7, filename: "<b>x</b>.pdf", content_type: "application/pdf", size_bytes: 10 },
|
|
{ id: 71, comment_id: 8, filename: "r.png", content_type: "image/png", size_bytes: 10 },
|
|
{ id: 72, comment_id: null, filename: "plain.txt", content_type: "text/plain", size_bytes: 10 }] } };
|
|
});
|
|
const P = await boot(env); const d = env.d;
|
|
await P.openTaskModal(taskOf(P, 101)); await settle();
|
|
const list = d.getElementById("pj-comment-list");
|
|
check("[14] 파일만 있는 댓글에 파일 표시", list.querySelector('a[href="/project/api/attachments/70/download"]') !== null);
|
|
check("[14] 파일명은 이스케이프(태그로 해석 안 됨)", !list.querySelector(".pj-comment-atts b") && list.textContent.includes("<b>x</b>.pdf"));
|
|
check("[14] 답글의 파일은 답글에", !!list.querySelector(".pj-comment-item.is-reply img[src='/project/api/attachments/71/inline']"));
|
|
check("[14] 댓글 아닌 첨부는 댓글에 안 섞임", !list.innerHTML.includes("attachments/72/"));
|
|
check("[14] 첨부 목록에 '댓글' 표시", d.getElementById("pj-attach-list").textContent.includes("댓글"));
|
|
}
|
|
|
|
// ── [12] 연결된 작업은 읽기 전용 ─────────────────────────
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
env.route("GET", /\/project\/api\/tasks\/301$/, function () {
|
|
return { body: { task: detail(301, "연결된 작업", { project_id: 3, project_name: "비밀", access: "read", followers: null, subtasks: [{ id: 3011, title: "읽기 하위", project_id: 3 }] }) } };
|
|
});
|
|
const P = await boot(env); const d = env.d;
|
|
const linked = P.state().tasks.find(function (t) { return t.id === 301; });
|
|
await P.openTaskModal(linked); await settle();
|
|
check("[12] 제목·담당자 편집 불가", d.getElementById("pj-t-title").readOnly && d.getElementById("pj-t-assignee").disabled);
|
|
check("[12] 읽기 전용 안내 표시", !d.getElementById("pj-t-readonly").hidden);
|
|
check("[12] 댓글 입력·완료·삭제 숨김", d.getElementById("pj-comment-dock").hidden && d.getElementById("pj-toggle-complete").hidden && d.getElementById("pj-delete-task").hidden);
|
|
check("[12] 하위 작업 추가 칸 숨김, 목록은 보임", d.querySelector(".pj-subtask-form").hidden && subsText(d).includes("읽기 하위"));
|
|
d.getElementById("pj-t-title").value = "바꿈";
|
|
d.getElementById("pj-t-title").dispatchEvent(new env.w.Event("blur")); await settle();
|
|
const puts12 = env.calls.filter(function (c) { return c.method === "PUT"; });
|
|
check("[12] 읽기 전용이면 저장 요청을 보내지 않음(뒤늦은 403 없음)", puts12.length === 0, puts12);
|
|
}
|
|
|
|
// ── [13][01] 실시간 동기화 — 실패 후 같은 버전 재시도, 전체 범위 반영, 권한 회수 ──
|
|
{
|
|
const env = makeEnv(); baseRoutes(env);
|
|
let ver = "v1", snapMode = "fail";
|
|
const dSnap = deferred();
|
|
env.route("GET", /\/project\/api\/live-version/, function () { return { body: { ts: ver } }; });
|
|
env.route("GET", /\/snapshot\?scope=all/, function () {
|
|
if (snapMode === "fail") return { status: 500, body: { detail: "잠시 오류" } };
|
|
if (snapMode === "slow") return dSnap.promise;
|
|
if (snapMode === "gone") return { status: 403, body: { detail: "권한 없음" } };
|
|
return { body: { scope: "all", project: { id: 1, name: "P1" },
|
|
projects: [{ id: 1, name: "P1", color: "#4573d2", status: "active" }],
|
|
tasks: [{ id: 101, title: "작업 A(새 제목)", project_id: 1, context_project_id: 1, stage_id: 11, stage_name: "할 일" },
|
|
{ id: 150, title: "다른 사람이 만든 작업", project_id: 1, context_project_id: 1, stage_id: 13, stage_name: "검토" }],
|
|
stages_by_project: { "1": [{ id: 11, project_id: 1, name: "할 일" }, { id: 13, project_id: 1, name: "검토" }] },
|
|
stages: [{ id: 11, project_id: 1, name: "할 일" }, { id: 13, project_id: 1, name: "검토" }],
|
|
members: [{ user_email: "me@test.local" }] } };
|
|
});
|
|
const P = await boot(env); const d = env.d;
|
|
const st = function () { return env.w.pjLiveRefreshState(); };
|
|
const poll = function () { return env.w.__pjLivePoll(); };
|
|
const nextDelay = function () { const t = env.slow.filter(function (s) { return s.fn === env.w.__pjLivePoll; }).pop(); return t && t.ms; };
|
|
check("[13] 처음 본 버전 = 반영된 버전", st().observed === "v1" && st().applied === "v1");
|
|
ver = "v2";
|
|
await poll(); await settle();
|
|
check("[13] 스냅샷 실패 → 반영 버전은 그대로(v1), 실패 1", st().observed === "v2" && st().applied === "v1" && st().failures === 1, st());
|
|
check("[13] 실패 뒤 다음 확인은 늘어난 간격(16초)", nextDelay() === 16000, nextDelay());
|
|
snapMode = "ok";
|
|
await poll(); await settle();
|
|
check("[13] 같은 버전 다음 요청 성공 → v2 반영", st().applied === "v2" && st().failures === 0, st());
|
|
const s = P.state();
|
|
check("[01] 다른 프로젝트(P2) 작업·사이드바 항목 제거(권한 회수)", !s.tasks.some(function (t) { return t.project_id === 2; }) && !s.projectsMeta.some(function (p) { return p.id === 2; }));
|
|
check("[01] 새 작업·새 섹션 반영", s.tasks.some(function (t) { return t.id === 150; }) && s.boardStages.includes("검토"));
|
|
check("[01] 제목 변경 반영", s.tasks.find(function (t) { return t.id === 101; }).title === "작업 A(새 제목)");
|
|
// 동기화 중 버전이 또 바뀌면 끝난 뒤 한 번 더
|
|
snapMode = "slow"; ver = "v3";
|
|
const firstPoll = poll();
|
|
await settle();
|
|
ver = "v4";
|
|
const snapsBefore = env.calls.filter(function (c) { return /snapshot/.test(c.url); }).length;
|
|
await poll(); // 동기화가 도는 중에 또 확인 — 겹쳐 받지 않는다
|
|
const snapsDuring = env.calls.filter(function (c) { return /snapshot/.test(c.url); }).length;
|
|
dSnap.resolve({ body: { tasks: [], projects: [{ id: 1, name: "P1", status: "active" }], stages_by_project: {}, stages: [], members: [] } });
|
|
await firstPoll; await settle();
|
|
check("[13] 동기화 중 새 버전(v4) — 겹쳐 돌지 않고 반영 버전은 v3", st().applied === "v3" && st().observed === "v4" && snapsDuring === snapsBefore, { st: st(), snapsBefore: snapsBefore, snapsDuring: snapsDuring });
|
|
snapMode = "ok";
|
|
await poll(); await settle();
|
|
check("[13] 다음 주기에 v4 반영", st().applied === "v4", st());
|
|
snapMode = "gone"; ver = "v5";
|
|
await poll(); await settle();
|
|
check("[01][02] 이 프로젝트 권한 회수 → 작업 비우고 안내", !!d.querySelector(".pj-access-lost") && P.state().tasks.length === 0);
|
|
}
|
|
|
|
clearTimeout(WATCHDOG);
|
|
console.log(fails.length ? "\nFAILED: " + fails.join(", ") : "\nALL PASS");
|
|
process.exit(fails.length ? 1 : 0);
|
|
})().catch(function (e) { console.error(e); process.exit(1); });
|