feat(performance): 직접 추가 쇼핑몰(수동 입력)·쇼핑몰 그룹·설정 드래그 순서
- 마이그레이션 009: perf_marketplaces.is_custom·is_group·parent_code - 설정: [+ 쇼핑몰 추가(수동 입력)]·[+ 그룹 추가], 이름 변경·삭제, 직접 추가 쇼핑몰 그룹 select - custom_ 코드는 registry.get_adapter 가 수동 입력 전용 어댑터(CustomManualAdapter)로 - 매출 실적 표: 그룹 열 = 보이는 하위 쇼핑몰 합계(일 합계엔 안 더함), ▾/▸ 하위 열 접기(localStorage) - 설정 표 ⠿ 드래그 → PUT /api/marketplace-order → sort_order, 화면 순서는 ordered_marketplaces 한 곳 - 테스트: test_custom_groups.py, perf_groups.browser.test.js Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
// 실적 쇼핑몰 그룹·드래그 순서(2026-10-22) — 실제 브라우저(Chromium).
|
||||
// python tests/js/render_performance.py
|
||||
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_groups.browser.test.js
|
||||
// 매출 실적: 그룹 열 = 하위 합계, ▾ 누르면 하위 열이 숨고(▸) 새로고침해도 기억.
|
||||
// 설정: ⠿ 를 끌어 놓으면 화면 순서 그대로 PUT /api/marketplace-order — 그룹은 하위와 함께, 하위는 그룹 안에서만.
|
||||
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); }
|
||||
}
|
||||
function page(file) {
|
||||
const css = fs.readFileSync(path.join(ROOT, "app", "static", "performance.css"), "utf8");
|
||||
const js = fs.readFileSync(path.join(ROOT, "app", "static", "performance.js"), "utf8");
|
||||
return fs.readFileSync(path.join(__dirname, ".out", file), "utf8")
|
||||
.replace(/<link rel="stylesheet" href="\/static\/performance\.css[^"]*" \/>/, function () { return "<style>" + css + "</style>"; })
|
||||
.replace(/<script src="\/static\/performance\.js[^"]*" defer><\/script>/, function () { return "<script>" + js + "</script>"; });
|
||||
}
|
||||
|
||||
(async function () {
|
||||
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
|
||||
try {
|
||||
// ── 매출 실적 — 그룹 열 접기/펴기 ──
|
||||
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } });
|
||||
const p = await ctx.newPage();
|
||||
await p.route("**/*", function (r) { r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page("perf_dash_groups.html") }); });
|
||||
await p.goto("http://perf.test/performance/");
|
||||
const heads = function () {
|
||||
return p.evaluate(function () {
|
||||
return Array.from(document.querySelectorAll(".perf-main thead th")).filter(function (th) { return th.offsetParent !== null; })
|
||||
.map(function (th) { return th.textContent.replace(/\s+/g, " ").trim(); });
|
||||
});
|
||||
};
|
||||
const h0 = await heads();
|
||||
check("그룹 열이 하위 열 바로 앞", JSON.stringify(h0.slice(1, 7)) === JSON.stringify(["카페24", "네이버", "▾오프라인", "매장A ✎", "매장B ✎", "행사 ✎"]), h0);
|
||||
const g5 = await p.evaluate(function () {
|
||||
const tr = document.querySelector('td[data-manual-code="custom_a"][data-date="2026-10-05"]').closest("tr");
|
||||
return tr.querySelector('[data-group-cell="group_off"] .v-gross').textContent.trim();
|
||||
});
|
||||
check("그룹 칸 = 하위 합계(30,000 + 12,000)", g5 === "42,000", g5);
|
||||
await p.click('[data-group-toggle="group_off"]');
|
||||
const h1 = await heads();
|
||||
const hiddenTd = await p.evaluate(function () {
|
||||
return Array.from(document.querySelectorAll('td[data-group-child="group_off"]')).every(function (td) { return td.offsetParent === null; });
|
||||
});
|
||||
check("▾ 누르면 하위 열(머리글·칸) 숨김, ▸ 표시", h1.indexOf("매장A ✎") < 0 && h1.indexOf("▸오프라인") >= 0 && hiddenTd && h1.indexOf("행사 ✎") >= 0, h1);
|
||||
await p.reload();
|
||||
const h2 = await heads();
|
||||
check("접은 상태 새로고침 후에도 기억", h2.indexOf("매장A ✎") < 0 && h2.indexOf("▸오프라인") >= 0, h2);
|
||||
await p.click('[data-group-toggle="group_off"]');
|
||||
check("다시 누르면 펼침", (await heads()).indexOf("매장B ✎") >= 0);
|
||||
await ctx.close();
|
||||
|
||||
// ── 설정 — 드래그 순서 ──
|
||||
const sp = await browser.newPage({ viewport: { width: 1500, height: 1000 } });
|
||||
const puts = [];
|
||||
let reloads = 0; const pages = [];
|
||||
await sp.route("**/*", async function (r) {
|
||||
const req = r.request(), url = new URL(req.url()).pathname;
|
||||
if (url === "/favicon.ico" || url.startsWith("/static/")) { r.fulfill({ status: 404, body: "" }); return; }
|
||||
if (!url.startsWith("/performance/api/")) {
|
||||
reloads++; pages.push(url);
|
||||
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page("perf_settings_groups.html") });
|
||||
return;
|
||||
}
|
||||
puts.push({ method: req.method(), url: url, body: req.postData() ? JSON.parse(req.postData()) : null });
|
||||
r.fulfill({ status: 200, contentType: "application/json", body: "{}" });
|
||||
});
|
||||
await sp.goto("http://perf.test/performance/settings");
|
||||
const order = function () {
|
||||
return sp.evaluate(function () {
|
||||
return Array.from(document.querySelectorAll(".perf-set-table tbody.perf-sort-block > tr[data-code]")).map(function (tr) { return tr.dataset.code; });
|
||||
});
|
||||
};
|
||||
check("설정 처음 순서(그룹 뒤에 하위)", JSON.stringify(await order()) === JSON.stringify(["cafe24", "naver", "group_off", "custom_a", "custom_b", "custom_c"]), await order());
|
||||
async function drag(fromCode, toCode, where) {
|
||||
const h = await sp.locator('tr[data-code="' + fromCode + '"] .perf-drag').boundingBox();
|
||||
const t = await sp.locator('tr[data-code="' + toCode + '"]').boundingBox();
|
||||
await sp.mouse.move(h.x + h.width / 2, h.y + h.height / 2);
|
||||
await sp.mouse.down();
|
||||
const y = where === "above" ? t.y + 3 : t.y + t.height - 3;
|
||||
await sp.mouse.move(h.x + h.width / 2, (h.y + y) / 2, { steps: 4 });
|
||||
await sp.mouse.move(h.x + h.width / 2, y, { steps: 6 });
|
||||
await sp.mouse.up();
|
||||
await sp.waitForTimeout(100);
|
||||
}
|
||||
// 그룹(하위 포함)을 카페24 위로
|
||||
await drag("group_off", "cafe24", "above");
|
||||
const o1 = await order();
|
||||
check("그룹 블록 통째로 이동", JSON.stringify(o1) === JSON.stringify(["group_off", "custom_a", "custom_b", "cafe24", "naver", "custom_c"]), o1);
|
||||
const last = puts[puts.length - 1];
|
||||
check("놓으면 화면 순서 그대로 저장", last && last.method === "PUT" && last.url === "/performance/api/marketplace-order" &&
|
||||
JSON.stringify(last.body.codes) === JSON.stringify(o1), last);
|
||||
// 하위끼리 순서 변경 — 그룹 행 위로는 못 나감
|
||||
await drag("custom_b", "custom_a", "above");
|
||||
const o2 = await order();
|
||||
check("하위 쇼핑몰은 그룹 안에서 순서 변경", JSON.stringify(o2) === JSON.stringify(["group_off", "custom_b", "custom_a", "cafe24", "naver", "custom_c"]), o2);
|
||||
const n = puts.length;
|
||||
await drag("custom_a", "naver", "below");
|
||||
check("하위 쇼핑몰은 그룹 밖으로 안 나감(저장 없음)", JSON.stringify(await order()) === JSON.stringify(o2) && puts.length === n, await order());
|
||||
// 그룹 지정 select → PUT parent_code
|
||||
check("순서 저장은 새로고침 없음", reloads === 1, pages);
|
||||
await sp.selectOption('tr[data-code="custom_c"] select[data-act-group]', "group_off");
|
||||
await sp.waitForTimeout(300);
|
||||
const g = puts[puts.length - 1];
|
||||
check("그룹 지정 → PUT parent_code 후 새로고침", g && g.url === "/performance/api/marketplaces/custom_c" && g.body.parent_code === "group_off" && reloads === 2, { g: g, reloads: reloads });
|
||||
const wraps = await sp.evaluate(function () {
|
||||
const t = document.querySelector(".perf-set-table");
|
||||
return t.scrollWidth <= t.parentElement.clientWidth + 1;
|
||||
});
|
||||
check("설정 표가 1500px 에서 가로 스크롤 없음", wraps);
|
||||
await sp.screenshot({ path: path.join(__dirname, ".out", "perf_settings_groups.png"), fullPage: true });
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
console.log(fails.length ? "\n" + fails.length + " FAIL" : "\nALL PASS");
|
||||
process.exit(fails.length ? 1 : 0);
|
||||
})();
|
||||
@@ -273,7 +273,8 @@ function gross(td) { return td.querySelector(".v-gross").textContent.trim(); }
|
||||
const heads = Array.from(e.d.querySelectorAll(SHOP + " thead th")).map(function (th) { return th.textContent.trim(); });
|
||||
check("[설정] '수동 입력' 열(매출 집계 다음)", heads.indexOf("수동 입력") === heads.indexOf("매출 집계") + 1, heads);
|
||||
const rows = Array.from(e.d.querySelectorAll(SHOP + " tbody tr")).map(function (tr) { return tr.dataset.code; });
|
||||
check("[설정] 쇼핑몰 순서 = 어댑터 등록 순서(003 열 순서)", rows.join(",") === "cafe24,naver,coupang,ohouse,gmarket,kakao,gsshop,elevenst,lotteon,toss", rows);
|
||||
// 2026-10-22 — 설정 표 순서 = DB sort_order(⠿ 드래그로 바꾸는 순서, 매출 실적 열과 같음). 예전엔 어댑터 등록 순서였다.
|
||||
check("[설정] 쇼핑몰 순서 = DB sort_order(드래그 순서)", rows.join(",") === "cafe24,naver,coupang,toss,gsshop,elevenst,ohouse,gmarket,kakao,lotteon", rows);
|
||||
const adRows = Array.from(e.d.querySelectorAll("#perf-ad-sources tbody tr")).map(function (tr) { return tr.dataset.code + ":" + tr.dataset.api; });
|
||||
check("[설정] 광고 API 연동 표는 따로(구글 광고, /api/ad-sources/)", adRows.join(",") === "google:ad-sources", adRows);
|
||||
const box = e.d.querySelector('tr[data-code="coupang"] input[data-field="manual_input"]');
|
||||
|
||||
@@ -91,6 +91,7 @@ def main() -> None:
|
||||
actx = build_ad_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7),
|
||||
sales_codes=["cafe24", "coupang"])
|
||||
actx["ad_sync_sources"] = [{"code": "google", "name": "구글 광고"}] # [구글 광고 불러오기]
|
||||
actx["auto_sync"] = ctx["auto_sync"] # 광고비 탭도 다음 업데이트 카운트다운(router._auto_sync_ctx)
|
||||
html = e.get_template("performance/ads.html").render(**base, active_tab="ads", **actx)
|
||||
with open(os.path.join(OUT_DIR, "perf_ads.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
@@ -102,8 +103,43 @@ def main() -> None:
|
||||
html = e.get_template("performance/settings.html").render(**base, active_tab="settings", **sctx)
|
||||
with open(os.path.join(OUT_DIR, "perf_settings.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
# 직접 추가 쇼핑몰·그룹(2026-10-22) — perf_dash_groups.html · perf_settings_groups.html (perf_groups.browser.test.js)
|
||||
gctx = build_dashboard(GroupStore(), kind="week", anchor=date(2026, 10, 7), today=date(2026, 10, 7))
|
||||
gctx["auto_sync"] = None
|
||||
html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="gross", **gctx)
|
||||
with open(os.path.join(OUT_DIR, "perf_dash_groups.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
gsctx = build_settings(GroupStore(), configured={}, key_info={"ok": True}, key_versions_in_use={}, sample_count=0)
|
||||
gsctx.update(ad_api_ready=True, ad_sources=[])
|
||||
html = e.get_template("performance/settings.html").render(**base, active_tab="settings", **gsctx)
|
||||
with open(os.path.join(OUT_DIR, "perf_settings_groups.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
print("ok")
|
||||
|
||||
|
||||
class GroupStore(FakeStore):
|
||||
"""카페24·네이버 + 그룹 '오프라인'(매장A·매장B) + 그룹 없는 직접 추가 '행사'."""
|
||||
|
||||
def list_marketplaces(self):
|
||||
rows = [{"code": c, "name": NAMES[c], "enabled": True, "include_in_sales": True, "sort_order": i * 10,
|
||||
"manual_input": False, "is_custom": False, "is_group": False, "parent_code": None}
|
||||
for i, c in enumerate(("cafe24", "naver"), 1)]
|
||||
custom = {"enabled": True, "include_in_sales": True, "manual_input": True, "is_custom": True, "is_group": False}
|
||||
return rows + [
|
||||
{"code": "group_off", "name": "오프라인", "sort_order": 30, "enabled": True, "include_in_sales": False,
|
||||
"manual_input": False, "is_custom": True, "is_group": True, "parent_code": None},
|
||||
{**custom, "code": "custom_a", "name": "매장A", "sort_order": 40, "parent_code": "group_off"},
|
||||
{**custom, "code": "custom_b", "name": "매장B", "sort_order": 50, "parent_code": "group_off"},
|
||||
{**custom, "code": "custom_c", "name": "행사", "sort_order": 60, "parent_code": None},
|
||||
]
|
||||
|
||||
def manual_amounts(self, start, end, codes, *, active_only=True):
|
||||
manual = {(date(2026, 10, 5), "custom_a"): 30000, (date(2026, 10, 5), "custom_b"): 12000}
|
||||
return {k: v for k, v in manual.items() if start <= k[0] <= end and k[1] in codes}
|
||||
|
||||
def ad_amounts(self, start, end):
|
||||
return {}, {}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user