Files
dbx-main/tests/js/comment_image_viewer.browser.test.js
king 808361b62c fix: 실적 표 칸 풍선 도움말 제거 · 댓글 사진 창 기본 맞춤(창에 꽉 차게)
- [실적] 매출 실적·광고비 표 몸통 칸(입력 칸·날짜 칸·광고비 줄)의 title 풍선 도움말 제거(저장 뒤에도 안 붙임), 열 머리글은 그대로
- [프로젝트] 댓글 사진 이미지 창: 처음 = 맞춤, 창 크기 = 사진 비율이라 가장자리 검은 공간 없이 꽉 참,
  막대는 사진 위에 뜸, 창 크기를 바꿔도 맞춤 상태면 다시 맞춤(확대·끌기 뒤엔 그대로)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 12:49:40 +09:00

140 lines
10 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 실제 브라우저 — 업무 창 댓글에 붙은 사진을 누르면 내려받지 않고 이미지 창(별도 브라우저 창)이 열린다(2026-10-22).
// 처음 = 맞춤으로 창에 꽉 참(가장자리 검은 공간 없음, 창 크기를 바꿔도 맞춤 유지), 끌어서 이동, 휠 확대·축소, [원본 보기] = 100%,
// [다운로드] = 첨부 다운로드 주소. Ctrl+클릭은 예전처럼 링크. (2026-10-22 — 처음 100% 에서 맞춤으로 바꿈)
// python tests/js/render_project.py
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/comment_image_viewer.browser.test.js
const assert = require("node:assert/strict");
const fs = require("node:fs"), path = require("node:path"), http = require("node:http"), zlib = require("node:zlib");
const { chromium } = require("playwright");
const ROOT = path.resolve(__dirname, "../.."), OUT = path.join(__dirname, ".out"), STATIC = path.join(ROOT, "app/static");
// 1600×1000 PNG(단색 + 가로 줄무늬) — 창보다 큰 사진
function png(w, h) {
const crcTable = Array.from({ length: 256 }, (_, n) => { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; return c >>> 0; });
const crc = buf => { let c = 0xffffffff; for (const b of buf) c = crcTable[(c ^ b) & 0xff] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0; };
const chunk = (type, data) => { const len = Buffer.alloc(4); len.writeUInt32BE(data.length); const td = Buffer.concat([Buffer.from(type), data]);
const c = Buffer.alloc(4); c.writeUInt32BE(crc(td)); return Buffer.concat([len, td, c]); };
const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4); ihdr[8] = 8; ihdr[9] = 2;
const rows = [];
for (let y = 0; y < h; y++) { const r = Buffer.alloc(1 + w * 3); for (let x = 0; x < w; x++) { const v = (y >> 5) % 2 ? 90 : 200; r[1 + x * 3] = v; r[2 + x * 3] = 150; r[3 + x * 3] = 255 - v; } rows.push(r); }
return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", ihdr), chunk("IDAT", zlib.deflateSync(Buffer.concat(rows))), chunk("IEND", Buffer.alloc(0))]);
}
const PHOTO = png(1600, 1000);
const detail = (id) => ({ id, title: "작업 " + id, project_id: 1, stage_id: 11, description: "", priority: "normal",
assignee_email: "", subtasks: [], links: [], followers: [], access: "full", completed_at: null, created_by: "me@test.local" });
const downloads = [];
const server = http.createServer(async (req, res) => {
const url = new URL(req.url, "http://localhost");
const json = (code, body) => { res.statusCode = code; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify(body)); };
if (url.pathname === "/project/p/1") { res.setHeader("Content-Type", "text/html; charset=utf-8"); res.end(fs.readFileSync(path.join(OUT, "project_render.html"))); return; }
if (url.pathname === "/project/api/attachments/7/inline") { res.setHeader("Content-Type", "image/png"); res.end(PHOTO); return; }
if (url.pathname === "/project/api/attachments/7/download") {
downloads.push(url.pathname);
res.setHeader("Content-Type", "image/png"); res.setHeader("Content-Disposition", 'attachment; filename="photo.png"'); res.end(PHOTO); return;
}
if (url.pathname.startsWith("/project/api/")) {
const task = /^\/project\/api\/tasks\/(\d+)$/.exec(url.pathname);
if (task) return json(200, { task: detail(+task[1]) });
if (url.pathname.endsWith("/comments")) return json(200, { comments: [{ id: 1, task_id: 101, author_email: "me@test.local", author_name: "Me",
body: "사진 확인 부탁", created_at: "2026-10-21T16:10:00+09:00", parent_id: null, reactions: [] }], events: [], features: {} });
if (url.pathname.endsWith("/attachments")) return json(200, { attachments: [{ id: 7, task_id: 101, comment_id: 1, filename: "photo.png",
content_type: "image/png", size_bytes: PHOTO.length, uploaded_by: "me@test.local", created_at: "2026-10-21T16:10:00+09:00" }] });
if (url.pathname.endsWith("/members")) return json(200, { members: [{ user_email: "me@test.local" }] });
if (url.pathname.endsWith("/live-version")) return json(200, { ts: "v1" });
if (url.pathname.endsWith("/alerts")) return json(200, { me: "me@test.local", latest_id: 0, alerts: [] });
return json(200, {});
}
if (url.pathname.startsWith("/static/")) {
const file = path.join(STATIC, decodeURIComponent(url.pathname.slice("/static/".length)));
if (file.startsWith(STATIC) && fs.existsSync(file)) {
res.setHeader("Content-Type", file.endsWith(".js") ? "text/javascript" : file.endsWith(".css") ? "text/css" : "application/octet-stream");
res.end(fs.readFileSync(file)); return;
}
}
res.statusCode = 404; res.end("");
});
(async function () {
await new Promise(r => server.listen(0, "127.0.0.1", r));
const base = "http://127.0.0.1:" + server.address().port;
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
const ctx = await browser.newContext({ viewport: { width: 1600, height: 1000 }, acceptDownloads: true });
const page = await ctx.newPage();
const errors = [];
page.on("pageerror", e => errors.push(e.message));
const pass = [];
const ok = (name, cond, extra) => { assert.ok(cond, name + (extra === undefined ? "" : " → " + JSON.stringify(extra))); pass.push(name); console.log("PASS " + name); };
try {
await page.goto(base + "/project/p/1?task=101");
const thumb = page.locator("a.pj-comment-att-img img");
await thumb.waitFor();
await page.waitForFunction(() => { const i = document.querySelector("a.pj-comment-att-img img"); return i && i.naturalWidth > 0; });
ok("댓글 사진 = 누를 수 있는 확대 커서", await thumb.evaluate(i => getComputedStyle(i).cursor) === "zoom-in");
const [pop] = await Promise.all([ctx.waitForEvent("page"), thumb.click()]);
await pop.waitForFunction(() => { const i = document.getElementById("img"); return i && i.naturalWidth > 0 && document.getElementById("pct").textContent; });
ok("누르면 내려받지 않고 이미지 창이 열림", downloads.length === 0 && pop !== page);
const st = () => pop.evaluate(() => ({ pct: document.getElementById("pct").textContent, tr: document.getElementById("img").style.transform,
title: document.title, w: innerWidth, h: innerHeight }));
// 사진이 창을 꽉 채우나 — 사진 사각형이 창의 한 축을 꽉 채우고 다른 축도 비율대로(이 창은 1600×1000 = 사진과 같은 비율이라 둘 다)
const filled = () => pop.evaluate(() => { const r = document.getElementById("img").getBoundingClientRect();
return { l: Math.round(r.left), t: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height), W: innerWidth, H: innerHeight }; });
const s0 = await st();
const f0 = await filled();
ok("처음 = 맞춤, 사진이 창에 꽉 참(가장자리 검은 공간 없음), 창 제목 = 파일 이름",
s0.title === "photo.png" && f0.l === 0 && f0.t === 0 && f0.w === f0.W && f0.h === f0.H, { s0: s0, f0: f0 });
await pop.setViewportSize({ width: 800, height: 500 });
await pop.waitForTimeout(100);
const f1 = await filled();
ok("창 크기를 바꿔도 맞춤 유지(꽉 참)", f1.l === 0 && f1.t === 0 && f1.w === 800 && f1.h === 500 && (await st()).pct === "50%", f1);
await pop.setViewportSize({ width: 1600, height: 1000 });
await pop.waitForTimeout(100);
await pop.click("#one");
const s0b = await st();
const box = await pop.locator("#stage").boundingBox();
await pop.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await pop.mouse.down();
await pop.mouse.move(box.x + box.width / 2 + 150, box.y + box.height / 2 + 80, { steps: 5 });
await pop.mouse.up();
const s1 = await st();
ok("끌면 이미지가 움직임(100% 그대로)", s1.tr !== s0b.tr && s1.pct === "100%", { before: s0b.tr, after: s1.tr });
await pop.mouse.wheel(0, -300);
const s2 = await st();
await pop.mouse.wheel(0, 600);
const s3 = await st();
ok("휠 위 = 확대, 아래 = 축소", parseInt(s2.pct, 10) > 100 && parseInt(s3.pct, 10) < parseInt(s2.pct, 10), [s2.pct, s3.pct]);
await pop.click("#one");
ok("[원본 보기] = 100% 로", (await st()).pct === "100%" && (await pop.locator("#one").textContent()).trim() === "원본 보기");
await pop.click("#fit");
const fz = await filled();
ok("[맞춤] = 다시 창에 꽉 참", fz.l === 0 && fz.t === 0 && fz.w === fz.W && fz.h === fz.H, fz);
await pop.mouse.move(800, 400); // 막대 위가 아니라 사진 위에서 휠
await pop.mouse.wheel(0, -300);
await pop.setViewportSize({ width: 1200, height: 900 });
await pop.waitForTimeout(100);
ok("확대한 뒤엔 창 크기를 바꿔도 맞춤으로 돌아가지 않음", (await st()).pct !== "75%");
await pop.setViewportSize({ width: 1600, height: 1000 });
const dlHref = await pop.getAttribute("#dl", "href");
ok("[다운로드] = 첨부 다운로드 주소", /\/project\/api\/attachments\/7\/download$/.test(dlHref || ""), dlHref);
const [download] = await Promise.all([pop.waitForEvent("download"), pop.click("#dl")]);
ok("[다운로드] 누르면 파일 내려받기", download.suggestedFilename() === "photo.png" && downloads.length === 1, download.suggestedFilename());
// 작은 창(작은 사진) — 막대 단추 글자가 한 줄(예전엔 막대 폭이 창 절반으로 잡혀 "원본/보기"처럼 줄바꿈)
for (const w of [560, 480]) {
await pop.setViewportSize({ width: w, height: 400 });
const bar = await pop.evaluate(() => {
const b = document.getElementById("bar"), r = b.getBoundingClientRect();
const tall = Array.from(b.querySelectorAll("button, a")).filter(el => el.getBoundingClientRect().height > 32).map(el => el.textContent.trim());
return { tall: tall, h: Math.round(r.height), inside: r.left >= 0 && r.right <= innerWidth };
});
ok("창 폭 " + w + "px — 막대 단추 글자 한 줄, 막대가 창 안", bar.tall.length === 0 && bar.h <= 40 && bar.inside, bar);
}
await pop.locator("#bar").screenshot({ path: path.join(OUT, "comment_image_bar.png") });
await pop.screenshot({ path: path.join(OUT, "comment_image_viewer.png") });
await pop.close();
ok("페이지 오류 없음", errors.length === 0, errors);
console.log("\nALL PASS (" + pass.length + ")");
} finally {
await browser.close();
server.close();
}
})().catch(e => { console.error(e); process.exit(1); });