-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathstatus-indicator.timer.test.tsx
More file actions
163 lines (140 loc) · 4.86 KB
/
status-indicator.timer.test.tsx
File metadata and controls
163 lines (140 loc) · 4.86 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { describe, test, expect } from 'bun:test'
import React from 'react'
import { StatusIndicator, StatusElapsedTime } from '../status-indicator'
import { initializeThemeStore } from '../../hooks/use-theme'
import { renderToStaticMarkup } from 'react-dom/server'
import { getStatusIndicatorState } from '../status-indicator'
describe('StatusIndicator state transitions', () => {
describe('StatusIndicator text states', () => {
test('shows "thinking..." when waiting for first response (streamStatus = waiting)', () => {
const now = Date.now()
const markup = renderToStaticMarkup(
<StatusIndicator
clipboardMessage={null}
streamStatus="waiting"
timerStartTime={now - 5000}
nextCtrlCWillExit={false}
isConnected={true}
/>,
)
// ShimmerText renders individual characters in spans
expect(markup).toContain('t')
expect(markup).toContain('h')
expect(markup).toContain('i')
expect(markup).toContain('n')
expect(markup).toContain('k')
expect(markup).not.toContain('w') // not "working"
})
test('shows "working..." when streaming content (streamStatus = streaming)', () => {
const now = Date.now()
const markup = renderToStaticMarkup(
<StatusIndicator
clipboardMessage={null}
streamStatus="streaming"
timerStartTime={now - 5000}
nextCtrlCWillExit={false}
isConnected={true}
/>,
)
// ShimmerText renders individual characters in spans
expect(markup).toContain('w')
expect(markup).toContain('o')
expect(markup).toContain('r')
expect(markup).toContain('k')
})
test('shows nothing when inactive (streamStatus = idle)', () => {
const markup = renderToStaticMarkup(
<StatusIndicator
clipboardMessage={null}
streamStatus="idle"
timerStartTime={null}
nextCtrlCWillExit={false}
isConnected={true}
/>,
)
expect(markup).toBe('')
})
})
describe('Priority states', () => {
test('nextCtrlCWillExit takes highest priority', () => {
const now = Date.now()
const markup = renderToStaticMarkup(
<StatusIndicator
clipboardMessage="Copied!"
streamStatus="waiting"
timerStartTime={now - 5000}
nextCtrlCWillExit={true}
isConnected={true}
/>,
)
expect(markup).toContain('Press Ctrl-C again to exit')
expect(markup).not.toContain('Copied!')
expect(markup).not.toContain('thinking')
expect(markup).not.toContain('working')
})
test('clipboard message takes priority over streaming states', () => {
const now = Date.now()
const markup = renderToStaticMarkup(
<StatusIndicator
clipboardMessage="Copied!"
streamStatus="waiting"
timerStartTime={now - 12000}
nextCtrlCWillExit={false}
isConnected={true}
/>,
)
expect(markup).toContain('Copied!')
// Shimmer text would contain individual characters, but clipboard message doesn't
})
})
describe('Connectivity states', () => {
test('shows "connecting..." shimmer when offline and idle', () => {
const markup = renderToStaticMarkup(
<StatusIndicator
clipboardMessage={null}
streamStatus="idle"
timerStartTime={null}
nextCtrlCWillExit={false}
isConnected={false}
/>,
)
expect(markup).toContain('c')
expect(markup).toContain('o')
expect(markup).toContain('n')
})
test('getStatusIndicatorState reports connecting state when offline', () => {
const state = getStatusIndicatorState({
clipboardMessage: null,
streamStatus: 'idle',
nextCtrlCWillExit: false,
isConnected: false,
})
expect(state.kind).toBe('connecting')
})
})
describe('StatusElapsedTime', () => {
test('shows nothing initially (useEffect not triggered in static render)', () => {
const now = Date.now()
const markup = renderToStaticMarkup(
<StatusElapsedTime streamStatus="streaming" timerStartTime={now - 5000} />,
)
// Static rendering doesn't trigger useEffect, so elapsed time starts at 0
// In real usage, useEffect updates the elapsed time after mount
expect(markup).toBe('')
})
test('shows nothing when inactive', () => {
const now = Date.now()
const markup = renderToStaticMarkup(
<StatusElapsedTime streamStatus="idle" timerStartTime={now - 5000} />,
)
expect(markup).toBe('')
})
test('shows nothing when timerStartTime is null', () => {
const markup = renderToStaticMarkup(
<StatusElapsedTime streamStatus="streaming" timerStartTime={null} />,
)
expect(markup).toBe('')
})
})
})
initializeThemeStore()