Spaces:
Sleeping

File size: 1,922 Bytes
228bdaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f4ddef
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { describe, expect, it } from 'vitest'
import { byTab, tabOf } from './live'
import type { InboxItem } from './types'
import { ago, money } from './words'

const item = (quote_id: string, bucket: InboxItem['bucket'], last_position: number): InboxItem => ({
  quote_id,
  run_id: null,
  customer: 'Acme',
  summary: '',
  total: 1,
  bucket,
  rule_ids: [],
  reasons: [],
  last_position,
})

describe('byTab', () => {
  it('groups items by tab, newest first, with approved and rejected under Done', () => {
    const groups = byTab([
      item('Q-1', 'ready', 3),
      item('Q-2', 'flagged', 5),
      item('Q-3', 'ready', 9),
      item('Q-4', 'approved', 7),
      item('Q-5', 'rejected', 8),
      item('Q-6', 'pending', 10),
    ])
    expect(groups.ready.map((i) => i.quote_id)).toEqual(['Q-3', 'Q-1'])
    expect(groups.flagged.map((i) => i.quote_id)).toEqual(['Q-2'])
    expect(groups.done.map((i) => i.quote_id)).toEqual(['Q-5', 'Q-4'])
    expect(groups.needs_senior).toEqual([])
  })
  it('keeps quotes still being prepared out of every tab', () => {
    expect(tabOf('pending')).toBeNull()
  })
})

describe('words', () => {
  it('formats money with or without cents', () => {
    expect(money(13216.68)).toBe('$13,217')
    expect(money(3150.41, true)).toBe('$3,150.41')
  })
  it('says how long ago', () => {
    const now = new Date('2026-11-29T12:00:00Z')
    expect(ago('2026-11-29T11:59:30Z', now)).toBe('just now')
    expect(ago('2026-11-29T11:30:00Z', now)).toBe('30 min ago')
    expect(ago('2026-11-29T09:00:00Z', now)).toBe('3 h ago')
  })
})

describe('range bar', () => {
  it('places values inside the bar and clamps the rest', async () => {
    const { position } = await import('../components/CostEstimate')
    expect(position(50, 0, 100)).toBe(50)
    expect(position(-5, 0, 100)).toBe(0)
    expect(position(500, 0, 100)).toBe(100)
    expect(position(1, 1, 1)).toBe(50)
  })
})