-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathstatus-indicator.test.tsx
More file actions
124 lines (110 loc) · 3.65 KB
/
status-indicator.test.tsx
File metadata and controls
124 lines (110 loc) · 3.65 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { describe, test, expect } from 'bun:test'
import { getStatusIndicatorState } from '../../utils/status-indicator-state'
import type { StatusIndicatorStateArgs } from '../../utils/status-indicator-state'
describe('StatusIndicator state logic', () => {
describe('getStatusIndicatorState', () => {
const baseArgs: StatusIndicatorStateArgs = {
clipboardMessage: null,
streamStatus: 'idle',
nextCtrlCWillExit: false,
isConnected: true,
}
test('returns idle state when no special conditions', () => {
const state = getStatusIndicatorState(baseArgs)
expect(state.kind).toBe('idle')
})
test('returns ctrlC state when nextCtrlCWillExit is true (highest priority)', () => {
const state = getStatusIndicatorState({
...baseArgs,
nextCtrlCWillExit: true,
clipboardMessage: 'Some message',
streamStatus: 'streaming',
isConnected: false,
})
expect(state.kind).toBe('ctrlC')
})
test('returns clipboard state when message exists (second priority)', () => {
const state = getStatusIndicatorState({
...baseArgs,
clipboardMessage: 'Copied to clipboard!',
streamStatus: 'streaming',
isConnected: false,
})
expect(state.kind).toBe('clipboard')
if (state.kind === 'clipboard') {
expect(state.message).toBe('Copied to clipboard!')
}
})
test('returns connecting state when not connected (third priority)', () => {
const state = getStatusIndicatorState({
...baseArgs,
isConnected: false,
streamStatus: 'streaming',
})
expect(state.kind).toBe('connecting')
})
test('returns waiting state when streamStatus is waiting', () => {
const state = getStatusIndicatorState({
...baseArgs,
streamStatus: 'waiting',
})
expect(state.kind).toBe('waiting')
})
test('returns streaming state when streamStatus is streaming', () => {
const state = getStatusIndicatorState({
...baseArgs,
streamStatus: 'streaming',
})
expect(state.kind).toBe('streaming')
})
test('handles empty clipboard message as falsy', () => {
const state = getStatusIndicatorState({
...baseArgs,
clipboardMessage: '',
streamStatus: 'streaming',
})
// Empty string is falsy, should fall through to streaming state
expect(state.kind).toBe('streaming')
})
describe('state priority order', () => {
test('nextCtrlCWillExit beats clipboard', () => {
const state = getStatusIndicatorState({
...baseArgs,
nextCtrlCWillExit: true,
clipboardMessage: 'Test',
})
expect(state.kind).toBe('ctrlC')
})
test('clipboard beats connecting', () => {
const state = getStatusIndicatorState({
...baseArgs,
clipboardMessage: 'Test',
isConnected: false,
})
expect(state.kind).toBe('clipboard')
})
test('connecting beats waiting', () => {
const state = getStatusIndicatorState({
...baseArgs,
isConnected: false,
streamStatus: 'waiting',
})
expect(state.kind).toBe('connecting')
})
test('waiting beats streaming', () => {
const state = getStatusIndicatorState({
...baseArgs,
streamStatus: 'waiting',
})
expect(state.kind).toBe('waiting')
})
test('streaming beats idle', () => {
const state = getStatusIndicatorState({
...baseArgs,
streamStatus: 'streaming',
})
expect(state.kind).toBe('streaming')
})
})
})
})