/* 맞춤 기본 = 가운데 · 가운데(237-1) 시험 진입 — vite --ssr 로 번들해 Node 로 돌림. * 결과 = JSON {pass, fail, failures} 한 줄(`test_spreadsheet_align_default.py` 가 읽음) */ import { applyCellStyle, shownHAlign, shownVAlign, type ResolvedBorders, } from "../../../A00_Common/spreadsheet/spreadsheet_cellstyle"; import { blockToClipboard } from "../../../A00_Common/spreadsheet/spreadsheet_clipboard"; import type { CellStyle, Workbook } from "../../../A00_Common/spreadsheet/spreadsheet_types"; let pass = 0; const failures: string[] = []; const eq = (name: string, got: unknown, want: unknown): void => { if (JSON.stringify(got) === JSON.stringify(want)) pass += 1; else failures.push(`${name}: ${JSON.stringify(got)} ≠ ${JSON.stringify(want)}`); }; // 도구줄 · 대화상자가 보이는 값 — 안 준 칸(없음 · 일반) = 가운데 · 준 칸 그대로 eq("가로 없음", shownHAlign(undefined), "center"); eq("가로 일반", shownHAlign("general"), "center"); eq("가로 왼쪽", shownHAlign("left"), "left"); eq("가로 오른쪽", shownHAlign("right"), "right"); eq("가로 균등", shownHAlign("distributed"), "distributed"); eq("세로 없음", shownVAlign(undefined), "center"); eq("세로 위", shownVAlign("top"), "top"); eq("세로 아래", shownVAlign("bottom"), "bottom"); // 칸 CSS — 가짜 칸(DOM 없이 style 만 봄) function paint(style: CellStyle, hAlign: Parameters[3]) { const text = { classList: { contains: () => true }, style: {} as Record }; const cell = { style: {} as Record, firstElementChild: text, replaceChildren: () => undefined, }; applyCellStyle(cell as unknown as HTMLElement, style, {} as ResolvedBorders, hAlign); return { v: cell.style.justifyContent, h: text.style.textAlign }; } eq("칸 안 준 = 가운데 · 가운데", paint({}, "general"), { v: "center", h: "center" }); eq("칸 왼쪽 · 아래 그대로", paint({ 세로: "bottom" }, "left"), { v: "flex-end", h: "left" }); eq("칸 오른쪽 · 위 그대로", paint({ 세로: "top" }, "right"), { v: "flex-start", h: "right" }); // 내보내기(복사 HTML) — 안 준 칸 = 가운데 · 가운데 · 준 칸 그대로 const book = { 종류: "통합문서", 판: 1, 열: "rv", 서식: [{}, { 가로: "left", 세로: "top" }], 시트: [{ id: "s1", 이름: "시트1", 칸: { A1: { 값: "가" }, B1: { 값: "나", 서식: 1 } } }], 활성: "s1", } as unknown as Workbook; const { html } = blockToClipboard(book, "s1", { r0: 0, c0: 0, r1: 0, c1: 1 }, (_r, c) => c === 0 ? "가" : "나", ); const tds = [...html.matchAll(/]*style="([^"]*)"/g)].map((m) => m[1]); eq("내보내기 칸 수", tds.length, 2); eq( "내보내기 안 준 칸", /text-align:center/.test(tds[0]) && /vertical-align:middle/.test(tds[0]), true, ); eq("내보내기 준 칸", /text-align:left/.test(tds[1]) && /vertical-align:top/.test(tds[1]), true); console.log(JSON.stringify({ pass, fail: failures.length, failures }));