2f31604c4e
- 출고리스트 문서(1J74op7lBZOgE27p4R28I3RWsv0EtXdii)는 구글 시트가 아니라 드라이브에 올린 .xlsx 라 Sheets API 로는 쓸 수 없었다 → app/integrations/drive_xlsx.py 추가: 내려받아 openpyxl 로 고친 뒤 같은 파일 id 에 다시 올림(GoogleSheetsWriter 와 같은 메서드, lock 블록 = 내려받기·올리기 1번씩) - 올리기 직전 파일 version 이 바뀌었으면 덮어쓰지 않고 처음부터 다시(최대 3번) - router._sheet_target: 드라이브에서 형식을 보고 xlsx/구글 시트 writer 선택, CUPANG_SHEET_ID 기본값 = 위 파일 (출고리스트 작성 팝업과 분배 확정·출고 삭제 동기화 모두 적용) - 팝업 문구 "구글 시트" → "출고리스트 엑셀", cupang-outbound.js 캐시 버전 올림 - 테스트: 가짜 Drive 에 진짜 xlsx 를 두고 덧붙이기·양식 생성·충돌 재시도·시트 삭제·범위 읽기·writer 선택 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
191 lines
11 KiB
JavaScript
191 lines
11 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 = [];
|
|
|
|
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));
|
|
}
|
|
|
|
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(body);
|
|
if (body.center === "실패센터") return json(res, 502, { detail: "출고리스트 파일에 기록하지 못했습니다(HttpError). 잠시 후 다시 시도해 주세요." });
|
|
json(res, 200, { ok: true, title: "20261026(월)", first_row: 10, last_row: 11, line_count: body.lines.length,
|
|
url: "https://docs.google.com/spreadsheets/d/x/edit#gid=1", created: false });
|
|
});
|
|
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 () {
|
|
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)");
|
|
await page.screenshot({ path: path.join(OUT, "cupang-outbound-button.png"), clip: { x: 0, y: 0, width: 1600, height: 260 } });
|
|
|
|
// 팝업 열기 — 작성일 = 오늘(프로젝트 날짜 버튼), 작업자 = 핫프렌즈
|
|
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오늘".replace("\n", "\n"));
|
|
assert.equal(await page.locator("#cpg-ol-worker").inputValue(), "핫프렌즈");
|
|
assert.equal(await page.locator("#cpg-ol-method").inputValue(), "파렛트");
|
|
assert.deepEqual(await page.locator("#cpg-ol-method option").allInnerTexts(), ["파렛트", "택배"]);
|
|
await page.waitForFunction(() => document.querySelectorAll("#cpg-ol-center option").length === 4);
|
|
assert.deepEqual(await page.locator("#cpg-ol-center option").allInnerTexts(), ["센터 선택", "대구3", "인천32", "+ 직접 입력"]);
|
|
|
|
// 출고일 → 센터입고일은 다음날로 자동
|
|
await pickDate(page, "cpg-ol-ship-date", "2026-10-26");
|
|
assert.equal(await page.locator("#cpg-ol-ship-date").inputValue(), "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\(월\)/);
|
|
|
|
// 필수값 확인
|
|
await page.locator("#cpg-ol-submit").click();
|
|
assert.equal(await page.locator("#cpg-ol-error").innerText(), "입고센터를 선택해 주세요.");
|
|
await page.locator("#cpg-ol-center").selectOption("인천32");
|
|
await page.locator("#cpg-ol-submit").click();
|
|
assert.equal(await page.locator("#cpg-ol-error").innerText(), "제품을 1개 이상 추가해 주세요.");
|
|
assert.ok(!(await page.locator(".cpg-ol-lines").isVisible()), "제품이 없으면 표를 숨김");
|
|
|
|
// 코드표 검색 → Enter 로 첫 결과, 클릭으로 다음 결과
|
|
await page.locator("#cpg-ol-search").fill("점보");
|
|
assert.deepEqual(await page.locator(".cpg-ol-hit b").allInnerTexts(), ["MT-7000"]);
|
|
await page.locator("#cpg-ol-search").press("Enter");
|
|
await page.locator(".cpg-ol-qty").first().fill("1200");
|
|
await page.locator("#cpg-ol-search").fill("ms-");
|
|
await page.locator(".cpg-ol-hit", { hasText: "MS-1004" }).click();
|
|
assert.equal(await page.locator("#cpg-ol-lines tr").count(), 2);
|
|
assert.deepEqual(await page.locator("#cpg-ol-lines tr td:nth-child(2)").allInnerTexts(), ["점보 7,000ml", "미라네 4호세트"]);
|
|
await page.locator("#cpg-ol-submit").click();
|
|
assert.equal(await page.locator("#cpg-ol-error").innerText(), "미라네 4호세트의 수량을 입력해 주세요.");
|
|
await page.locator(".cpg-ol-qty").nth(1).fill("60");
|
|
// 같은 제품을 또 고르면 줄을 늘리지 않고 그 수량 칸으로
|
|
await page.locator("#cpg-ol-search").fill("MT-7000");
|
|
await page.locator("#cpg-ol-search").press("Enter");
|
|
assert.equal(await page.locator("#cpg-ol-lines tr").count(), 2);
|
|
await page.locator("#cpg-ol-outbound").fill("2파렛트");
|
|
await page.screenshot({ path: path.join(OUT, "cupang-outbound-dialog.png") });
|
|
|
|
// 완료 → 서버로 보낸 값, 성공 안내
|
|
await page.locator("#cpg-ol-submit").click();
|
|
await page.locator(".erp-dialog").waitFor({ state: "visible" });
|
|
assert.match(await page.locator(".erp-dialog").innerText(), /'20261026\(월\)' 시트 10~11행에 2개 제품을 추가했습니다/);
|
|
assert.deepEqual(posts[0], {
|
|
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", center: "인천32", ship_method: "파렛트",
|
|
outbound: "2파렛트", worker: "핫프렌즈",
|
|
lines: [{ code: "MT-7000", name: "점보 7,000ml", quantity: "1200" }, { code: "MS-1004", name: "미라네 4호세트", quantity: "60" }],
|
|
});
|
|
assert.ok(await page.locator("#cpg-ol-dlg").isHidden(), "성공하면 팝업 닫힘");
|
|
await page.screenshot({ path: path.join(OUT, "cupang-outbound-done.png") });
|
|
await page.locator(".erp-dialog button", { hasText: "닫기" }).click();
|
|
|
|
// 다시 열면 비어 있고, 센터 직접 입력 + 실패 응답은 팝업 안에 보여 준다
|
|
await openBtn.click();
|
|
assert.equal(await page.locator("#cpg-ol-lines tr").count(), 0);
|
|
assert.equal(await page.locator("#cpg-ol-ship-date").inputValue(), "");
|
|
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 option").length === 4);
|
|
await page.locator("#cpg-ol-center").selectOption("__new__");
|
|
await page.locator("#cpg-ol-center-new").fill("실패센터");
|
|
await page.locator("#cpg-ol-method").selectOption("택배");
|
|
await page.locator("#cpg-ol-search").fill("중형");
|
|
await page.locator("#cpg-ol-search").press("Enter");
|
|
await page.locator(".cpg-ol-qty").first().fill("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-dlg").isVisible(), "실패하면 입력 유지");
|
|
assert.equal(posts[1].center, "실패센터");
|
|
assert.equal(posts[1].ship_method, "택배");
|
|
|
|
// 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());
|
|
|
|
// 좁은 화면에서도 가로 넘침 없음
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await openBtn.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); });
|