feat(backend,site): NOL 수집 및 숙박 안내 구조화와 지역 콘텐츠 연동
수집한 객실·이용 정보가 발행 화면에 연결되지 않던 경로를 보완하고, 숙소 소개와 지역 맛집 표시를 개선한다. - NOL 브라우저 수집 어댑터와 수집·반영 스크립트 추가 - 크롤링 fact 즉시 노출 및 직접 입력·정정값 보호 - 이용안내 항목별 구조화와 기존 표 연결, 원문 UI 비표시 - 군산 한일옥 고정 등록과 지역 맛집 탐색·보강 경로 추가 - 숙소 소개 요약, 히어로 문구, 지역 콘텐츠·목업 표시 개선 검증: 작업 트리 기준 site 타입·린트·빌드 및 안내 렌더링 테스트 통과, PC·모바일 화면 확인. 스테이징 diff 공백 검사 통과. 사용자 요청에 따라 현재 스테이징된 55개 파일만 포함하며 미스테이징 문서·테스트 등은 제외.
This commit is contained in:
1 parent
67a1db3cb9
commit
a093921b62
55 files changed
+2325
-269
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import {selectPublishable} from '@o2o/shared';
|
||||
import {useSite} from '@site/lib/site-context';
|
||||
import {factualSummary} from '@site/seo/meta';
|
||||
import {essentialRows} from '@site/lib/derive';
|
||||
@@ -17,7 +18,8 @@ import {formatKoreanDate} from '@site/lib/format';
|
||||
export function AnswerBlock() {
|
||||
const payload = useSite();
|
||||
const rows = essentialRows(payload).slice(0, 6);
|
||||
const summary = payload.narrative.summary ?? factualSummary(payload);
|
||||
const intro = selectPublishable(payload.facts).find((fact) => fact.key === 'intro');
|
||||
const summary = intro?.summary?.trim() || payload.narrative.summary || factualSummary(payload);
|
||||
|
||||
if (rows.length === 0 && !summary) return null;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Phone} from 'lucide-react';
|
||||
import {useSite} from '@site/lib/site-context';
|
||||
import {bookingActionLabel, bookingLinks, essentialRows, RULE_FACT_KEYS} from '@site/lib/derive';
|
||||
import {bookingActionLabel, bookingLinks, essentialRows} from '@site/lib/derive';
|
||||
import {formatKoreanDate} from '@site/lib/format';
|
||||
import type {InfoRow} from '@site/lib/derive';
|
||||
import {Section} from '@site/lib/ui';
|
||||
@@ -43,19 +43,45 @@ const RULE_LABELS = new Set([
|
||||
export function EssentialInfoSection() {
|
||||
const payload = useSite();
|
||||
const rows = essentialRows(payload);
|
||||
const guides = payload.links.filter((link) => link.confirmed &&
|
||||
[link.stayGuide?.policy, link.stayGuide?.service, link.stayGuide?.reservation].some((text) => text?.trim()));
|
||||
const structured = guides.flatMap((link) => link.stayGuide?.fields ?? []);
|
||||
const mergedRows = [...rows];
|
||||
const seen = new Set(rows.map((row) => row.key));
|
||||
for (const field of structured) {
|
||||
// 직접 입력한 노출값을 우선한다. 같은 항목을 출처마다 반복하지 않는다.
|
||||
if (!seen.has(field.key)) {
|
||||
mergedRows.push(field);
|
||||
seen.add(field.key);
|
||||
}
|
||||
}
|
||||
const isRule = (row: InfoRow) => {
|
||||
if (['cooking_allowed', 'smoking'].includes(row.key ?? '')) return false;
|
||||
return RULE_LABELS.has(row.label) || structured.some((field) => field.key === row.key && field.group === 'rules');
|
||||
};
|
||||
const hiddenCount = payload.facts.filter(
|
||||
(fact) => fact.scope === 'place' && !rows.some((row) => row.label === fact.label),
|
||||
).length;
|
||||
|
||||
if (rows.length === 0) return null;
|
||||
if (rows.length === 0 && guides.length === 0) return null;
|
||||
|
||||
/**
|
||||
* 규정과 나머지를 가른다.
|
||||
*
|
||||
* ★ 순서를 뒤집지 않는다 — 규정이 먼저다. 예약 전에 알아야 클레임이 안 난다.
|
||||
*/
|
||||
const ruleRows = rows.filter((row) => RULE_LABELS.has(row.label));
|
||||
const otherRows = rows.filter((row) => !RULE_LABELS.has(row.label));
|
||||
const ruleRows = [
|
||||
...mergedRows.filter(isRule),
|
||||
...guides.filter((link) => !link.stayGuide?.fields?.length && link.stayGuide?.policy).map((link) => ({
|
||||
label: 'NOL 이용 안내', value: link.stayGuide?.policy ?? '',
|
||||
})),
|
||||
];
|
||||
const otherRows = [
|
||||
...mergedRows.filter((row) => !isRule(row)),
|
||||
...guides.filter((link) => !link.stayGuide?.fields?.length && link.stayGuide?.service).map((link) => ({
|
||||
label: 'NOL 시설 안내', value: link.stayGuide?.service ?? '',
|
||||
})),
|
||||
];
|
||||
|
||||
return (
|
||||
<Section
|
||||
@@ -71,7 +97,7 @@ export function EssentialInfoSection() {
|
||||
<span>
|
||||
{hiddenCount > 0
|
||||
? `확인 중인 항목 ${hiddenCount}개는 표시하지 않았습니다. 필요하시면 전화로 문의해 주세요.`
|
||||
: '모든 항목이 사업자 확인을 거쳤습니다.'}
|
||||
: '등록 정보와 수집한 안내를 기준으로 표시합니다.'}
|
||||
</span>
|
||||
<span className="font-medium">{formatKoreanDate(payload.site.updatedAt)} 기준</span>
|
||||
</span>
|
||||
@@ -80,6 +106,11 @@ export function EssentialInfoSection() {
|
||||
<div className="space-y-8">
|
||||
{ruleRows.length > 0 && <Rows title="예약 전 확인" rows={ruleRows} emphasis />}
|
||||
{otherRows.length > 0 && <Rows title="시설 · 편의" rows={otherRows} />}
|
||||
{guides.filter((link) => link.stayGuide?.reservation).map((link) => (
|
||||
<Rows key={`reservation-${link.url}`} title="예약 공지" emphasis rows={[
|
||||
{label: 'NOL 예약 공지', value: link.stayGuide?.reservation ?? ''},
|
||||
]} />
|
||||
))}
|
||||
<BookingRow />
|
||||
</div>
|
||||
</Section>
|
||||
@@ -112,16 +143,16 @@ function Rows({title, rows, emphasis}: {title: string; rows: InfoRow[]; emphasis
|
||||
|
||||
{/* ★ 테두리는 판 하나에만 준다. 줄 사이는 선(divide)이지 상자가 아니다. */}
|
||||
<dl className="divide-line divide-y">
|
||||
{rows.map((row) => (
|
||||
{rows.map((row, index) => (
|
||||
<div
|
||||
key={row.label}
|
||||
key={`${row.label}-${index}`}
|
||||
className="flex flex-col gap-1 py-3.5 sm:flex-row sm:items-baseline sm:gap-6"
|
||||
>
|
||||
<dt className="text-muted text-[length:var(--fs-sm)] sm:w-40 sm:shrink-0">
|
||||
{row.label}
|
||||
</dt>
|
||||
{/* measure: 긴 규정 문장이 화면 끝까지 늘어나면 다음 줄 첫 글자를 못 찾는다. */}
|
||||
<dd className="measure text-[length:var(--fs-sm)] font-semibold">
|
||||
<dd className="measure min-w-0 whitespace-pre-line break-words text-[length:var(--fs-sm)] font-semibold">
|
||||
{row.value}
|
||||
{row.note && <span className="text-muted mt-0.5 block font-normal">{row.note}</span>}
|
||||
</dd>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import {useEffect, useState, type CSSProperties} from 'react';
|
||||
import {PlaceCategory} from '@o2o/shared';
|
||||
import {useSite} from '@site/lib/site-context';
|
||||
import lines from '@site/lib/lodging-catchphrases.json';
|
||||
import './hero-catchphrase.css';
|
||||
|
||||
export function HeroCatchphrase({children}: {children?: string}) {
|
||||
const {place} = useSite();
|
||||
const lodging = place.category === PlaceCategory.LODGING;
|
||||
const [index, setIndex] = useState(0);
|
||||
// 업장 소개는 첫 줄에 고정하고, 공통 감성 문구만 둘째 줄에서 순환한다.
|
||||
const phrases = lines;
|
||||
useEffect(() => {
|
||||
if (!lodging) return;
|
||||
const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
|
||||
const timer = window.setInterval(() => {
|
||||
if (!document.hidden && !motion.matches) setIndex((value) => (value + 1) % phrases.length);
|
||||
}, 6000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [lodging, phrases.length]);
|
||||
|
||||
if (!lodging) return children;
|
||||
const text = phrases[index % phrases.length];
|
||||
return (
|
||||
<span className="hero-catchphrase">
|
||||
{children && <span className="hero-catchphrase-fixed">{children}</span>}
|
||||
<span className="w4d-line w4d-line--in" key={index}>
|
||||
{text.split(/\s+/).map((word, i) => (
|
||||
<span key={i}>{i > 0 && ' '}<span className="w4d-w"><span style={{'--w4d-d': `${i * 55}ms`} as CSSProperties}>{word}</span></span></span>
|
||||
))}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import {HeroCatchphrase} from '@site/sections/HeroCatchphrase';
|
||||
import {useCallback, useEffect, useRef, useState} from 'react';
|
||||
import {ChevronLeft, ChevronRight, Phone} from 'lucide-react';
|
||||
import {useSite} from '@site/lib/site-context';
|
||||
@@ -124,7 +125,7 @@ export function HeroPension() {
|
||||
</h1>
|
||||
{(narrative.tagline ?? narrative.heroSubline) && (
|
||||
<p className="measure mt-3 text-[length:var(--fs-lead)] leading-relaxed opacity-90">
|
||||
{narrative.tagline ?? narrative.heroSubline}
|
||||
<HeroCatchphrase>{narrative.tagline ?? narrative.heroSubline}</HeroCatchphrase>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {HeroCatchphrase} from '@site/sections/HeroCatchphrase';
|
||||
import {ChevronDown, MapPin} from 'lucide-react';
|
||||
import {useSite} from '@site/lib/site-context';
|
||||
import {primaryImage} from '@site/seo/meta';
|
||||
@@ -99,7 +100,7 @@ export function HeroSection() {
|
||||
{/* ★ 한 줄이 없으면 요약이라도 세운다 — 이름만 덩그러니 있는 첫 화면은 안내가 아니다. */}
|
||||
{(narrative.tagline ?? narrative.heroSubline ?? narrative.summary) && (
|
||||
<p className="measure mt-3 text-[length:var(--fs-lead)] leading-relaxed opacity-85">
|
||||
{narrative.tagline ?? narrative.heroSubline ?? narrative.summary}
|
||||
<HeroCatchphrase>{narrative.tagline ?? narrative.heroSubline ?? narrative.summary}</HeroCatchphrase>
|
||||
</p>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {HeroCatchphrase} from '@site/sections/HeroCatchphrase';
|
||||
import {Phone} from 'lucide-react';
|
||||
import {useSite} from '@site/lib/site-context';
|
||||
import {bookingActionLabel, bookingLinks, heroFacts, lowestPrice, placeRow} from '@site/lib/derive';
|
||||
@@ -59,7 +60,7 @@ export function HeroSplit() {
|
||||
{place.name}
|
||||
</h1>
|
||||
<p className="measure mt-3 text-[length:var(--fs-lead)] leading-relaxed opacity-80">
|
||||
{narrative.tagline ?? narrative.heroSubline ?? narrative.summary}
|
||||
<HeroCatchphrase>{narrative.tagline ?? narrative.heroSubline ?? narrative.summary}</HeroCatchphrase>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -47,6 +47,16 @@ function meters(text: string | undefined): number {
|
||||
return Number(m[1]) * (m[2].toLowerCase() === 'km' ? 1000 : 1);
|
||||
}
|
||||
|
||||
function distanceOf(place: LocalPlace): number {
|
||||
// 숫자가 없는 옛 payload만 표기 문자열로 복원한다.
|
||||
if (place.distanceMeters != null) {
|
||||
return Number.isFinite(place.distanceMeters) && place.distanceMeters >= 0
|
||||
? place.distanceMeters
|
||||
: Infinity;
|
||||
}
|
||||
return meters(place.distanceText);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주변 정보.
|
||||
*
|
||||
@@ -68,11 +78,11 @@ export function LocalGuideSection() {
|
||||
|
||||
const all = [...local.restaurants, ...local.attractions];
|
||||
const count = (r: (typeof RANGES)[number]) =>
|
||||
all.filter((place) => r.test(meters(place.distanceText))).length;
|
||||
all.filter((place) => r.test(distanceOf(place))).length;
|
||||
// 비었거나 전체와 똑같은 탭은 세우지 않는다 — 눌러도 그대로인 탭은 고장으로 읽힌다.
|
||||
const ranges = RANGES.filter((r, i) => i === 0 || (count(r) > 0 && count(r) < all.length));
|
||||
const active = ranges.find((r) => r.id === range) ?? RANGES[0];
|
||||
const within = (place: LocalPlace) => active.test(meters(place.distanceText));
|
||||
const within = (place: LocalPlace) => active.test(distanceOf(place));
|
||||
|
||||
return (
|
||||
<Section
|
||||
@@ -201,7 +211,7 @@ function PlaceList({
|
||||
)}
|
||||
{/* 거리는 사진 위에 얹는다 — 손님이 카드에서 제일 먼저 찾는 값이다.
|
||||
★ 분을 앞에, 거리를 뒤에. 답이 '분'이고 'm' 는 그 근거다. */}
|
||||
{place.distanceText && (
|
||||
{(Number.isFinite(distanceOf(place)) || place.distanceText) && (
|
||||
<span
|
||||
className="absolute bottom-2 left-2 rounded-md px-2 py-0.5 text-[length:var(--fs-xs)] font-bold"
|
||||
style={{
|
||||
@@ -209,7 +219,7 @@ function PlaceList({
|
||||
color: 'var(--tpl-bg, #fff)',
|
||||
}}
|
||||
>
|
||||
{walkText(meters(place.distanceText)) ?? place.distanceText}
|
||||
{walkText(distanceOf(place)) ?? place.distanceText}
|
||||
<span className="ml-1 font-normal opacity-70">{place.distanceText}</span>
|
||||
</span>
|
||||
)}
|
||||
@@ -217,6 +227,9 @@ function PlaceList({
|
||||
|
||||
<span className="flex flex-1 flex-col gap-1 p-3.5">
|
||||
<span className="text-[length:var(--fs-sm)] font-bold">{place.name}</span>
|
||||
{place.location && (
|
||||
<span className="text-muted text-[length:var(--fs-xs)] break-words">{place.location}</span>
|
||||
)}
|
||||
{place.description && (
|
||||
<span className="text-muted line-clamp-3 text-[length:var(--fs-xs)] leading-relaxed">
|
||||
{place.description}
|
||||
@@ -245,10 +258,11 @@ function PlaceList({
|
||||
<span>
|
||||
{' '}
|
||||
{place.distanceText}
|
||||
{walkText(meters(place.distanceText)) && ` · ${walkText(meters(place.distanceText))}`}
|
||||
{walkText(distanceOf(place)) && ` · ${walkText(distanceOf(place))}`}
|
||||
</span>
|
||||
)}
|
||||
{place.description && <p>{place.description}</p>}
|
||||
{place.location && <p>{place.location}</p>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
.hero-catchphrase { display: block; }
|
||||
.hero-catchphrase-fixed { display: block; }
|
||||
.hero-catchphrase .w4d-line { display: block; margin-top: 0.5rem; min-height: 1.5em; word-break: keep-all; }
|
||||
.hero-catchphrase .w4d-w { display: inline-block; overflow: hidden; vertical-align: bottom; }
|
||||
.hero-catchphrase .w4d-w > span { display: inline-block; animation: lodging-word-in 0.45s both; animation-delay: var(--w4d-d); }
|
||||
@keyframes lodging-word-in {
|
||||
from { opacity: 0; transform: translateY(100%); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.hero-catchphrase .w4d-w > span { animation: none; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import {expect, it} from 'vitest';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {PlaceCategory} from '@o2o/shared';
|
||||
import {SiteProvider} from '@site/lib/site-context';
|
||||
import {MOONLIGHT_STAY_PAYLOAD} from '@site/fixtures/moonlight-stay';
|
||||
import lines from '@site/lib/lodging-catchphrases.json';
|
||||
import {HeroCatchphrase} from './HeroCatchphrase';
|
||||
|
||||
it('keeps the original lodging tagline in the static HTML', () => {
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={MOONLIGHT_STAY_PAYLOAD}><HeroCatchphrase>고유문구</HeroCatchphrase></SiteProvider>);
|
||||
expect(html).toContain('<span class="hero-catchphrase-fixed">고유문구</span>');
|
||||
expect(html).toContain('w4d-line--in');
|
||||
const text = html.replace(/<[^>]+>/g, '');
|
||||
expect(text).toContain('고유문구' + lines[0]);
|
||||
});
|
||||
|
||||
it('does not add lodging copy or controls to another category', () => {
|
||||
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
|
||||
payload.place.category = PlaceCategory.CAFE;
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}><HeroCatchphrase>카페 소개</HeroCatchphrase></SiteProvider>);
|
||||
expect(html).toBe('카페 소개');
|
||||
});
|
||||
|
||||
it('ships ten distinct short phrases', () => {
|
||||
expect(new Set(lines).size).toBe(10);
|
||||
expect(lines.every((line) => line.length >= 15 && line.length <= 30)).toBe(true);
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import {expect, it} from 'vitest';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {FactStatus, SourceType, type SitePayload} from '@o2o/shared';
|
||||
import {SiteProvider} from '@site/lib/site-context';
|
||||
import {MOONLIGHT_STAY_PAYLOAD} from '@site/fixtures/moonlight-stay';
|
||||
import {AnswerBlock} from './AnswerBlock';
|
||||
import {EssentialInfoSection} from './EssentialInfoSection';
|
||||
import {AboutSection} from './AboutSection';
|
||||
|
||||
function fixture(summary?: string): SitePayload {
|
||||
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
|
||||
payload.facts = [{
|
||||
key: 'intro', label: '숙소 소개', value: '숙소 소개 전체 원문입니다.', summary,
|
||||
scope: 'place', type: 'text', status: FactStatus.VERIFIED,
|
||||
sourceType: SourceType.LLM, critical: false, required: false,
|
||||
}];
|
||||
payload.narrative = {about: ['숙소 소개 전체 원문입니다.'], summary: '기존 첫 문장'};
|
||||
return payload;
|
||||
}
|
||||
|
||||
it('shows the same summary in both booking information sections', () => {
|
||||
const payload = fixture('짧게 요약한 숙소 소개');
|
||||
for (const section of [<AnswerBlock />, <EssentialInfoSection />]) {
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}>{section}</SiteProvider>);
|
||||
expect(html).toContain('짧게 요약한 숙소 소개');
|
||||
expect(html).not.toContain('숙소 소개 전체 원문입니다.');
|
||||
}
|
||||
const about = renderToStaticMarkup(<SiteProvider payload={payload}><AboutSection /></SiteProvider>);
|
||||
expect(about).toContain('숙소 소개 전체 원문입니다.');
|
||||
});
|
||||
|
||||
it.each([undefined, ' '])('keeps original text when summary is %s', (summary) => {
|
||||
const payload = fixture(summary);
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}><EssentialInfoSection /></SiteProvider>);
|
||||
expect(html).toContain('숙소 소개 전체 원문입니다.');
|
||||
});
|
||||
|
||||
it('does not expose summaries from unverified facts', () => {
|
||||
const payload = fixture('검증 안 된 요약');
|
||||
payload.facts[0].status = FactStatus.UNVERIFIED;
|
||||
for (const section of [<AnswerBlock />, <EssentialInfoSection />]) {
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}>{section}</SiteProvider>);
|
||||
expect(html).not.toContain('검증 안 된 요약');
|
||||
}
|
||||
});
|
||||
@@ -15,7 +15,6 @@ import {useState} from 'react';
|
||||
import {useSite} from '@site/lib/site-context';
|
||||
import {sectionItems, sectionName} from '@site/lib/derive';
|
||||
import {SongsSection} from './SongsSection';
|
||||
import {DailySection} from './DailySection';
|
||||
import {PeopleSection} from './PeopleSection';
|
||||
import {ChronicleSection} from './ChronicleSection';
|
||||
import {PostcardSection} from './PostcardSection';
|
||||
@@ -30,7 +29,6 @@ const COUNT_WORD: Record<number, string> = {1: '한', 2: '두', 3: '세', 4: '
|
||||
|
||||
const TABS = [
|
||||
{id: 'songs', label: '가요 다방', Component: SongsSection},
|
||||
{id: 'daily', label: '오늘의 한 장', Component: DailySection},
|
||||
{id: 'people', label: '인물 열전', Component: PeopleSection},
|
||||
{id: 'chronicle', label: '시간의 골목', Component: ChronicleSection},
|
||||
{id: 'postcard', label: '오늘의 엽서', Component: PostcardSection},
|
||||
@@ -38,6 +36,7 @@ const TABS = [
|
||||
|
||||
export function StorySection() {
|
||||
const payload = useSite();
|
||||
const title = sectionName(payload, 'story', `${payload.place.addressLocality ?? '지역'} 이야기`);
|
||||
// 데이터가 있는 것만 탭이 된다 — 눌러서 빈 화면을 보게 하지 않는다.
|
||||
const tabs = TABS.filter((tab) => sectionItems(payload, tab.id).items.length > 0);
|
||||
const [active, setActive] = useState(0);
|
||||
@@ -65,13 +64,13 @@ export function StorySection() {
|
||||
>
|
||||
<div className="shell">
|
||||
<h2 id="story-heading" className="h2">
|
||||
{sectionName(payload, 'story', '군산 이야기')}
|
||||
{title}
|
||||
</h2>
|
||||
<p className="measure mt-3 text-[length:var(--fs-sm)] opacity-70">
|
||||
이 도시를 {COUNT_WORD[tabs.length] ?? `${tabs.length}`} 갈래로 봅니다. 하나씩 골라 보세요.
|
||||
</p>
|
||||
|
||||
<div className="mt-6 flex flex-wrap gap-1.5" role="tablist" aria-label="군산 이야기">
|
||||
<div className="mt-6 flex flex-wrap gap-1.5" role="tablist" aria-label={title}>
|
||||
{tabs.map((tab, index) => {
|
||||
const on = index === active;
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
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 {LocalGuideSection} from './LocalGuideSection';
|
||||
|
||||
it('renders collected descriptions and addresses with numeric distance filters', () => {
|
||||
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
|
||||
payload.local.attractions = [];
|
||||
payload.local.restaurants = [
|
||||
{name: 'Cafe A', category: 'cafe', searchQuery: 'Cafe A', location: 'Address A',
|
||||
description: 'Collected description', distanceMeters: 401, distanceText: '400m'},
|
||||
{name: 'Cafe B', category: 'cafe', searchQuery: 'Cafe B', distanceMeters: 100},
|
||||
{name: 'Cafe C', category: 'cafe', searchQuery: 'Cafe C'},
|
||||
];
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}><LocalGuideSection /></SiteProvider>);
|
||||
expect(html).toContain('Collected description');
|
||||
expect(html).toContain('Address A');
|
||||
expect(html).toMatch(/걸어서 5분 이내 <span[^>]*>1<\/span>/);
|
||||
expect(html).toContain('Cafe C');
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import {expect, it} from 'vitest';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {sanitizePayloadForPublish, FactStatus, SourceType} from '@o2o/shared';
|
||||
import {SiteProvider} from '@site/lib/site-context';
|
||||
import {MOONLIGHT_STAY_PAYLOAD} from '@site/fixtures/moonlight-stay';
|
||||
import {EssentialInfoSection} from './EssentialInfoSection';
|
||||
|
||||
function fixture(confirmed = true) {
|
||||
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
|
||||
payload.facts = [];
|
||||
payload.links = [{
|
||||
channel: 1, title: 'NOL', url: 'https://nol.yanolja.com/stay/domestic/10068088', confirmed,
|
||||
stayGuide: {
|
||||
policy: '체크인 15:00 체크아웃 11:00\n전 연령 동일 1인당 2만원',
|
||||
service: '주방\n욕조',
|
||||
reservation: '- 반려동물 입실금지\n<script>alert(1)</script>',
|
||||
},
|
||||
}];
|
||||
return payload;
|
||||
}
|
||||
|
||||
it('renders guides without facts, before booking actions, preserving line breaks and escaping HTML', () => {
|
||||
const payload = fixture();
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}><EssentialInfoSection /></SiteProvider>);
|
||||
expect(html).toContain('예약 전 확인');
|
||||
expect(html).toContain('체크인 15:00 체크아웃 11:00\n전 연령 동일 1인당 2만원');
|
||||
expect(html).toContain('주방\n욕조');
|
||||
expect(html).toContain('반려동물 입실금지');
|
||||
expect(html).toContain('whitespace-pre-line');
|
||||
expect(html).toContain('<script>');
|
||||
expect(html).not.toContain('<script>');
|
||||
expect(html).not.toContain('모든 항목이 사업자 확인');
|
||||
expect(html.indexOf('반려동물 입실금지')).toBeLessThan(html.indexOf('예약은 아래로'));
|
||||
});
|
||||
|
||||
it('does not render or embed guides from unconfirmed links', () => {
|
||||
const payload = fixture(false);
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}><EssentialInfoSection /></SiteProvider>);
|
||||
expect(html).toBe('');
|
||||
expect(JSON.stringify(sanitizePayloadForPublish(payload))).not.toContain('반려동물 입실금지');
|
||||
});
|
||||
|
||||
it('supports older payloads without guides', () => {
|
||||
const payload = fixture();
|
||||
delete payload.links[0].stayGuide;
|
||||
expect(renderToStaticMarkup(<SiteProvider payload={payload}><EssentialInfoSection /></SiteProvider>)).toBe('');
|
||||
});
|
||||
|
||||
it('keeps structured rows and restrictions without the original disclosure or source link', () => {
|
||||
const payload = fixture();
|
||||
payload.facts = [{key: 'check_in_time', label: '체크인 시간', value: '16:00',
|
||||
scope: 'place', type: 'time', status: FactStatus.CORRECTED, sourceType: SourceType.OWNER,
|
||||
critical: true, required: true}];
|
||||
payload.links[0].stayGuide!.fields = [
|
||||
{key: 'check_in_time', label: '체크인 시간', value: '15:00', group: 'rules'},
|
||||
{key: 'extra_person_fee', label: '인원 추가 요금', value: '20,000원', note: '1인당 · 전 연령 동일', group: 'rules'},
|
||||
{key: 'cooking_allowed', label: '취사', value: '가능', note: '생선구이 조리금지', group: 'facilities'},
|
||||
];
|
||||
const html = renderToStaticMarkup(<SiteProvider payload={payload}><EssentialInfoSection /></SiteProvider>);
|
||||
expect(html.match(/체크인 시간/g)).toHaveLength(1);
|
||||
expect(html).toContain('16:00');
|
||||
expect(html).toContain('20,000원');
|
||||
expect(html).toContain('1인당 · 전 연령 동일');
|
||||
expect(html).toContain('생선구이 조리금지');
|
||||
expect(html).not.toContain('<details');
|
||||
expect(html).not.toContain('NOL 이용안내 · 시설 원문');
|
||||
expect(html).not.toContain('NOL 안내 원문');
|
||||
expect(html).not.toContain('체크인 15:00 체크아웃 11:00');
|
||||
expect(html).toContain('반려동물 입실금지');
|
||||
expect(html).toContain('예약은 아래로');
|
||||
});
|
||||
Reference in new issue
Block a user