feat(라이브): 달력 보기 오른쪽에 공용 달력과 말레이시아 공휴일
표 오른쪽에 erp-datepop 붙박이 달력을 두고, 날짜를 누르면 그 날이 표 맨 왼쪽에 오게 한다. 다른 달을 누르면 그 달 화면으로 이동해 같은 위치로 맞춘다. 마지막 날도 맨 왼쪽에 오도록 표 끝에 여백을 둔다. 말레이시아 공휴일·대체휴일 표(holidays.py, 쿠알라룸푸르 기준 2026·2027)를 표시한다. 공용 달력에 선택 옵션 locale 을 추가해 영문 화면도 영어로 그린다. 기존 화면 동작은 그대로. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
// 라이브 커머스 오른쪽 달력(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
|
||||
// 표 오른쪽에 달력, 말레이시아 공휴일·대체휴일 빨강·이름·말풍선, 날짜를 누르면 그 날이 표 맨 왼쪽(마지막 날까지), 다른 달은 그 달 화면으로 가서 맨 왼쪽, 영문 화면은 달력도 영어.
|
||||
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" : "font/woff2";
|
||||
return r.fulfill({ status: 200, contentType: type, body: fs.readFileSync(f) });
|
||||
}
|
||||
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();
|
||||
check("달력이 표 오른쪽", side.x >= wrap.x + wrap.width && Math.abs(side.y - wrap.y) < 2, { side: side, wrap: wrap });
|
||||
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());
|
||||
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"));
|
||||
await p.locator('.lv-jump-day[data-jump="2026-11-20"]').click();
|
||||
await p.waitForTimeout(150);
|
||||
check("날짜로 이동 줄도 맨 왼쪽·달력 선택 따라감", (await gap("2026-11-20")) < 2 && (await day("2026-11-20").getAttribute("class")).includes("is-selected"));
|
||||
|
||||
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)");
|
||||
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");
|
||||
})();
|
||||
@@ -0,0 +1,64 @@
|
||||
"""라이브 커머스 달력 보기를 진짜 앱 라우터로 렌더 — 오른쪽 달력 브라우저 테스트용(2026-11-05).
|
||||
|
||||
python tests/js/render_live.py # → tests/js/.out/live_cal_ko.html · live_cal_en.html · live_cal_dec.html
|
||||
|
||||
DB 없이 가짜 저장소로 11월·12월 화면을 그린다(공휴일 = 실제 표).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from datetime import date, time
|
||||
from decimal import Decimal
|
||||
from unittest.mock import patch
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.insert(0, ROOT)
|
||||
os.chdir(ROOT)
|
||||
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
|
||||
for key in ("ASSET", "CAFE24", "CUPANG", "VACATION", "PROJECT", "DISPATCH", "PERFORMANCE", "MALAYSIA_STOCK", "ITEMCODE", "EXPENSE", "INOUT", "OUTREACH", "LIVE"):
|
||||
os.environ[key + "_DB_URL"] = ""
|
||||
os.environ.update(SESSION_SECRET_KEY="local-live-test-only", SESSION_COOKIE_SECURE="false", PERFORMANCE_AUTO_SYNC="false", DATA_DIR=tempfile.mkdtemp())
|
||||
|
||||
from fastapi.testclient import TestClient # noqa: E402
|
||||
|
||||
import app.main as main # noqa: E402
|
||||
|
||||
|
||||
class Fake:
|
||||
def host_choices(self):
|
||||
return [{"id": 1, "display_name": "Nabella", "full_name": "Nazzureen Nabella binti Samad", "is_active": True}]
|
||||
|
||||
def list_broadcasts(self, start, end):
|
||||
if start.month != 11:
|
||||
return []
|
||||
return [{"id": 1, "host_id": 1, "host_name": "Nabella", "tiktok_handle": "MainAccount", "broadcast_date": date(2026, 11, 5), "start_time": time(8),
|
||||
"end_time": time(10), "venue": "", "sales_amount": Decimal("500"), "images": []}]
|
||||
|
||||
def ad_spends(self, start, end):
|
||||
return {}
|
||||
|
||||
def account_choices(self):
|
||||
return ["MainAccount"]
|
||||
|
||||
|
||||
def main_() -> None:
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
main.app.state.live_store = Fake()
|
||||
user = {"email": "t@test.local", "name": "T", "role": "user", "is_super_admin": False, "modules": {"live": True}}
|
||||
with patch.object(main, "get_current_user_record", side_effect=lambda r: user), patch.object(main, "get_session_user", side_effect=lambda r: user), \
|
||||
patch.object(main.user_store, "get", side_effect=lambda e: user), patch.object(main.user_store, "list_all", side_effect=lambda: [user]):
|
||||
for name, lang, month in (("live_cal_ko.html", "ko", "2026-11"), ("live_cal_en.html", "en", "2026-11"), ("live_cal_dec.html", "ko", "2026-12")):
|
||||
client = TestClient(main.app)
|
||||
client.cookies.set("live_lang", lang)
|
||||
res = client.get("/live/calendar?month=" + month)
|
||||
assert res.status_code == 200, (name, res.status_code)
|
||||
with open(os.path.join(OUT_DIR, name), "w", encoding="utf-8") as f:
|
||||
f.write(res.text)
|
||||
print("ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main_()
|
||||
Reference in New Issue
Block a user