import test from 'node:test' import assert from 'node:assert/strict' import { formatAnalyticsCount, getActivePageHref, getActivePageTitle, getRealtimePages } from '../lib/analytics-display.js' test('통계 수치는 천 단위 쉼표와 빈 값 보정을 제공한다', () => { assert.equal(formatAnalyticsCount(10413), '10,413') assert.equal(formatAnalyticsCount('1234567'), '1,234,567') assert.equal(formatAnalyticsCount(null), '0') assert.equal(formatAnalyticsCount(NaN), '0') }) test('실시간 페이지는 최근 확인순으로 같은 경로를 중복 제거한다', () => { const pages = getRealtimePages({ pages: [ { path: '/post/a', postTitle: '이전 제목', lastSeenAt: '2026-10-21T00:00:00Z' }, { path: '/post/b', postTitle: '두 번째', lastSeenAt: '2026-10-21T01:00:00Z' }, { path: '/post/a', postTitle: '최신 제목', lastSeenAt: '2026-10-21T02:00:00Z' } ] }) assert.equal(pages.length, 2) assert.equal(pages[0].postTitle, '최신 제목') assert.equal(getActivePageTitle({ path: '/' }), '홈') assert.equal(getRealtimePages({ path: '/', pages: [] }).length, 1) }) test('실시간 바로가기는 공개 내부 경로만 사용한다', () => { assert.equal(getActivePageHref({ postSlug: '한글 제목' }), '/post/%ED%95%9C%EA%B8%80%20%EC%A0%9C%EB%AA%A9') assert.equal(getActivePageHref({ path: '/' }), '/') for (const path of ['//example.com', '/\\example.com', '/admin', '/admin/settings', 'https://example.com']) { assert.equal(getActivePageHref({ path }), '') } })