forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabBar.test.tsx
More file actions
66 lines (49 loc) · 2.01 KB
/
Copy pathTabBar.test.tsx
File metadata and controls
66 lines (49 loc) · 2.01 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
import { describe, it, expect, vi, afterEach } from 'vitest'
import { render, screen, cleanup } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { TabBar } from './TabBar'
import { TABS } from './tabs'
// WIREFRAMES.md, map screen §6: Trail / Downloads / More. Three tabs, no more -
// v1's whole surface fits in them, and the tab bar sits in the thumb zone where
// every extra target costs accuracy mid-walk.
const PROPS = { active: 'trail' as const, onSelect: vi.fn() }
afterEach(() => {
cleanup()
vi.clearAllMocks()
})
describe('TabBar', () => {
it('has exactly the three MVP tabs, in order', () => {
render(<TabBar {...PROPS} />)
expect(screen.getAllByRole('tab').map((t) => t.textContent)).toEqual([
'Trail',
'Downloads',
'More',
])
})
it('derives its tabs from the shared list rather than hardcoding them in markup', () => {
render(<TabBar {...PROPS} />)
expect(screen.getAllByRole('tab')).toHaveLength(TABS.length)
})
it('marks the active tab as selected, and only that one', () => {
render(<TabBar {...PROPS} active="downloads" />)
const selected = screen.getAllByRole('tab', { selected: true })
expect(selected).toHaveLength(1)
expect(selected[0]).toHaveTextContent('Downloads')
})
it('reports which tab was chosen', async () => {
const user = userEvent.setup()
render(<TabBar {...PROPS} />)
await user.click(screen.getByRole('tab', { name: 'More' }))
expect(PROPS.onSelect).toHaveBeenCalledWith('more')
})
it('still reports a tap on the tab that is already active, so it can scroll-to-top', async () => {
const user = userEvent.setup()
render(<TabBar {...PROPS} active="trail" />)
await user.click(screen.getByRole('tab', { name: 'Trail' }))
expect(PROPS.onSelect).toHaveBeenCalledWith('trail')
})
it('is a tablist, so assistive tech announces position within the set', () => {
render(<TabBar {...PROPS} />)
expect(screen.getByRole('tablist')).toBeInTheDocument()
})
})