Files
TREK/client/src/components/Collab/CollabNotes.helpers.test.ts
T
Maurice 31859651d7 feat(help): rewrite the help center for v5 with a Tours section, new pictures in every language, and fix the tour planner bugs it surfaced
Every help screen checked against the v5 redesign. Tours is documented for
the first time, as a screen of its own with twelve screens under it, and
notifications get help of their own. All pictures are taken again on a
realistic demo trip, with short loops where a still cannot show the motion.
The English is plain and every language is written naturally rather than
word for word.

The switcher shows two levels at most, a screen's overview lists its
sub-screens as cards above its guides, each wiki page is linked once, and
the help sidebar is wider.

Fixes found along the way: Save to Collection keeps a tour's route, a track
dropped on the places column opens the Tours import, tour Share on desktop,
the unsaved tour draft lives on the account, a route click no longer adds
an end point, Trip places leaves the trip's tours out, Escape closes a
stage's day menu, confirms before destructive deletes, DWD warnings sharing
one id kept apart, a booking's date moves with it, and smaller fixes across
notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and
the admin screens.
2026-10-22 22:29:35 +02:00

87 lines
3.6 KiB
TypeScript

// FE-W4CNH-001 to FE-W4CNH-008
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
import { formatTimestamp, originalCategoryName, planCategoryColorSave } from './CollabNotes.helpers'
// The helper feeds t() with a key and params; echo them so the branches are visible.
const t = (key: string, params?: Record<string, number>) =>
params ? `${key}:${Object.values(params)[0]}` : key
const NOW = new Date('2026-06-15T12:00:00Z')
beforeAll(() => {
vi.useFakeTimers()
vi.setSystemTime(NOW)
})
afterAll(() => {
vi.useRealTimers()
})
function ago(minutes: number): string {
return new Date(NOW.getTime() - minutes * 60_000).toISOString().replace('Z', '')
}
describe('formatTimestamp', () => {
it('FE-W4CNH-001: renders an empty string for a missing timestamp', () => {
expect(formatTimestamp(null, t, 'en')).toBe('')
expect(formatTimestamp('', t, 'en')).toBe('')
})
it('FE-W4CNH-002: labels the last minute as just now', () => {
expect(formatTimestamp(ago(0), t, 'en')).toBe('collab.chat.justNow')
})
it('FE-W4CNH-003: counts minutes below the hour', () => {
expect(formatTimestamp(ago(5), t, 'en')).toBe('collab.chat.minutesAgo:5')
expect(formatTimestamp(ago(59), t, 'en')).toBe('collab.chat.minutesAgo:59')
})
it('FE-W4CNH-004: counts hours below the day', () => {
expect(formatTimestamp(ago(60), t, 'en')).toBe('collab.chat.hoursAgo:1')
expect(formatTimestamp(ago(60 * 23), t, 'en')).toBe('collab.chat.hoursAgo:23')
})
it('FE-W4CNH-005: counts days below a week', () => {
expect(formatTimestamp(ago(60 * 24), t, 'en')).toBe('collab.notes.daysAgo:1')
expect(formatTimestamp(ago(60 * 24 * 6), t, 'en')).toBe('collab.notes.daysAgo:6')
})
it('FE-W4CNH-006: falls back to a localized short date beyond a week', () => {
expect(formatTimestamp(ago(60 * 24 * 10), t, 'en-US')).toBe('Jun 5')
})
it('FE-W4CNH-007: treats a naive timestamp as UTC and accepts an explicit Z', () => {
const withZ = new Date(NOW.getTime() - 5 * 60_000).toISOString()
expect(formatTimestamp(withZ, t, 'en')).toBe('collab.chat.minutesAgo:5')
})
it('FE-W4CNH-008: falls back to English labels when the translation is missing', () => {
const empty = () => ''
expect(formatTimestamp(ago(0), empty, 'en')).toBe('just now')
expect(formatTimestamp(ago(5), empty, 'en')).toBe('5m ago')
expect(formatTimestamp(ago(120), empty, 'en')).toBe('2h ago')
expect(formatTimestamp(ago(60 * 24 * 2), empty, 'en')).toBe('2d ago')
})
})
describe('category colour save', () => {
const notes = [{ id: 1, category: 'Food' }, { id: 2, category: 'Food' }, { id: 3, category: 'Sights' }]
it('FE-W4CNH-009: a rename and a new colour in one Save recolour the notes under the old name', () => {
const plan = planCategoryColorSave(notes, { Food: '#ef4444', Sights: '#3b82f6' }, { Dinner: '#10b981', Sights: '#3b82f6' }, { Food: 'Dinner' })
expect(plan.updates).toEqual([{ noteId: 1, color: '#10b981' }, { noteId: 2, color: '#10b981' }])
expect(plan.emptyCategories).toEqual({})
})
it('FE-W4CNH-010: only a category without notes is kept as an empty one', () => {
const plan = planCategoryColorSave(notes, { Food: '#ef4444' }, { Food: '#ef4444', Spare: '#6366f1' })
expect(plan.updates).toEqual([])
expect(plan.emptyCategories).toEqual({ Spare: '#6366f1' })
})
it('FE-W4CNH-011: the original name of a renamed category is found, others map to themselves', () => {
expect(originalCategoryName('Dinner', { Food: 'Dinner' })).toBe('Food')
expect(originalCategoryName('Sights', { Food: 'Dinner' })).toBe('Sights')
})
})