7e459c1926
- 팝업에 입고센터 카드: [+ 입고센터 추가]·[센터 삭제], 센터마다 입고센터·출고방식·제품·출고를 따로 입력 (작성일·출고일·센터입고일·작업자는 공통), 출고방식 기본값 택배 - POST /cupang/api/outbound-sheet: centers 목록을 받아 센터 순서대로 출고일 시트 아래에 덧붙임 (엑셀 내려받기·올리기 1번씩, 순번 이어짐, 파렛트 센터만 배경색). centers 없으면 예전처럼 센터 1곳 - ?stream=1 이면 단계별 진행률을 NDJSON 으로 흘려보냄(내려받기 → 센터별 추가 → 올리기 → 완료/오류), 팝업은 막대 그래프와 %로 표시하고 단계 사이에도 조금씩 채움, 실패하면 빨간 막대 + 사유 - 테스트: pytest(센터별 입력 검사·여러 센터 한 번에 쓰기·진행 단계·스트림·충돌), Playwright(카드·진행 막대·완료·실패·모바일) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
275 lines
16 KiB
JavaScript
275 lines
16 KiB
JavaScript
// 쿠팡 밀크런 — "밀크런 출고리스트 작성" 팝업을 실제 Chromium 에서 검증(DB·구글 미사용, 가짜 서버).
|
|
// python tests/js/render_cupang_index.py
|
|
// PJ_TEST_BROWSER=<설치된 Chrome/Edge 경로> node tests/js/cupang_outbound.browser.test.js
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs");
|
|
const http = require("node:http");
|
|
const path = require("node:path");
|
|
const { chromium } = require("playwright");
|
|
const ROOT = path.resolve(__dirname, "../..");
|
|
const STATIC = path.join(ROOT, "app/static");
|
|
const OUT = path.join(__dirname, ".out");
|
|
const posts = [];
|
|
let releaseUpload = null; // 올리기 단계에서 멈춰 두었다가 진행 막대를 확인한 뒤 풀어 준다
|
|
|
|
const PRODUCTS = [
|
|
{ code: "MT-7000", name: "점보 7,000ml", type: "단품" },
|
|
{ code: "MS-1004", name: "미라네 4호세트", type: "세트" },
|
|
{ code: "MT-3000", name: "중형 3,000ml", type: "단품" },
|
|
];
|
|
|
|
function json(res, status, body) {
|
|
res.statusCode = status;
|
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
res.end(JSON.stringify(body));
|
|
}
|
|
|
|
// 실제 서버처럼 진행 상황을 NDJSON 한 줄씩
|
|
function streamWrite(res, body) {
|
|
res.statusCode = 200;
|
|
res.setHeader("Content-Type", "application/x-ndjson");
|
|
const send = ev => res.write(JSON.stringify(ev) + "\n");
|
|
send({ progress: 5, until: 40, step: "출고리스트 엑셀 내려받는 중" });
|
|
if (body.centers.some(c => c.center === "실패센터")) {
|
|
send({ error: "출고리스트 파일에 기록하지 못했습니다(HttpError). 잠시 후 다시 시도해 주세요." });
|
|
res.end();
|
|
return;
|
|
}
|
|
const n = body.centers.length;
|
|
body.centers.forEach((c, i) => send({ progress: 40 + Math.floor(40 * i / n), until: 40 + Math.floor(40 * (i + 1) / n),
|
|
step: c.center + " 추가 중 (" + (i + 1) + "/" + n + ")" }));
|
|
send({ progress: 80, until: 100, step: "출고리스트 엑셀 올리는 중" });
|
|
releaseUpload = function () {
|
|
let row = 10;
|
|
const centers = body.centers.map(c => {
|
|
const r = { center: c.center, first_row: row, last_row: row + c.lines.length - 1, line_count: c.lines.length };
|
|
row += c.lines.length;
|
|
return r;
|
|
});
|
|
send({ progress: 100, until: 100, step: "완료", done: true, ok: true, title: "20261026(월)",
|
|
first_row: 10, last_row: row - 1, line_count: centers.reduce((a, c) => a + c.line_count, 0), centers: centers,
|
|
url: "https://docs.google.com/spreadsheets/d/x/edit" });
|
|
res.end();
|
|
};
|
|
}
|
|
|
|
const server = http.createServer(function (req, res) {
|
|
const url = new URL(req.url, "http://localhost");
|
|
if (url.pathname === "/cupang/") {
|
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
res.end(fs.readFileSync(path.join(OUT, "cupang_index_render.html"))); return;
|
|
}
|
|
if (url.pathname === "/cupang/api/outbound-sheet/centers") return json(res, 200, { centers: ["대구3", "인천32"], reason: "" });
|
|
if (url.pathname === "/cupang/api/products/all") return json(res, 200, { enabled: true, reason: "", error: "", results: PRODUCTS });
|
|
if (url.pathname === "/cupang/api/outbound-sheet" && req.method === "POST") {
|
|
let raw = "";
|
|
req.on("data", c => { raw += c; });
|
|
req.on("end", function () {
|
|
const body = JSON.parse(raw);
|
|
posts.push({ stream: url.searchParams.get("stream"), body: body });
|
|
if (body.centers.some(c => c.center === "잘못센터")) return json(res, 400, { detail: "2번째 입고센터: 입고센터를 입력해 주세요." });
|
|
streamWrite(res, body);
|
|
});
|
|
return;
|
|
}
|
|
const file = path.resolve(STATIC, "." + decodeURIComponent(url.pathname.slice(7)));
|
|
if (!url.pathname.startsWith("/static/") || !file.startsWith(STATIC + path.sep) || !fs.existsSync(file) || !fs.statSync(file).isFile()) {
|
|
res.statusCode = 404; res.end(); return;
|
|
}
|
|
const types = { ".css": "text/css", ".js": "text/javascript", ".woff2": "font/woff2", ".woff": "font/woff", ".png": "image/png", ".svg": "image/svg+xml" };
|
|
res.setHeader("Content-Type", types[path.extname(file)] || "application/octet-stream");
|
|
fs.createReadStream(file).pipe(res);
|
|
});
|
|
|
|
async function pickDate(page, inputId, typed) {
|
|
// 프로젝트 날짜 팝업: 버튼 → 팝업의 날짜 칸에 직접 입력 + Enter
|
|
await page.locator("#" + inputId + " + .pj-date-btn").click();
|
|
const pop = page.locator(".pj-datepop");
|
|
await pop.waitFor({ state: "visible" });
|
|
await pop.locator(".pj-dp-field").fill(typed);
|
|
await pop.locator(".pj-dp-field").press("Enter");
|
|
await pop.waitFor({ state: "detached" });
|
|
}
|
|
|
|
async function addProduct(card, text, qty) {
|
|
await card.locator(".cpg-ol-search-input").fill(text);
|
|
await card.locator(".cpg-ol-search-input").press("Enter");
|
|
if (qty != null) await card.locator(".cpg-ol-qty").last().fill(String(qty));
|
|
}
|
|
|
|
(async function () {
|
|
let browser;
|
|
try {
|
|
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
|
|
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));
|
|
await page.goto("http://127.0.0.1:" + server.address().port + "/cupang/");
|
|
|
|
// 버튼: "+ 신규 등록" 바로 오른쪽, 엑셀 초록
|
|
const openBtn = page.locator("#cpg-ol-open");
|
|
await openBtn.waitFor({ state: "visible" });
|
|
const newBox = await page.locator("a", { hasText: "+ 신규 등록" }).boundingBox();
|
|
const btnBox = await openBtn.boundingBox();
|
|
assert.ok(btnBox.x > newBox.x + newBox.width - 1 && btnBox.x - (newBox.x + newBox.width) < 20, "신규 등록 바로 옆");
|
|
assert.ok(Math.abs(btnBox.y - newBox.y) < 3, "같은 줄");
|
|
assert.equal(await openBtn.evaluate(el => getComputedStyle(el).backgroundColor), "rgb(33, 115, 70)");
|
|
|
|
// 팝업 열기 — 작성일 = 오늘, 작업자 = 핫프렌즈, 입고센터 카드 1장(출고방식 기본 택배, 삭제 버튼 숨김)
|
|
await openBtn.click();
|
|
await page.locator("#cpg-ol-dlg").waitFor({ state: "visible" });
|
|
assert.equal(await page.locator("#cpg-ol-doc-date + .pj-date-btn").innerText(), "calendar_month\n오늘");
|
|
assert.equal(await page.locator("#cpg-ol-worker").inputValue(), "핫프렌즈");
|
|
const cards = page.locator(".cpg-ol-center");
|
|
assert.equal(await cards.count(), 1);
|
|
const c1 = cards.nth(0);
|
|
assert.equal(await c1.locator(".cpg-ol-center-no").innerText(), "입고센터 1");
|
|
assert.ok(await c1.locator(".cpg-ol-center-del").isHidden(), "센터가 하나면 삭제 버튼 숨김");
|
|
assert.equal(await c1.locator(".cpg-ol-method").inputValue(), "택배");
|
|
assert.deepEqual(await c1.locator(".cpg-ol-method option").allInnerTexts(), ["택배", "파렛트"]);
|
|
await page.waitForFunction(() => document.querySelectorAll(".cpg-ol-center-sel option").length === 4);
|
|
assert.deepEqual(await c1.locator(".cpg-ol-center-sel option").allInnerTexts(), ["센터 선택", "대구3", "인천32", "+ 직접 입력"]);
|
|
assert.ok(await page.locator("#cpg-ol-progress").isHidden(), "처음엔 진행 막대 숨김");
|
|
|
|
// 출고일 → 센터입고일은 다음날로 자동
|
|
await pickDate(page, "cpg-ol-ship-date", "2026-10-26");
|
|
assert.equal(await page.locator("#cpg-ol-arrival-date").inputValue(), "2026-10-27");
|
|
assert.match(await page.locator("#cpg-ol-target").innerText(), /20261026\(월\)/);
|
|
|
|
// 첫 센터: 필수값 확인 → 인천32 파렛트, 제품 2개
|
|
await page.locator("#cpg-ol-submit").click();
|
|
assert.equal(await page.locator("#cpg-ol-error").innerText(), "입고센터를 선택해 주세요.");
|
|
await c1.locator(".cpg-ol-center-sel").selectOption("인천32");
|
|
await page.locator("#cpg-ol-submit").click();
|
|
assert.equal(await page.locator("#cpg-ol-error").innerText(), "제품을 1개 이상 추가해 주세요.");
|
|
assert.ok(!(await c1.locator(".cpg-ol-lines").isVisible()), "제품이 없으면 표를 숨김");
|
|
await c1.locator(".cpg-ol-method").selectOption("파렛트");
|
|
await addProduct(c1, "점보", 1200);
|
|
await c1.locator(".cpg-ol-search-input").fill("ms-");
|
|
await c1.locator(".cpg-ol-hit", { hasText: "MS-1004" }).click();
|
|
await addProduct(c1, "MT-7000"); // 같은 제품은 줄을 늘리지 않는다
|
|
assert.equal(await c1.locator(".cpg-ol-lines tbody tr").count(), 2);
|
|
await c1.locator(".cpg-ol-outbound").fill("2파렛트");
|
|
|
|
// 센터 추가 → 2번 카드(기본 택배, 다른 센터 카드와 제품 목록 따로), 번호·삭제 버튼
|
|
await page.locator("#cpg-ol-add-center").click();
|
|
assert.equal(await cards.count(), 2);
|
|
const c2 = cards.nth(1);
|
|
assert.equal(await c2.locator(".cpg-ol-center-no").innerText(), "입고센터 2");
|
|
assert.ok(await c1.locator(".cpg-ol-center-del").isVisible() && await c2.locator(".cpg-ol-center-del").isVisible());
|
|
assert.equal(await c2.locator(".cpg-ol-method").inputValue(), "택배");
|
|
assert.equal(await c2.locator(".cpg-ol-lines tbody tr").count(), 0);
|
|
await page.locator("#cpg-ol-submit").click();
|
|
assert.equal(await page.locator("#cpg-ol-error").innerText(), "입고센터 1: 미라네 4호세트의 수량을 입력해 주세요.");
|
|
await c1.locator(".cpg-ol-qty").nth(1).fill("60");
|
|
await page.locator("#cpg-ol-submit").click();
|
|
assert.equal(await page.locator("#cpg-ol-error").innerText(), "입고센터 2: 입고센터를 선택해 주세요.");
|
|
await c2.locator(".cpg-ol-center-sel").selectOption("__new__");
|
|
await c2.locator(".cpg-ol-center-new").fill("이천1");
|
|
await addProduct(c2, "중형", 30);
|
|
// 3번 카드를 만든 뒤 가운데(이천1) 카드를 지우면 번호가 다시 매겨진다
|
|
await page.locator("#cpg-ol-add-center").click();
|
|
assert.equal(await cards.count(), 3);
|
|
await cards.nth(1).locator(".cpg-ol-center-del").click();
|
|
assert.equal(await cards.count(), 2);
|
|
const c2b = cards.nth(1);
|
|
assert.equal(await c2b.locator(".cpg-ol-center-no").innerText(), "입고센터 2");
|
|
assert.equal(await c2b.locator(".cpg-ol-lines tbody tr").count(), 0, "지운 카드의 제품은 따라오지 않음");
|
|
await c2b.locator(".cpg-ol-center-sel").selectOption("대구3");
|
|
await addProduct(c2b, "중형", 30);
|
|
await page.screenshot({ path: path.join(OUT, "cupang-outbound-dialog.png"), fullPage: true });
|
|
|
|
// 완료 → 진행 막대·% (올리기 단계에서 멈춘 동안 확인) → 성공 안내
|
|
await page.locator("#cpg-ol-submit").click();
|
|
await page.locator("#cpg-ol-progress").waitFor({ state: "visible" });
|
|
await page.waitForFunction(() => document.getElementById("cpg-ol-progress-step").textContent === "출고리스트 엑셀 올리는 중");
|
|
await page.waitForTimeout(600);
|
|
const mid = await page.evaluate(() => ({
|
|
pct: document.getElementById("cpg-ol-progress-pct").textContent,
|
|
width: parseFloat(document.getElementById("cpg-ol-progress-bar").style.width),
|
|
aria: document.getElementById("cpg-ol-progress-track").getAttribute("aria-valuenow"),
|
|
}));
|
|
assert.ok(mid.width >= 80 && mid.width < 100, "올리는 중엔 80~99% — " + mid.width);
|
|
assert.equal(mid.pct, Math.round(mid.width) + "%");
|
|
assert.equal(mid.aria, String(Math.round(mid.width)));
|
|
assert.equal(await page.locator("#cpg-ol-submit").innerText(), "기록 중…");
|
|
assert.ok(await page.locator("#cpg-ol-add-center").isDisabled(), "기록 중엔 센터 추가 막음");
|
|
await page.screenshot({ path: path.join(OUT, "cupang-outbound-progress.png") });
|
|
releaseUpload();
|
|
await page.locator(".erp-dialog").waitFor({ state: "visible" });
|
|
const done = await page.locator(".erp-dialog").innerText();
|
|
assert.match(done, /'20261026\(월\)' 시트에 입고센터 2곳, 3개 제품을 추가했습니다/);
|
|
assert.match(done, /인천32 — 10~11행 \(2개 제품\)/);
|
|
assert.match(done, /대구3 — 12~12행 \(1개 제품\)/);
|
|
assert.equal(posts[0].stream, "1");
|
|
assert.deepEqual(posts[0].body, {
|
|
document_date: await page.evaluate(() => new Date(Date.now() + 9 * 3600000).toISOString().slice(0, 10)),
|
|
ship_date: "2026-10-26", center_arrival_date: "2026-10-27", worker: "핫프렌즈",
|
|
centers: [
|
|
{ center: "인천32", ship_method: "파렛트", outbound: "2파렛트",
|
|
lines: [{ code: "MT-7000", name: "점보 7,000ml", quantity: "1200" }, { code: "MS-1004", name: "미라네 4호세트", quantity: "60" }] },
|
|
{ center: "대구3", ship_method: "택배", outbound: "",
|
|
lines: [{ code: "MT-3000", name: "중형 3,000ml", quantity: "30" }] },
|
|
],
|
|
});
|
|
assert.ok(await page.locator("#cpg-ol-dlg").isHidden(), "성공하면 팝업 닫힘");
|
|
await page.locator(".erp-dialog button", { hasText: "닫기" }).click();
|
|
|
|
// 다시 열면 카드 1장·빈 상태, 진행 막대 숨김. 직접 입력 센터 + 실패(스트림 중 오류)는 막대 빨강 + 팝업 안 안내
|
|
await openBtn.click();
|
|
assert.equal(await cards.count(), 1);
|
|
assert.equal(await cards.nth(0).locator(".cpg-ol-lines tbody tr").count(), 0);
|
|
assert.equal(await cards.nth(0).locator(".cpg-ol-method").inputValue(), "택배");
|
|
assert.ok(await page.locator("#cpg-ol-progress").isHidden());
|
|
await pickDate(page, "cpg-ol-ship-date", "10/30");
|
|
await pickDate(page, "cpg-ol-arrival-date", "11/2");
|
|
await pickDate(page, "cpg-ol-ship-date", "10/31");
|
|
assert.equal(await page.locator("#cpg-ol-arrival-date").inputValue(), "2026-11-02", "직접 고른 센터입고일은 유지");
|
|
await page.waitForFunction(() => document.querySelectorAll(".cpg-ol-center-sel option").length === 4);
|
|
const f1 = cards.nth(0);
|
|
await f1.locator(".cpg-ol-center-sel").selectOption("__new__");
|
|
await f1.locator(".cpg-ol-center-new").fill("실패센터");
|
|
await addProduct(f1, "중형", 5);
|
|
await page.locator("#cpg-ol-submit").click();
|
|
await page.waitForFunction(() => !document.getElementById("cpg-ol-error").hidden);
|
|
assert.match(await page.locator("#cpg-ol-error").innerText(), /출고리스트 파일에 기록하지 못했습니다/);
|
|
assert.ok(await page.locator("#cpg-ol-progress").evaluate(el => el.classList.contains("is-error")));
|
|
assert.ok(await page.locator("#cpg-ol-dlg").isVisible(), "실패하면 입력 유지");
|
|
assert.equal(await page.locator("#cpg-ol-submit").innerText(), "완료");
|
|
assert.equal(posts[1].body.centers[0].center, "실패센터");
|
|
|
|
// 서버 입력 오류(400, 스트림 전)도 팝업 안에 보여 준다
|
|
await f1.locator(".cpg-ol-center-new").fill("잘못센터");
|
|
await page.locator("#cpg-ol-submit").click();
|
|
await page.waitForFunction(() => /2번째 입고센터/.test(document.getElementById("cpg-ol-error").textContent));
|
|
|
|
// Esc: 날짜 팝업이 떠 있으면 그것만 닫고, 다음 Esc 에 출고리스트 팝업 닫힘
|
|
await page.locator("#cpg-ol-doc-date + .pj-date-btn").click();
|
|
await page.locator(".pj-datepop").waitFor({ state: "visible" });
|
|
await page.waitForTimeout(50); // 날짜 팝업은 다음 틱에 Esc 처리를 건다(project.js openDatePopover)
|
|
await page.keyboard.press("Escape");
|
|
await page.locator(".pj-datepop").waitFor({ state: "detached" });
|
|
assert.ok(await page.locator("#cpg-ol-dlg").isVisible());
|
|
await page.keyboard.press("Escape");
|
|
assert.ok(await page.locator("#cpg-ol-dlg").isHidden());
|
|
|
|
// 좁은 화면에서도 가로 넘침 없음(센터 2장)
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await openBtn.click();
|
|
await page.locator("#cpg-ol-add-center").click();
|
|
const over = await page.evaluate(() => {
|
|
const box = document.querySelector(".cpg-ol-box");
|
|
return box.scrollWidth - box.clientWidth;
|
|
});
|
|
assert.ok(over <= 1, "모바일 팝업 가로 넘침 " + over);
|
|
await page.screenshot({ path: path.join(OUT, "cupang-outbound-mobile.png") });
|
|
|
|
assert.deepEqual(errors, [], "브라우저 JS 오류 없음");
|
|
console.log("ALL PASS — 버튼, 날짜 팝업, 입고센터 카드(추가·삭제·번호·기본 택배), 코드표 검색, 진행 막대·%, 완료·실패, Esc, 모바일");
|
|
} finally {
|
|
if (browser) await browser.close();
|
|
await new Promise(resolve => server.close(resolve));
|
|
}
|
|
})().catch(function (e) { console.error(e); process.exit(1); });
|