feat(실적): 틱톡 탭과 틱톡 광고 API 연동
광고비 탭 오른쪽에 틱톡 탭 추가. 일자별 ROAS, 광고비, 매출을 광고비 탭과 같은 틀로 보여 준다. 실적 설정 광고 API 연동에 틱톡 추가(광고 계정 ID, 액세스 토큰, 선택 틱톡샵 ID). 채널 표(CHANNELS)에 넣지 않아 매출 실적·광고비 탭 합계에는 들어가지 않는다. DB 변경 없음. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// 실적 틱톡 탭(2026-11-05) — 실제 브라우저(Chromium).
|
||||
// python tests/js/render_performance.py
|
||||
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_tiktok.browser.test.js
|
||||
// 광고비 오른쪽 탭, ROAS·광고비·매출 열, 매출·광고비 그래프 둘, 합계 줄 스크롤 고정, 칸 입력 없음, 스크립트 오류 없음.
|
||||
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: 1400, height: 800 } })).newPage();
|
||||
const errors = [];
|
||||
p.on("pageerror", function (e) { errors.push(String(e)); });
|
||||
await p.route("**/*", function (r) {
|
||||
const url = new URL(r.request().url()).pathname;
|
||||
if (url.startsWith("/static/")) {
|
||||
const f = path.join(ROOT, "app", url);
|
||||
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) });
|
||||
}
|
||||
if (!url.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", url.slice(1)), "utf8") });
|
||||
});
|
||||
await p.goto("http://erp.test/perf_tiktok_shell.html");
|
||||
await p.waitForTimeout(300);
|
||||
const tabs = await p.locator(".perf-tabs-main .perf-tab").allInnerTexts();
|
||||
check("탭 순서 = 매출 실적·광고비·틱톡", tabs.map(function (t) { return t.replace(/^[a-z_]+\s*/, "").trim(); }).join() === "매출 실적,광고비,틱톡", tabs);
|
||||
check("틱톡 탭이 켜짐", await p.locator(".perf-tab-tiktok.is-active").count() === 1);
|
||||
const head = await p.locator("table.perf-main thead th").allInnerTexts();
|
||||
check("열 = 날짜·ROAS·광고비·매출", head.join() === "날짜,ROAS,광고비,매출", head);
|
||||
const total = await p.locator("table.perf-main tbody tr").first().innerText();
|
||||
check("맨 위 기간 합계", total.includes("합계") && total.includes("210,000") && total.includes("630,000") && total.includes("300%"), total);
|
||||
const day = await p.locator("table.perf-main tbody tr", { hasText: "400%" }).first().innerText();
|
||||
check("일자 줄 값", day.includes("120,000") && day.includes("480,000"), day);
|
||||
check("매출 그래프", await p.locator("#perf-chart-daily svg rect.bar").count() > 0);
|
||||
check("광고비 그래프", await p.locator("#perf-chart-daily2 svg rect.bar").count() > 0);
|
||||
check("칸 입력 없음", await p.locator("[data-manual-code]").count() === 0);
|
||||
check("업데이트 버튼", (await p.locator("#perf-ad-sync-btn").innerText()).includes("광고비 업데이트"));
|
||||
await p.screenshot({ path: path.join(__dirname, ".out", "perf_tiktok.png") });
|
||||
await p.locator("table.perf-main").hover();
|
||||
await p.mouse.wheel(0, 500);
|
||||
await p.waitForTimeout(250);
|
||||
const stuck = await p.evaluate(function () {
|
||||
const first = document.querySelector("table.perf-main tbody tr.perf-row-total:first-child th");
|
||||
const top = first.getBoundingClientRect().top;
|
||||
return document.querySelector("table.perf-main thead th").getBoundingClientRect().bottom <= top + 2 && top >= 0 && top < 300;
|
||||
});
|
||||
check("스크롤해도 제목·합계 줄 고정", stuck);
|
||||
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");
|
||||
})();
|
||||
@@ -19,7 +19,7 @@ ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)
|
||||
sys.path.insert(0, ROOT)
|
||||
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
|
||||
|
||||
from app.modules.performance.ad_spend import build_ad_dashboard # noqa: E402
|
||||
from app.modules.performance.ad_spend import build_ad_dashboard, build_tiktok_dashboard # noqa: E402
|
||||
from app.modules.performance.dashboard import amount_text, build_dashboard, build_settings # noqa: E402
|
||||
from app.modules.performance.router import _auto_sync_settings_ctx # noqa: E402
|
||||
|
||||
@@ -84,6 +84,12 @@ def env() -> jinja2.Environment:
|
||||
return e
|
||||
|
||||
|
||||
class TiktokStore:
|
||||
def ad_details(self, code, start, end):
|
||||
rows = [("2026-10-02", 120000, 480000), ("2026-10-05", 90000, 150000), ("2026-09-20", 50000, 100000)]
|
||||
return [{"date": d, "amount": a, "roas": None, "metrics": {"매출": b}, "source": "api"} for d, a, b in rows]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
e = env()
|
||||
@@ -117,6 +123,12 @@ def main() -> None:
|
||||
html = shell.get_template("performance/ads.html").render(**sbase, active_tab="ads", **sactx)
|
||||
with open(os.path.join(OUT_DIR, "perf_ads_shell.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
# 틱톡 탭(2026-11-05) — 가상의 광고 API 값
|
||||
tk = build_tiktok_dashboard(TiktokStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7), holidays={"2026-10-03": "개천절"})
|
||||
tk.update(auto_sync=ctx["auto_sync"], update_watch={"kind": "ads", "seen": "job-old"}, tiktok_configured=True, ad_running=False,
|
||||
ad_last_update_at=None, ad_sync_sources=[{"code": "tiktok", "name": "틱톡"}])
|
||||
with open(os.path.join(OUT_DIR, "perf_tiktok_shell.html"), "w", encoding="utf-8") as f:
|
||||
f.write(shell.get_template("performance/tiktok.html").render(**sbase, active_tab="tiktok", **tk))
|
||||
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": "구글 광고"}] # [구글 광고 불러오기]
|
||||
|
||||
Reference in New Issue
Block a user