ec8b9787e6
막대가 left:50% 라 폭이 창 절반으로 잡혀 작은 창에서 줄바꿈됐다 — 막대 폭 = 내용 길이(max-content)·한 줄, 이미지 창 최소 폭 480 → 560px. 브라우저 테스트에 480·560px 창 확인 추가. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
8.9 KiB
JavaScript
119 lines
8.9 KiB
JavaScript
// 실제 브라우저 — 업무 창 댓글에 붙은 사진을 누르면 내려받지 않고 이미지 창(별도 브라우저 창)이 열린다(2026-10-22).
|
||
// 처음 100%(창보다 커도), 끌어서 이동, 휠 확대·축소, [원본 보기] = 100% 로, [다운로드] = 첨부 다운로드 주소. Ctrl+클릭은 예전처럼 링크.
|
||
// 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 }));
|
||
const s0 = await st();
|
||
ok("처음 100%(사진 1600×1000 이 창보다 커도), 창 제목 = 파일 이름", s0.pct === "100%" && s0.title === "photo.png" && (s0.w < 1600 || s0.h < 1000), s0);
|
||
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 !== s0.tr && s1.pct === "100%", { before: s0.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");
|
||
ok("[맞춤] = 창에 맞춤(100% 아래)", parseInt((await st()).pct, 10) < 100);
|
||
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); });
|