forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrongWayCue.test.tsx
More file actions
79 lines (60 loc) · 2.48 KB
/
Copy pathWrongWayCue.test.tsx
File metadata and controls
79 lines (60 loc) · 2.48 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
import { describe, it, expect, vi, afterEach } from 'vitest'
import { render, screen, cleanup } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { WrongWayCue } from './WrongWayCue'
// WIREFRAMES.md §9, beat 1: the in-app cue. "You may be off the trail — about
// 90 ft from the white blazes for the last 12 minutes," with Show me the way
// back / I'm fine.
//
// The wording is hedged on purpose. GPS under tree canopy is unreliable
// enough that certainty would be dishonest, and "You ARE off the trail" to
// someone standing on it is exactly the false positive that spends this
// feature's whole trust budget. "May be" is the claim the data supports.
const PROPS = {
open: true,
distanceFt: 90,
minutes: 12,
onShowWayBack: vi.fn(),
onDismiss: vi.fn(),
}
afterEach(() => {
cleanup()
vi.clearAllMocks()
})
describe('WrongWayCue', () => {
it('stays out of the way when there is nothing to say', () => {
render(<WrongWayCue {...PROPS} open={false} />)
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
})
it('hedges rather than asserting - GPS under canopy does not support certainty', () => {
render(<WrongWayCue {...PROPS} />)
expect(screen.getByRole('alert')).toHaveTextContent(/may be/i)
})
it('gives the distance and the duration behind the claim', () => {
render(<WrongWayCue {...PROPS} />)
const cue = screen.getByRole('alert')
expect(cue).toHaveTextContent(/90 ft/)
expect(cue).toHaveTextContent(/12 minutes/)
})
it('offers to show the way back', async () => {
const user = userEvent.setup()
render(<WrongWayCue {...PROPS} />)
await user.click(screen.getByRole('button', { name: /way back/i }))
expect(PROPS.onShowWayBack).toHaveBeenCalled()
})
it('lets the hiker say they are fine, and believes them', async () => {
const user = userEvent.setup()
render(<WrongWayCue {...PROPS} />)
await user.click(screen.getByRole('button', { name: /fine/i }))
expect(PROPS.onDismiss).toHaveBeenCalled()
})
it('is announced to assistive tech without waiting to be found', () => {
render(<WrongWayCue {...PROPS} />)
expect(screen.getByRole('alert')).toBeInTheDocument()
})
it('never promises to navigate anywhere - it points, it does not route', () => {
// Consistent with the closure sheet's "OurHike does not work out detours".
render(<WrongWayCue {...PROPS} />)
expect(screen.queryByText(/directions|navigate|route you/i)).toBe(null)
})
})