forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapDetailPicker.test.tsx
More file actions
63 lines (48 loc) · 2.41 KB
/
Copy pathMapDetailPicker.test.tsx
File metadata and controls
63 lines (48 loc) · 2.41 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
import { describe, it, expect, vi, afterEach } from 'vitest'
import { render, screen, cleanup, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MapDetailPicker } from './MapDetailPicker'
import { PREFERENCE_KEYS } from '../lib/userPreferences'
afterEach(cleanup)
const group = () => within(screen.getByRole('group', { name: /map detail/i }))
describe('MapDetailPicker', () => {
it('offers all three levels as one radio group', () => {
render(<MapDetailPicker value="standard" onChange={() => {}} />)
const values = group()
.getAllByRole('radio')
.map((radio) => (radio as HTMLInputElement).value)
expect(values.sort()).toEqual(['full', 'minimal', 'standard'])
})
it('groups them on the canonical field name', () => {
// `layer_detail_level` predates this control by some months - the key
// shipped in the schema unwired (backend/app/schemas/preferences.py
// requires it), and the control has to write the key that already syncs.
render(<MapDetailPicker value="standard" onChange={() => {}} />)
expect(PREFERENCE_KEYS).toContain('layer_detail_level')
for (const radio of group().getAllByRole('radio')) {
expect(radio).toHaveAttribute('name', 'layer_detail_level')
}
})
it('shows the current choice as the checked one', () => {
render(<MapDetailPicker value="minimal" onChange={() => {}} />)
const checked = group()
.getAllByRole('radio')
.find((radio) => (radio as HTMLInputElement).checked)
expect((checked as HTMLInputElement).value).toBe('minimal')
})
it('reports a change as the preference value, not as a label', async () => {
const user = userEvent.setup()
const onChange = vi.fn()
render(<MapDetailPicker value="standard" onChange={onChange} />)
await user.click(screen.getByRole('radio', { name: /minimal/i }))
expect(onChange).toHaveBeenCalledWith('minimal')
})
it('says what minimal KEEPS, so less detail does not read as less map', () => {
// The level exists for a hiker overwhelmed by ink; a description that
// only listed losses would scare off exactly that hiker. mapDetail.ts's
// matrix keeps index contours and side paths, so the words have to.
render(<MapDetailPicker value="minimal" onChange={() => {}} />)
expect(screen.getByText(/index contours/i)).toBeInTheDocument()
expect(screen.getByText(/side paths/i)).toBeInTheDocument()
})
})