141 lines
10 KiB
JavaScript
141 lines
10 KiB
JavaScript
// 실제 브라우저에서 주차를 바꿔도 왼쪽 DOM·스크롤·폴더가 유지되고, 저장 실패 시 이동을 멈추는지 확인한다.
|
|
// python tests/js/render_goals.py; NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/goal_nav.browser.test.js
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs"), path = require("node:path"), http = require("node:http");
|
|
const { chromium } = require("playwright");
|
|
const ROOT = path.resolve(__dirname, "../.."), OUT = path.join(__dirname, ".out"), STATIC = path.join(ROOT, "app/static");
|
|
const firstMonday = month => {
|
|
const d = new Date(Date.UTC(2026, month - 1, 1));
|
|
d.setUTCDate(d.getUTCDate() + (8 - d.getUTCDay()) % 7);
|
|
return d.toISOString().slice(0, 10);
|
|
};
|
|
const tree = { years: [{ year: 2026, months: Array.from({ length: 12 }, (_, i) => {
|
|
const month = i + 1, starts = month === 9 ? ["2026-09-21", "2026-09-28"] : [firstMonday(month)];
|
|
return { month, weeks: starts.map(start => ({ start, label: start, href: `/project/goals/2026/meetings/${month}?week=${start}` })) };
|
|
}) }] };
|
|
let navReads = 0, topReads = 0, releaseSave = null, saving = false, failSave = false, holdSave = false;
|
|
let failContent = false, delayWeek = "", liveVersion = "1";
|
|
const contentReads = [], writes = [];
|
|
const server = http.createServer(async (req, res) => {
|
|
const url = new URL(req.url, "http://localhost");
|
|
if (url.pathname === "/project/api/goals/meeting-nav") { navReads++; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify(tree)); return; }
|
|
if (url.pathname.startsWith("/project/api/")) {
|
|
res.setHeader("Content-Type", "application/json");
|
|
if (url.pathname.endsWith("/live-version")) { res.end(JSON.stringify({ ts: liveVersion })); return; }
|
|
if (req.method === "PUT") {
|
|
let raw = ""; for await (const chunk of req) raw += chunk;
|
|
writes.push({ path: url.pathname, body: JSON.parse(raw) });
|
|
if (holdSave) { saving = true; await new Promise(r => { releaseSave = r; }); saving = false; }
|
|
if (failSave) { res.statusCode = 503; res.end(JSON.stringify({ detail: "test save failure" })); return; }
|
|
}
|
|
res.end("{}"); return;
|
|
}
|
|
if (url.pathname.startsWith("/project/goals/")) {
|
|
const month = Number(url.pathname.split("/").pop());
|
|
const week = url.searchParams.get("week") || firstMonday(month);
|
|
const content = url.searchParams.get("content") === "1";
|
|
if (content) contentReads.push(week); else topReads++;
|
|
if (content && week === delayWeek) await new Promise(r => setTimeout(r, 150));
|
|
if (content && failContent) { res.statusCode = 503; res.setHeader("Content-Type", "text/html"); res.end("unavailable"); return; }
|
|
const fixture = /\/meetings\//.test(url.pathname) ? (content ? "meeting_content_admin.html" : "meeting_shell_admin.html") : "goals_shell_admin.html";
|
|
let html = fs.readFileSync(path.join(OUT, fixture), "utf8")
|
|
.replaceAll("2026-09-28", week).replaceAll("2026년 9월", `2026년 ${month}월`).replaceAll('data-month="9"', `data-month="${month}"`);
|
|
res.setHeader("Content-Type", "text/html; charset=utf-8"); res.end(html); return;
|
|
}
|
|
const file = path.resolve(STATIC, "." + decodeURIComponent(url.pathname.slice(7)));
|
|
if (!url.pathname.startsWith("/static/") || !file.startsWith(STATIC + path.sep) || !fs.existsSync(file)) { res.statusCode = 404; res.end(); return; }
|
|
res.setHeader("Content-Type", ({ ".css": "text/css", ".js": "text/javascript", ".woff2": "font/woff2", ".woff": "font/woff" })[path.extname(file)] || "application/octet-stream");
|
|
res.end(fs.readFileSync(file));
|
|
});
|
|
(async () => {
|
|
let browser;
|
|
try {
|
|
await new Promise(r => server.listen(0, "127.0.0.1", r));
|
|
browser = await chromium.launch({ headless: true, executablePath: process.env.PJ_TEST_BROWSER || undefined });
|
|
const page = await browser.newPage({ viewport: { width: 1600, height: 1000 } });
|
|
const errors = []; page.on("pageerror", e => errors.push(e.message));
|
|
const origin = "http://127.0.0.1:" + server.address().port;
|
|
await page.goto(origin + "/project/goals/2026/meetings/9?week=2026-09-28");
|
|
const currentFrame = () => page.frames().find(f => /content=1/.test(f.url()) && f.url() !== "about:blank");
|
|
const ready = async week => {
|
|
await page.waitForFunction(w => {
|
|
const f = document.querySelector(".pj-meeting-panel-frame:not(.is-loading)");
|
|
return f && f.contentDocument.getElementById("pj-meet-pane")?.dataset.week === w;
|
|
}, week);
|
|
};
|
|
await ready("2026-09-28");
|
|
assert.ok((await page.locator(".pj-meeting-panel-host").boundingBox()).height > 500, "실제 ERP 셸에서 오른쪽은 화면 높이를 사용");
|
|
await page.locator(".pj-side-meeting-month").first().waitFor();
|
|
await page.evaluate(() => {
|
|
window.sidebarIdentity = document.querySelector(".pj-side");
|
|
window.monthIdentity = document.querySelectorAll(".pj-side-meeting-month")[8];
|
|
sidebarIdentity.style.height = "300px";
|
|
sidebarIdentity.scrollTop = 200;
|
|
window.savedSideScroll = sidebarIdentity.scrollTop;
|
|
});
|
|
const clickWeek = async week => page.locator(`.pj-side-meeting-week[href$="week=${week}"]`).evaluate(e => e.click());
|
|
await clickWeek("2026-09-21"); await ready("2026-09-21");
|
|
assert.ok(page.url().endsWith("week=2026-09-21"));
|
|
assert.ok(await page.evaluate(() => document.querySelector(".pj-side") === sidebarIdentity && document.querySelectorAll(".pj-side-meeting-month")[8] === monthIdentity && sidebarIdentity.scrollTop === savedSideScroll && monthIdentity.open));
|
|
assert.equal(navReads, 1); assert.equal(topReads, 1);
|
|
assert.equal(await currentFrame().locator(".pj-side").count(), 0);
|
|
await page.goBack(); await ready("2026-09-28");
|
|
await page.goForward(); await ready("2026-09-21");
|
|
// 저장 응답이 늦으면 현재 회의록을 유지하고 완료 후에만 다음 주를 연다.
|
|
holdSave = true;
|
|
await currentFrame().locator("#pj-meet-notes").fill("saved before changing weeks");
|
|
const readsBeforeSave = contentReads.length;
|
|
await clickWeek("2026-09-28");
|
|
await page.waitForFunction(() => document.querySelector(".pj-meeting-panel-frame:not(.is-loading)").contentWindow.document.getElementById("pj-meet-notes").value === "saved before changing weeks");
|
|
await new Promise(r => setTimeout(r, 80));
|
|
assert.ok(saving); assert.equal(contentReads.length, readsBeforeSave);
|
|
holdSave = false; releaseSave(); await ready("2026-09-28");
|
|
assert.ok(writes.some(w => w.path.endsWith("2026-09-21") && w.body.notes === "saved before changing weeks"));
|
|
failSave = true;
|
|
await currentFrame().locator("#pj-meet-notes").fill("keep failed draft");
|
|
await clickWeek("2026-09-21");
|
|
await page.locator(".pj-meeting-panel-status.is-error").waitFor();
|
|
assert.ok(page.url().endsWith("week=2026-09-28"));
|
|
assert.equal(await currentFrame().locator("#pj-meet-notes").inputValue(), "keep failed draft");
|
|
failSave = false; await clickWeek("2026-09-21"); await ready("2026-09-21");
|
|
await page.evaluate(() => { window.currentPanelIdentity = document.querySelector(".pj-meeting-panel-frame:not(.is-loading)"); });
|
|
const reloadingFrame = currentFrame();
|
|
await Promise.all([reloadingFrame.waitForNavigation(), reloadingFrame.evaluate(() => location.reload())]); await ready("2026-09-21");
|
|
assert.ok(await page.evaluate(() => document.querySelector(".pj-meeting-panel-frame:not(.is-loading)") === currentPanelIdentity && currentPanelIdentity.isConnected));
|
|
// 오른쪽 안의 달 링크도 부모 주소만 갱신하고, 왼쪽 목록은 다시 읽지 않는다.
|
|
await currentFrame().locator('a[href="/project/goals/2026/meetings/10"]').click();
|
|
await ready("2026-10-05"); assert.ok(page.url().includes("/meetings/10?week=2026-10-05"));
|
|
failContent = true; await clickWeek("2026-09-21");
|
|
await page.locator(".pj-meeting-panel-status.is-error").waitFor();
|
|
assert.ok(page.url().includes("/meetings/10?week=2026-10-05"));
|
|
assert.equal(await currentFrame().locator("#pj-meet-pane").getAttribute("data-week"), "2026-10-05");
|
|
failContent = false; delayWeek = "2026-09-21";
|
|
await clickWeek("2026-09-21"); await new Promise(r => setTimeout(r, 30)); await clickWeek("2026-10-05");
|
|
await ready("2026-10-05"); await new Promise(r => setTimeout(r, 200));
|
|
assert.ok(page.url().includes("/meetings/10?week=2026-10-05")); delayWeek = "";
|
|
assert.equal(navReads, 1); assert.equal(topReads, 1);
|
|
assert.ok(await page.evaluate(() => document.querySelector(".pj-side") === sidebarIdentity && sidebarIdentity.scrollTop === savedSideScroll));
|
|
await page.locator(".pj-meeting-panel-host").screenshot({ path: path.join(OUT, "meeting-stable-navigation.png") });
|
|
assert.deepEqual(errors, []);
|
|
// 연간 목표에서 회의록으로 갔다가 뒤로 가면 원래 표와 메뉴를 다시 쓰며 새로고침하지 않는다.
|
|
const annual = await browser.newPage({ viewport: { width: 1600, height: 1000 } });
|
|
await annual.addInitScript(() => { window.__PJ_TEST__ = true; });
|
|
await annual.goto(origin + "/project/goals/2026");
|
|
await annual.locator(".pj-side-meeting-month").first().waitFor();
|
|
assert.equal(await annual.locator(".pj-side-goal-year.is-active").count(), 1);
|
|
await annual.evaluate(() => { window.originalTable = document.getElementById("pj-goal-table"); });
|
|
await annual.locator('.pj-side-meeting-week[href$="week=2026-09-28"]').evaluate(e => e.click());
|
|
await annual.waitForFunction(() => !!document.querySelector(".pj-meeting-panel-frame:not(.is-loading)"));
|
|
liveVersion = "2";
|
|
await annual.evaluate(() => window.__pjLivePoll());
|
|
assert.equal(await annual.evaluate(() => window.pjLiveRefreshState().applied), "1", "회의록을 보는 동안 이전 화면 자동 갱신은 보류");
|
|
await annual.goBack();
|
|
await annual.waitForFunction(() => document.getElementById("pj-goal-table") === window.originalTable);
|
|
await annual.evaluate(() => window.__pjLivePoll());
|
|
assert.equal(await annual.evaluate(() => window.pjLiveRefreshState().applied), "2", "원래 화면으로 돌아오면 자동 갱신 재개");
|
|
assert.equal(await annual.locator(".pj-side-goal-year.is-active").count(), 1);
|
|
await annual.close();
|
|
console.log("ALL PASS: stable left DOM/scroll/folders, right-only navigation, back/forward, delayed saves, failed-save draft, inner month links and single sidebar read");
|
|
} finally { if (releaseSave) releaseSave(); if (browser) await browser.close(); await new Promise(r => server.close(r)); }
|
|
})().catch(e => { console.error(e); process.exitCode = 1; });
|