-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSignalQualityIndicator.test.tsx
More file actions
85 lines (79 loc) · 2.93 KB
/
Copy pathSignalQualityIndicator.test.tsx
File metadata and controls
85 lines (79 loc) · 2.93 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
import React from 'react'
import { render, screen } from '@testing-library/react'
import { SignalQualityIndicator } from './SignalQualityIndicator'
import '@testing-library/jest-dom'
// Mock Tooltip to ensure title is rendered as an attribute for easy testing
jest.mock('@mui/material', () => ({
...jest.requireActual('@mui/material'),
Tooltip: ({
children,
title,
}: {
children: React.ReactElement<{ title?: string }>
title: string
}) => React.cloneElement(children, { title }),
}))
// Mock MUI icons
jest.mock('@mui/icons-material/SignalCellularAlt', () => ({
__esModule: true,
default: () => <div data-testid="SignalCellularAltIcon" />,
}))
jest.mock('@mui/icons-material/SignalCellularAlt2Bar', () => ({
__esModule: true,
default: () => <div data-testid="SignalCellularAlt2BarIcon" />,
}))
jest.mock('@mui/icons-material/SignalCellularAlt1Bar', () => ({
__esModule: true,
default: () => <div data-testid="SignalCellularAlt1BarIcon" />,
}))
jest.mock('@mui/icons-material/SignalCellularConnectedNoInternet0Bar', () => ({
__esModule: true,
default: () => (
<div data-testid="SignalCellularConnectedNoInternet0BarIcon" />
),
}))
describe('SignalQualityIndicator', () => {
it('should render the "excellent" state with correct tooltip', () => {
const { container } = render(
<SignalQualityIndicator periodMs={1000} isConnected={true} />
)
expect(screen.getByTestId('SignalCellularAltIcon')).toBeInTheDocument()
expect(screen.getByText('1000ms')).toBeInTheDocument()
expect(container.firstChild).toHaveAttribute(
'title',
'Signal Quality: 1000ms avg period (~100% capture)'
)
})
it('should render the "good" state with correct tooltip', () => {
const { container } = render(
<SignalQualityIndicator periodMs={1800} isConnected={true} />
)
expect(screen.getByTestId('SignalCellularAlt2BarIcon')).toBeInTheDocument()
expect(screen.getByText('1800ms')).toBeInTheDocument()
expect(container.firstChild).toHaveAttribute(
'title',
'Signal Quality: 1800ms avg period (~56% capture)'
)
})
it('should render the "poor" state with correct tooltip', () => {
const { container } = render(
<SignalQualityIndicator periodMs={2500} isConnected={true} />
)
expect(screen.getByTestId('SignalCellularAlt1BarIcon')).toBeInTheDocument()
expect(screen.getByText('2500ms')).toBeInTheDocument()
expect(container.firstChild).toHaveAttribute(
'title',
'Signal Quality: 2500ms avg period (~40% capture)'
)
})
it('should render the "none" state when disconnected', () => {
const { container } = render(
<SignalQualityIndicator periodMs={1000} isConnected={false} />
)
expect(
screen.getByTestId('SignalCellularConnectedNoInternet0BarIcon')
).toBeInTheDocument()
expect(screen.queryByText('1000ms')).not.toBeInTheDocument()
expect(container.firstChild).toHaveAttribute('title', 'No Signal')
})
})