Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

1.5 KB
Raw Blame
import { insightPeriods } from '@linedesk/actions'
import { expect, test } from 'vitest'
import { DEFAULT_PLACE, hashForPlace, placeFromHash } from './place.ts'

test('the defaults keep the plain address; every other view round-trips', () => {
  expect(hashForPlace(DEFAULT_PLACE)).toBe('#insights')
  expect(placeFromHash('#insights')).toEqual(DEFAULT_PLACE)
  for (const period of insightPeriods)
    for (const metric of ['answered', 'booked', 'messages', 'missed'] as const) {
      const place = { period, range: null, metric }
      expect(placeFromHash(hashForPlace(place)), `${period} ${metric}`).toEqual(place)
    }
  const custom = { period: 'custom', range: { from: '2026-11-01', to: '2026-11-15' }, metric: 'booked' } as const
  expect(hashForPlace(custom)).toBe('#insights?period=custom&from=2026-11-01&to=2026-11-15&metric=booked')
  expect(placeFromHash(hashForPlace(custom))).toEqual(custom)
})

test('what an address says wrongly is the default', () => {
  expect(placeFromHash('#insights?period=forever&metric=money')).toEqual(DEFAULT_PLACE)
  expect(placeFromHash('#insights?period=custom&from=2026-11-15&to=2026-11-01')).toEqual(DEFAULT_PLACE)
  expect(placeFromHash('#insights?period=custom&from=yesterday&to=today')).toEqual(DEFAULT_PLACE)
  expect(placeFromHash('#contacts?period=7d')).toEqual(DEFAULT_PLACE)
  // A custom range still being typed (no dates yet) is not in the address.
  expect(hashForPlace({ period: 'custom', range: null, metric: 'answered' })).toBe('#insights')
})