Files
tasteby/frontend/__tests__/region.test.ts
joungmin 622ea58cd1 [QA] #532 formatRegion 검증 통과 — 단위 테스트 추가
- frontend/__tests__/region.test.ts: 설계서(docs/design/532-region-display)
  엣지케이스 8종(falsy/계층조인/null토큰/빈토큰/더미제거/단일토큰/전량더미/trim) 검증
- tsc --noEmit, jest 전체 스위트 통과 확인
- 실제 dev DB region 데이터로 엣지케이스 재확인

Refs #532
2026-07-27 13:49:26 +09:00

45 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* #532 — formatRegion() 순수 함수 단위 테스트.
* 설계서: docs/design/532-region-display/README.md
*/
import { formatRegion } from "@/lib/region";
describe("formatRegion", () => {
it("falsy 입력은 빈 문자열", () => {
expect(formatRegion("")).toBe("");
expect(formatRegion(null)).toBe("");
expect(formatRegion(undefined)).toBe("");
});
it("파이프 구분 지역을 계층(breadcrumb)으로 변환한다", () => {
expect(formatRegion("한국|서울|강남구")).toBe("한국 서울 강남구");
});
it("'null' 토큰(대소문자 무시)은 제거한다", () => {
expect(formatRegion("일본|null")).toBe("일본");
expect(formatRegion("일본|NULL")).toBe("일본");
});
it("빈 토큰은 제거한다", () => {
expect(formatRegion("한국||관악구")).toBe("한국 관악구");
});
it("더미 토큰 '나라'는 제거한다", () => {
expect(formatRegion("나라|서울")).toBe("서울");
});
it("단일 토큰은 그대로 반환한다", () => {
expect(formatRegion("한국")).toBe("한국");
});
it("모든 토큰이 더미/빈 값이면 빈 문자열", () => {
expect(formatRegion("한국|")).toBe("한국");
expect(formatRegion("|")).toBe("");
expect(formatRegion("나라|null|")).toBe("");
});
it("토큰 앞뒤 공백은 trim 된다", () => {
expect(formatRegion(" 한국 | 서울 ")).toBe("한국 서울");
});
});