fix(places): the closed-day tests parse, and the inspector keeps its size

A test title held an unescaped apostrophe, so the file did not parse. The
inspector maps a provider's week through one helper again, which keeps it
at its size baseline, and the counts type of the rail stays inside its file.
This commit is contained in:
Maurice
2026-11-30 13:28:00 +01:00
parent f15b9e73a0
commit 73e3ac2606
4 changed files with 15 additions and 6 deletions
@@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
import { placesLibraryRepo } from '../../repo/placesLibraryRepo';
/** How many places All places holds, and how many of them are saved in a list; each place once. */
export interface LibraryCounts {
interface LibraryCounts {
all: number;
saved: number;
}
@@ -36,7 +36,7 @@ import { TRANSPORT_TYPES, getPlaceBookings } from '../../utils/dayMerge'
import { NavigationMenu } from '../shared/NavigationMenu'
import { centredMapCard, type MapCardPlacement } from '../Map/centredMapCard'
import { resolveOpenNow, resolvePlaceTimeZone, getWeekdayIndex, type OpeningPeriod } from './placeOpenState'
import { closedHoursLine, convertHoursLine } from './placeHoursFormat'
import { closedHoursLines, convertHoursLine } from './placeHoursFormat'
import type { EndDayControlProps } from '../Roadtrip/EndDayControl'
import VisitControls, { type RoadtripStayControl } from '../Roadtrip/VisitControls'
import { DialogButton, DialogIconButton, DialogSection, DeleteButton, FooterSpacer, fs } from '../shared/DialogShell'
@@ -331,8 +331,7 @@ export default function PlaceInspector({
// Hours the traveller typed in win over looked-up ones (#2472): they are what
// somebody actually checked, and a place nobody listed has no other source.
const ownHours = hoursLines(place.opening_hours, locale, t('places.hoursClosed'), t('places.hoursAllDay'))
// A provider's closed day (OSM writes 'off') in the reader's words, as the own hours say it.
const openingHours = ownHours ?? googleDetails?.opening_hours?.map(line => closedHoursLine(line, t('places.hoursClosed'))) ?? null
const openingHours = ownHours ?? closedHoursLines(googleDetails?.opening_hours, t('places.hoursClosed'))
const detailLat = place.lat ?? googleDetails?.lat
const detailLng = place.lng ?? googleDetails?.lng
const placeTimeZone = resolvePlaceTimeZone(detailLat, detailLng)
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { closedHoursLine, convertHoursLine, isUnknownHoursLine, splitHoursLine } from './placeHoursFormat'
import { closedHoursLine, closedHoursLines, convertHoursLine, isUnknownHoursLine, splitHoursLine } from './placeHoursFormat'
describe('convertHoursLine', () => {
it('FE-PLANNER-HOURS-001: a range that stays in one half of the day carries the meridiem back to its opener', () => {
@@ -56,7 +56,7 @@ describe('isUnknownHoursLine', () => {
})
describe('closedHoursLine', () => {
it('FE-PLANNER-HOURS-010: a day OSM tags off or closed reads as closed in the reader's words', () => {
it('FE-PLANNER-HOURS-010: a day OSM tags off or closed reads as closed in the words of the reader', () => {
expect(closedHoursLine('Monday: off', 'Geschlossen')).toBe('Monday: Geschlossen')
expect(closedHoursLine('Sunday: Closed', 'Fermé')).toBe('Sunday: Fermé')
expect(closedHoursLine('off', 'Closed')).toBe('Closed')
@@ -67,4 +67,9 @@ describe('closedHoursLine', () => {
expect(closedHoursLine('Friday: 09:00-12:00 off', 'Closed')).toBe('Friday: 09:00-12:00 off')
expect(closedHoursLine('', 'Closed')).toBe('')
})
it('FE-PLANNER-HOURS-012: a whole week reads its closed days the same way, and no week stays none', () => {
expect(closedHoursLines(['Monday: off', 'Tuesday: 09:00-17:00'], 'Closed')).toEqual(['Monday: Closed', 'Tuesday: 09:00-17:00'])
expect(closedHoursLines(undefined, 'Closed')).toBeNull()
})
})
@@ -89,3 +89,8 @@ export function closedHoursLine(line: string, closedLabel: string): string {
if (!/^(off|closed)$/i.test(times)) return line
return day ? `${day}: ${closedLabel}` : closedLabel
}
/** A provider's whole week with its closed days in the reader's words; null without one. */
export function closedHoursLines(lines: string[] | null | undefined, closedLabel: string): string[] | null {
return lines?.map(line => closedHoursLine(line, closedLabel)) ?? null
}