This commit is contained in:
skkim committed 2026-09-15 17:21:40 +09:00
commit 4cd756108d
10 files changed
+149 -8

No files matched your search

@@ -11,6 +11,7 @@
*/
import {useSite} from '@site/lib/site-context';
import {useLiveWeather} from '@site/lib/use-live-weather';
import {useWeatherNote} from '@site/lib/use-weather-note';
import {weatherBand, weatherMood} from '@site/lib/derive';
import {Card, Section} from '@site/lib/ui';
import './weather.css';
@@ -32,12 +33,12 @@ export function WeatherSection() {
longitude: payload.place.longitude,
});
if (!weather) return null;
const mood = weatherMood(weather.condition);
const band = weatherBand(weather.temperature);
const mood = weatherMood(weather?.condition ?? '');
const band = weatherBand(weather?.temperature ?? 0);
const notes = payload.local.weather;
const skyKey = weather?.condition === '구름많음' ? '구름많음' : mood;
// 조건별 문장이 우선. 없으면 예전 한 칸(note)으로 떨어진다 — 옛 payload 도 깨지지 않는다.
const line = payload.local.weather?.notes?.[mood] ?? weather.note;
const line = useWeatherNote(notes?.noteSets?.[skyKey], notes?.notes?.[mood] ?? weather?.note);
/*
* ★ 기온 줄 (2026-09-09, 사장님: "기온에 따라서 문구 다르게, 펜션지역의 관광에 맞춰서")
* 하늘 줄은 집 안 이야기(마당·CAFÉ)라 "그래서 오늘 어디를 가지"에는 답하지 않았다.
@@ -45,7 +46,8 @@ export function WeatherSection() {
* ★ 없으면 줄 자체를 그리지 않는다 — 기온대는 항상 계산되지만 문장은 사장님이 적은
* 것뿐이라, 빈 칸을 우리가 채우면 지어낸 관광 안내가 된다.
*/
const bandLine = payload.local.weather?.tempNotes?.[band];
const bandLine = useWeatherNote(notes?.tempNoteSets?.[band], notes?.tempNotes?.[band]);
if (!weather) return null;
const observed = observedText(weather.observedAt);
return (
@@ -0,0 +1,30 @@
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('');
});