import { expect } from '@open-wc/testing' import { render } from 'lit' import { OxGristRendererDate } from '../src/renderers/ox-grist-renderer-date.js' /** * 'YYYY-MM-DD' 는 달력의 날이다. 브라우저가 UTC 서쪽에 있어도 그 날 그대로 나와야 한다. * * 시험 브라우저의 시간대는 고를 수 없으므로, 시간대를 적지 않은 Intl.DateTimeFormat 을 America/Tijuana * 로 돌린다 — 그 시간대의 브라우저가 날짜를 적는 길과 같다. */ const WEST = 'America/Tijuana' function renderText(value: any, type: string): string { const column = { type, record: {} } as any const host = document.createElement('div') render(OxGristRendererDate(value, column, {}, 0, undefined as any) as any, host) return host.textContent!.trim() } describe('OxGristRendererDate — calendar day', () => { const Original = Intl.DateTimeFormat beforeEach(() => { ;(Intl as any).DateTimeFormat = function (locales?: any, options: any = {}) { return new Original(locales, { timeZone: WEST, ...options }) } }) afterEach(() => { ;(Intl as any).DateTimeFormat = Original }) it("renders '2025-12-31' as Dec 31 west of UTC", () => { const expected = new Original(undefined, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: 'UTC' }).format( Date.UTC(2025, 11, 31) ) expect(renderText('2025-12-31', 'date')).to.equal(expected) }) it('still renders a datetime instant in the browser time zone', () => { // 2025-12-31T03:00Z is Dec 30 evening in Tijuana. const text = renderText('2025-12-31T03:00:00Z', 'datetime') const expected = new Original(undefined, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: '2-digit', hour12: false, timeZone: WEST }).format(new Date('2025-12-31T03:00:00Z')) expect(text).to.equal(expected) }) })