forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaypointLanes.test.tsx
More file actions
90 lines (69 loc) · 3.04 KB
/
Copy pathWaypointLanes.test.tsx
File metadata and controls
90 lines (69 loc) · 3.04 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { describe, it, expect, afterEach } from 'vitest'
import { render, screen, cleanup, within } from '@testing-library/react'
import { WaypointLanes } from './WaypointLanes'
// WIREFRAMES.md §1.4: three lanes of 19px - WATER, SLEEP, ELSE - with mono
// labels in the left gutter and pins positioned by percentage along the mile
// window. The clustering maths lives in lib/waypointLanes.ts and is tested
// there; this covers the rendering of it.
const WINDOW = { startMile: 1400, endMile: 1410 }
const POINTS = [
{ id: 'w1', type: 'water', mile: 1402 },
{ id: 'w2', type: 'water', mile: 1402.05 },
{ id: 'w3', type: 'water', mile: 1402.1 },
{ id: 's1', type: 'shelter', mile: 1406 },
{ id: 'r1', type: 'resupply', mile: 1408 },
]
const PROPS = { points: POINTS, ...WINDOW }
afterEach(() => {
cleanup()
})
describe('WaypointLanes', () => {
it('renders the three lanes with their gutter labels', () => {
render(<WaypointLanes {...PROPS} />)
expect(screen.getByText('WATER')).toBeInTheDocument()
expect(screen.getByText('SLEEP')).toBeInTheDocument()
expect(screen.getByText('ELSE')).toBeInTheDocument()
})
it('puts each waypoint in the right lane', () => {
render(<WaypointLanes {...PROPS} />)
expect(within(screen.getByTestId('lane-sleep')).getAllByRole('button')).toHaveLength(
1,
)
expect(within(screen.getByTestId('lane-else')).getAllByRole('button')).toHaveLength(1)
})
it('collapses a tight cluster into a single pill showing how many it swallowed', () => {
render(<WaypointLanes {...PROPS} />)
const waterPins = within(screen.getByTestId('lane-water')).getAllByRole('button')
expect(waterPins).toHaveLength(1)
expect(waterPins[0]).toHaveTextContent('3')
})
it('does not put a count on a lone pin', () => {
render(<WaypointLanes {...PROPS} />)
const shelter = within(screen.getByTestId('lane-sleep')).getByRole('button')
expect(shelter).not.toHaveTextContent('1')
})
it('positions a pin by percentage, so it lines up with the profile above it', () => {
render(<WaypointLanes {...PROPS} />)
const shelter = within(screen.getByTestId('lane-sleep')).getByRole('button')
// 1406 of 1400-1410 is 60%.
expect(shelter.style.left).toBe('60%')
})
it('names each pin for assistive tech instead of leaving a bare glyph', () => {
render(<WaypointLanes {...PROPS} />)
expect(
within(screen.getByTestId('lane-sleep')).getByRole('button', { name: /shelter/i }),
).toBeInTheDocument()
})
it('says how many a pill stands for in its accessible name', () => {
render(<WaypointLanes {...PROPS} />)
expect(
within(screen.getByTestId('lane-water')).getByRole('button', { name: /3 water/i }),
).toBeInTheDocument()
})
it('still renders all three lanes when nothing is in the window', () => {
render(<WaypointLanes {...PROPS} points={[]} />)
expect(screen.getByTestId('lane-water')).toBeInTheDocument()
expect(screen.getByTestId('lane-sleep')).toBeInTheDocument()
expect(screen.getByTestId('lane-else')).toBeInTheDocument()
})
})