Files
page-builder/tests/unit/styleInvariants.ts
jaybe 1f085bd64c
CI / test (push) Failing after 44m2s
CI / pr_and_merge (push) Has been skipped
스타일 수정
2025-11-29 15:11:49 +09:00

35 lines
1.3 KiB
TypeScript

import { expect } from "vitest";
// 스타일 관련 인변언트(전역 규칙)를 검증하기 위한 공통 테스트 유틸리티.
// - 퍼블릭/익스포트 토큰에서 px 단위 값 사용을 금지하거나,
// - border-width 등 꼭 필요한 px 사용만 예외로 허용할 때 사용한다.
export type StyleObject = Record<string, unknown>;
export function expectNoPxInStyleObject(style: unknown, options?: { allowKeys?: string[] }) {
if (!style || typeof style !== "object") return;
const allow = new Set(options?.allowKeys ?? []);
for (const [key, value] of Object.entries(style as StyleObject)) {
if (value == null) continue;
if (allow.has(key)) continue;
if (typeof value === "object") continue;
const str = String(value);
expect(str).not.toContain("px");
}
}
export function expectNoPxInStyleString(style: string | undefined | null, options?: { allowPatterns?: RegExp[] }) {
if (!style) return;
const allowPatterns = options?.allowPatterns ?? [];
if (allowPatterns.some((re) => re.test(style))) return;
expect(style).not.toContain("px");
}
export function expectNoPxInStyleParts(parts: string[] | undefined | null, options?: { allowPatterns?: RegExp[] }) {
if (!parts || parts.length === 0) return;
const combined = parts.join(";");
expectNoPxInStyleString(combined, options);
}