목업에만 있던 날씨 문구 계약을 제품 payload와 렌더러에 연결한다. 군산 전용 장소를 다른 사업장에 복사하지 않도록 공통 안내를 별도 JSON으로 관리한다. 날씨 변환 단위 테스트 3건, 렌더링 테스트 3건 및 TypeScript·ESLint 통과. 전체 발행 테스트는 깨끗한 renderer 재빌드 후 별도 확인.
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import {expect, it} from 'vitest';
|
|
import {renderToStaticMarkup} from 'react-dom/server';
|
|
import {SiteProvider} from '@site/lib/site-context';
|
|
import {MOONLIGHT_STAY_PAYLOAD} from '@site/fixtures/moonlight-stay';
|
|
import {WeatherSection} from './WeatherSection';
|
|
import type {WeatherSnapshot} from '@o2o/shared';
|
|
|
|
function render(weather?: WeatherSnapshot) {
|
|
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
|
|
payload.local.weather = weather;
|
|
return renderToStaticMarkup(<SiteProvider payload={payload}><WeatherSection /></SiteProvider>);
|
|
}
|
|
|
|
it('uses the first sky and temperature lines for deterministic HTML', () => {
|
|
const weather = {temperature: 30, observedAt: '2026-09-15T12:00', condition: '구름많음', noteSets: {'구름많음': ['구름 첫 줄', '다음 줄']}, tempNoteSets: {'혹서': ['더위 첫 줄']}};
|
|
expect(render(weather)).toContain('구름 첫 줄');
|
|
expect(render(weather)).toContain('더위 첫 줄');
|
|
expect(render(weather)).not.toContain('다음 줄');
|
|
expect(render(weather)).toBe(render(weather));
|
|
});
|
|
|
|
it('preserves legacy single notes', () => {
|
|
const html = render({temperature: 15, observedAt: '2026-09-15T12:00', condition: '비', notes: {'비': '기존 비 안내'}, tempNotes: {'쌀쌀': '겉옷 안내'}});
|
|
expect(html).toContain('기존 비 안내');
|
|
expect(html).toContain('겉옷 안내');
|
|
});
|
|
|
|
it('does not invent weather when an observation is missing', () => {
|
|
expect(render()).toBe('');
|
|
});
|