fc95c8bd25
- 스케줄표 머리글: 가운데 정렬, 굵게, 검정, 글자 12% 크게 - 스케줄표 첫 열 = 호스트 쇼핑몰(틱톡·쇼피) 아이콘 - 달력 카드 머리 왼쪽 위 사방 화살표 대신 쇼핑몰 작은 아이콘 - 아이콘 = 말레이시아 배송 로고에서 심볼만 잘라 만든 live-icon-tiktok.png, live-icon-shopee.png Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
245 lines
18 KiB
JavaScript
245 lines
18 KiB
JavaScript
// 라이브 커머스 오른쪽 달력(2026-11-05) — 실제 브라우저(Chromium).
|
||
// python tests/js/render_live.py
|
||
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/live_calendar.browser.test.js
|
||
// 세로 2분할·오른쪽 위 고정·전체 너비, 말레이시아 공휴일·대체휴일 빨강·이름·말풍선, 날짜를 누르면 그 날이 표 맨 왼쪽(마지막 날까지), 다른 달은 그 달 화면으로 가서 맨 왼쪽, 영문 화면은 달력도 영어.
|
||
const fs = require("fs"), path = require("path");
|
||
const { chromium } = require("playwright");
|
||
const ROOT = path.join(__dirname, "..", "..");
|
||
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); }
|
||
}
|
||
|
||
(async function () {
|
||
const exe = process.env.PJ_TEST_BROWSER;
|
||
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
|
||
try {
|
||
const p = await (await browser.newContext({ viewport: { width: 1600, height: 900 } })).newPage();
|
||
const errors = [];
|
||
p.on("pageerror", function (e) { errors.push(String(e)); });
|
||
await p.route("**/*", function (r) {
|
||
const u = new URL(r.request().url());
|
||
if (u.pathname.startsWith("/static/")) {
|
||
const f = path.join(ROOT, "app", u.pathname);
|
||
if (!fs.existsSync(f)) return r.fulfill({ status: 404, body: "" });
|
||
const type = f.endsWith(".css") ? "text/css" : f.endsWith(".js") ? "application/javascript" : f.endsWith(".png") ? "image/png" : "font/woff2";
|
||
return r.fulfill({ status: 200, contentType: type, body: fs.readFileSync(f) });
|
||
}
|
||
if (u.pathname.startsWith("/live/images/")) { // 결과 이미지 미리보기 — 아무 그림이나
|
||
return r.fulfill({ status: 200, contentType: "image/png", body: fs.readFileSync(path.join(ROOT, "app", "static", "dispatch", "courier", "tiktok.png")) });
|
||
}
|
||
const page = u.pathname === "/live/calendar" ? (u.searchParams.get("month") === "2026-12" ? "live_cal_dec.html" : "live_cal_ko.html") : u.pathname.slice(1);
|
||
if (!page.endsWith(".html")) return r.fulfill({ status: 200, contentType: "application/json", body: "{}" });
|
||
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", page), "utf8") });
|
||
});
|
||
// 맨 왼쪽 = 그 날 열의 왼쪽 끝이 고정된 시간 열 바로 옆
|
||
const gap = function (iso) {
|
||
return p.evaluate(function (d) {
|
||
const col = document.querySelector('thead th[data-day="' + d + '"]').getBoundingClientRect();
|
||
return Math.abs(col.left - document.querySelector("thead .lv-cal-time").getBoundingClientRect().right);
|
||
}, iso);
|
||
};
|
||
const day = function (iso) { return p.locator('#lv-side-cal [data-iso="' + iso + '"]'); };
|
||
|
||
await p.goto("http://erp.test/live/calendar?month=2026-11");
|
||
await p.waitForTimeout(300);
|
||
const side = await p.locator("#lv-side-cal").boundingBox(), wrap = await p.locator("#lv-cal-wrap").boundingBox();
|
||
const bar = await p.locator(".lv-bar").boundingBox();
|
||
check("달력이 오른쪽 위(왼쪽 내용과 같은 높이에서 시작)", side.x >= wrap.x + wrap.width && Math.abs(side.y - bar.y) < 6, { side: side, bar: bar });
|
||
check("날짜로 이동 줄 없음", (await p.locator(".lv-jump, [data-jump]").count()) === 0);
|
||
const edges = await p.evaluate(function () {
|
||
const page = document.querySelector(".erp-page").getBoundingClientRect();
|
||
const s = document.getElementById("lv-side-cal").getBoundingClientRect(), l = document.querySelector(".lv").getBoundingClientRect();
|
||
return { left: l.left - page.left, right: page.right - s.right };
|
||
});
|
||
check("좌우 여백 12px", edges.left <= 13 && edges.right <= 13, edges);
|
||
await p.setViewportSize({ width: 2400, height: 900 });
|
||
await p.waitForTimeout(100);
|
||
const wide = await p.evaluate(function () {
|
||
const page = document.querySelector(".erp-page").getBoundingClientRect();
|
||
return { pageRight: page.right, shell: document.documentElement.clientWidth };
|
||
});
|
||
check("넓은 화면도 전체 너비(최대 폭 해제)", Math.abs(wide.pageRight - wide.shell) < 2, wide);
|
||
// 풀HD 브라우저 — 페이지 세로 스크롤 없음, 모든 시간 칸에 카드가 있어도 표 안 스크롤도 없음
|
||
const fit = function () {
|
||
return p.evaluate(function () {
|
||
const pg = document.querySelector(".erp-page"), w = document.getElementById("lv-cal-wrap");
|
||
return { page: pg.scrollHeight - pg.clientHeight, table: w.scrollHeight - w.clientHeight, wrapH: w.clientHeight, row: document.querySelector(".lv-cal tbody tr").getBoundingClientRect().height };
|
||
});
|
||
};
|
||
// 1시간 칸(18줄, 2026-11-06) — 카드가 많은 달은 표 안에서 스크롤, 방송이 적은 달은 표도 한 화면
|
||
for (const h of [937, 880]) {
|
||
await p.setViewportSize({ width: 1920, height: h });
|
||
await p.waitForTimeout(100);
|
||
const f = await fit();
|
||
check("1920×" + h + ": 페이지 세로 스크롤 없음", f.page <= 0, f);
|
||
if (h === 880) await p.screenshot({ path: path.join(__dirname, ".out", "live_fit_880.png") });
|
||
}
|
||
await p.goto("http://erp.test/live/calendar?month=2026-12");
|
||
await p.waitForTimeout(300);
|
||
const empty = await fit();
|
||
check("1920×880 방송 없는 달: 18줄이 표 안 스크롤 없이", empty.page <= 0 && empty.table <= 0, empty);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_fit_880_empty.png") });
|
||
await p.goto("http://erp.test/live/calendar?month=2026-11");
|
||
await p.waitForTimeout(300);
|
||
await p.setViewportSize({ width: 1600, height: 600 });
|
||
await p.waitForTimeout(100);
|
||
const small = await fit();
|
||
check("더 낮은 창: 페이지는 안 움직이고 표 안에서 스크롤", small.page <= 0 && small.table > 0, small);
|
||
const miniW = (await p.locator("#lv-side-cal").boundingBox()).width;
|
||
check("오른쪽 달력 = 240px(300px × 80%)", Math.round(miniW) === 240, miniW);
|
||
const miniDay = await day("2026-11-17").evaluate(function (el) { const c = getComputedStyle(el); return c.height + "|" + c.fontSize; });
|
||
check("달력 칸·글자도 80%", miniDay === "27px|10.8px", miniDay);
|
||
await p.setViewportSize({ width: 1600, height: 900 });
|
||
await p.waitForTimeout(100);
|
||
check("디파발리 = 빨강·이름·말풍선", (await day("2026-11-08").getAttribute("class")).includes("has-hol") && (await day("2026-11-08").getAttribute("title")) === "디파발리");
|
||
check("대체휴일 표시", (await day("2026-11-09").innerText()).includes("대체휴일") && (await day("2026-11-09").getAttribute("title")) === "디파발리 대체", await day("2026-11-09").innerText());
|
||
const marked = await p.locator("#lv-side-cal .has-live").evaluateAll(function (els) { return els.map(function (e) { return e.dataset.iso; }); });
|
||
// 2026-11 달력은 11/1(일)부터라 10/30 칸은 없음, 12/3 = 다음 달 칸
|
||
check("방송 있는 날 = 점(다른 달 날짜 포함)", JSON.stringify(marked) === JSON.stringify(["2026-11-05", "2026-11-20", "2026-12-03"]), marked);
|
||
const dot = await day("2026-11-20").evaluate(function (el) { const c = getComputedStyle(el, "::after"); return c.width + "|" + c.backgroundColor; });
|
||
check("점 모양", dot === "6px|rgb(22, 163, 74)", dot);
|
||
const bold = await p.evaluate(function () {
|
||
return ["#lv-side-cal .pj-dp-title", "#lv-side-cal .pj-dp-wd", '#lv-side-cal [data-iso="2026-11-17"]'].map(function (s) { return getComputedStyle(document.querySelector(s)).fontWeight; });
|
||
});
|
||
check("오른쪽 달력 글자 굵게", bold.every(function (w) { return +w >= 700; }), bold);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_side_cal.png") });
|
||
|
||
await day("2026-11-17").click();
|
||
await p.waitForTimeout(150);
|
||
check("17일이 맨 왼쪽", (await gap("2026-11-17")) < 2, await gap("2026-11-17"));
|
||
check("누른 날 선택 표시", (await day("2026-11-17").getAttribute("class")).includes("is-selected"));
|
||
await day("2026-11-30").click();
|
||
await p.waitForTimeout(150);
|
||
check("마지막 날도 맨 왼쪽", (await gap("2026-11-30")) < 2, await gap("2026-11-30"));
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_side_cal_end.png") });
|
||
await day("2026-11-02").click();
|
||
await p.waitForTimeout(150);
|
||
check("앞날로 돌아감", (await gap("2026-11-02")) < 2, await gap("2026-11-02"));
|
||
// 2시간 방송 = 두 칸 합침(rowspan), 22:00~23:30 = 22·23 칸
|
||
const merged = await p.evaluate(function () {
|
||
return Array.from(document.querySelectorAll('td[data-day="2026-11-05"]')).map(function (td) { return td.dataset.start + "/" + (td.rowSpan || 1); });
|
||
});
|
||
check("2시간 방송 = 두 칸 합침", merged.slice(0, 3).join(",") === "06:00/2,08:00/2,10:00/2" && merged[merged.length - 1] === "22:00/2", merged);
|
||
const tall = await p.evaluate(function () {
|
||
const m = document.querySelector('td[data-day="2026-11-05"][data-start="06:00"]').getBoundingClientRect().height;
|
||
const one = document.querySelector('td[data-day="2026-11-04"][data-start="06:00"]').getBoundingClientRect().height;
|
||
const two = document.querySelector('td[data-day="2026-11-04"][data-start="07:00"]').getBoundingClientRect().height;
|
||
return Math.abs(m - one - two);
|
||
});
|
||
check("합친 칸 높이 = 두 줄", tall < 2, tall);
|
||
const fill = await p.evaluate(function () {
|
||
const td = document.querySelector('td[data-day="2026-11-05"][data-start="08:00"]'), card = td.querySelector(".lv-card");
|
||
const pad = parseFloat(getComputedStyle(td).paddingTop) + parseFloat(getComputedStyle(td).paddingBottom);
|
||
return Math.abs(td.getBoundingClientRect().height - pad - 1 - card.getBoundingClientRect().height); // 1 = 칸 아래 선
|
||
});
|
||
check("카드 높이 = 합친 칸 높이", fill < 2, fill);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_merge.png") });
|
||
// 이미지 링크에 마우스 → 오른쪽 달력 아래 미리보기, 벗어나면 숨김
|
||
const imgLink = p.locator('td[data-day="2026-11-05"][data-start="06:00"] a[data-preview]');
|
||
check("미리보기 처음엔 숨김", await p.locator("#lv-preview").isHidden());
|
||
await imgLink.hover();
|
||
await p.waitForTimeout(200);
|
||
const pv = await p.evaluate(function () {
|
||
const box = document.getElementById("lv-preview"), cal = document.getElementById("lv-side-cal").getBoundingClientRect(), b = box.getBoundingClientRect();
|
||
const img = box.querySelector("img");
|
||
return { hidden: box.hidden, src: img.getAttribute("src"), loaded: img.naturalWidth > 0, cap: box.querySelector("figcaption").textContent,
|
||
below: b.top >= cal.bottom, sameCol: Math.abs(b.left - cal.left) < 2 && Math.abs(b.width - cal.width) < 2, bottom: b.bottom <= window.innerHeight };
|
||
});
|
||
check("이미지 링크에 마우스 = 달력 아래 미리보기", !pv.hidden && pv.src === "/live/images/7" && pv.loaded && pv.below && pv.sameCol && pv.bottom && pv.cap.includes("1/2"), pv);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_preview.png") });
|
||
await p.mouse.move(5, 5);
|
||
await p.waitForTimeout(100);
|
||
check("벗어나면 숨김", await p.locator("#lv-preview").isHidden());
|
||
// 이미지 링크 클릭 = 화면 가운데 보기 창, 원본 크기, 회전, 다운로드, 앞뒤
|
||
await imgLink.click();
|
||
await p.waitForTimeout(300);
|
||
const v = function () {
|
||
return p.evaluate(function () {
|
||
const d = document.getElementById("lv-viewer"), b = d.getBoundingClientRect(), img = d.querySelector("img"), st = d.querySelector(".lv-viewer-stage");
|
||
const dl = d.querySelector("[data-download]");
|
||
return { open: d.open, cx: Math.round(b.left + b.width / 2 - innerWidth / 2), cy: Math.round(b.top + b.height / 2 - innerHeight / 2),
|
||
src: img.getAttribute("src"), natural: img.naturalWidth + "x" + img.naturalHeight, shown: Math.round(img.getBoundingClientRect().width) + "x" + Math.round(img.getBoundingClientRect().height),
|
||
stage: st.style.width + "x" + st.style.height, dl: dl.getAttribute("href") + "|" + dl.download, count: d.querySelector(".lv-viewer-count").textContent };
|
||
});
|
||
};
|
||
let s = await v();
|
||
check("클릭 = 가운데 보기 창", s.open && Math.abs(s.cx) <= 1 && Math.abs(s.cy) <= 1, s);
|
||
check("원본 크기", s.natural === "1566x459" && s.shown === "1566x459" && s.stage === "1566pxx459px", s);
|
||
check("다운로드 = 원본·파일 이름", s.dl === "/live/images/7|r.png" && s.count === "1 / 2", s);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_viewer.png") });
|
||
await p.locator("#lv-viewer [data-rotate]").click();
|
||
s = await v();
|
||
check("회전 = 무대 가로세로 바뀜, 이미지 90°", s.stage === "459pxx1566px" && s.shown === "459x1566", s);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_viewer_rot.png") });
|
||
await p.locator('#lv-viewer [data-step="1"]').click();
|
||
await p.waitForTimeout(200);
|
||
s = await v();
|
||
check("다음 이미지 = 회전 처음으로", s.src === "/live/images/8" && s.count === "2 / 2" && s.stage === "1566pxx459px" && s.dl.endsWith("|s.png"), s);
|
||
await p.locator("#lv-viewer [data-viewer-close]").click();
|
||
check("닫기", !(await v()).open);
|
||
|
||
await p.locator('#lv-side-cal [data-nav="1"]').click();
|
||
await Promise.all([p.waitForURL(/month=2026-12/), day("2026-12-10").click()]);
|
||
await p.waitForTimeout(300);
|
||
check("다른 달 = 그 달 화면에서 맨 왼쪽", (await gap("2026-12-10")) < 2, await gap("2026-12-10"));
|
||
check("크리스마스 표시", (await day("2026-12-25").getAttribute("title")) === "크리스마스");
|
||
|
||
await p.goto("http://erp.test/live_cal_en.html");
|
||
await p.waitForTimeout(300);
|
||
const text = await p.locator("#lv-side-cal").innerText();
|
||
check("영문 화면 = 달력도 영어", !/[가-힣]/.test(text) && text.includes("November 2026") && text.includes("Sun") && text.includes("Replacement"), text);
|
||
check("영문 말풍선", (await day("2026-11-09").getAttribute("title")) === "Deepavali (Replacement)");
|
||
// 스케줄표 — 머리글 가운데·굵게·검정·12px × 1.12, 첫 열 = 쇼핑몰 아이콘
|
||
await p.goto("http://erp.test/live_table_en.html");
|
||
await p.waitForTimeout(300);
|
||
const head = await p.evaluate(function () {
|
||
const ths = Array.from(document.querySelectorAll(".lv-sched thead th")), c = getComputedStyle(ths[5]); // 5 = 금액 열(전엔 오른쪽 정렬)
|
||
const img = document.querySelector(".lv-sched tbody tr td img.lv-pf");
|
||
return [ths[0].textContent, c.textAlign, c.fontWeight, c.color, c.fontSize, img && img.naturalWidth, img && img.alt].join("|");
|
||
});
|
||
check("스케줄표 머리글·쇼핑몰 열", head === "Platform|center|700|rgb(0, 0, 0)|13.44px|64|TikTok", head);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_table.png") });
|
||
// 방송 창이 애니메이션으로 나타남(추가·고치기 같은 창), 움직임 줄이기 설정이면 없음
|
||
await p.goto("http://erp.test/live/calendar?month=2026-11");
|
||
await p.waitForTimeout(200);
|
||
const anim = function () { return p.locator("#lv-dlg").evaluate(function (el) { const c = getComputedStyle(el); return c.animationName + "|" + c.animationDuration; }); };
|
||
await p.locator("#lv-add").click();
|
||
check("추가 창 애니메이션", (await anim()) === "lv-dlg-in|0.2s", await anim());
|
||
await p.waitForTimeout(300);
|
||
const opened = await p.locator("#lv-dlg").evaluate(function (el) { const c = getComputedStyle(el); return c.opacity + "|" + c.transform; });
|
||
check("끝나면 제자리", opened === "1|none", opened);
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_dialog.png") });
|
||
await p.locator("#lv-dlg [data-close]").click();
|
||
await p.locator(".lv-card-edit").first().click();
|
||
check("고치기 창 애니메이션", (await anim()) === "lv-dlg-in|0.2s", await anim());
|
||
// 카드 머리 왼쪽 = 호스트 쇼핑몰 아이콘(예전 ✥ 없음), 쇼핑몰 없는 호스트 = 아이콘 없음
|
||
const pf = await p.evaluate(function () {
|
||
const icon = function (id) { const i = document.querySelector('[data-card="' + id + '"] .lv-card-pf'); return i ? i.getAttribute("src").split("/").pop() + ":" + i.naturalWidth + ":" + Math.round(i.getBoundingClientRect().width) : "-"; };
|
||
return [icon(6), icon(8), icon(22), document.body.textContent.indexOf("✥") < 0].join("|");
|
||
});
|
||
check("카드 쇼핑몰 아이콘", pf === "live-icon-tiktok.png:64:12|live-icon-shopee.png:64:12|-|true", pf);
|
||
// Fee(시간 × 25)·커미션(판매금액 10%) 자동, 광고비·호스트 비용 = 저장한 값, 방송 장소 없음(2026-11-06)
|
||
const fees = function () { return p.locator("#lv-dlg").evaluate(function (d) {
|
||
const q = function (s) { return d.querySelector(s).value; };
|
||
return [q("[data-fee]"), q("[data-commission]"), q('[name="ad_spend"]'), q('[name="host_fee"]'), !!d.querySelector('[name="venue"]')].join("|");
|
||
}); };
|
||
check("고치기 창 금액", (await fees()) === "50.00|50.00|100.00|50.00|false", await fees());
|
||
await p.locator('#lv-dlg [name="sales_amount"]').fill("RM 1,234.5");
|
||
await p.locator('#lv-dlg [name="end_time"]').fill("08:30");
|
||
check("판매금액·끝 시간 바꾸면 다시 계산", (await fees()) === "62.50|123.45|100.00|50.00|false", await fees());
|
||
await p.screenshot({ path: path.join(__dirname, ".out", "live_dialog_fees.png") });
|
||
await p.locator("#lv-dlg [data-close]").click();
|
||
await p.emulateMedia({ reducedMotion: "reduce" });
|
||
await p.locator("#lv-add").click();
|
||
check("움직임 줄이기 = 없음", (await anim()).startsWith("none"), await anim());
|
||
await p.emulateMedia({ reducedMotion: "no-preference" });
|
||
check("스크립트 오류 없음", errors.length === 0, errors);
|
||
} finally {
|
||
await browser.close();
|
||
}
|
||
if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); }
|
||
console.log("\nALL OK");
|
||
})();
|