Skip to content

Commit 7a6fe94

Browse files
committed
fix types and tests
1 parent 60dd4a6 commit 7a6fe94

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

cli/src/components/__tests__/message-block.completion.test.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ const baseProps = {
2929
isComplete: false,
3030
completionTime: undefined,
3131
credits: undefined,
32-
timer: {
33-
start: () => {},
34-
stop: () => {},
35-
elapsedSeconds: 0,
36-
startTime: null,
37-
},
32+
timerStartTime: null,
3833
textColor: theme.foreground,
3934
timestampColor: theme.muted,
4035
markdownOptions: {

cli/src/components/__tests__/message-block.streaming.test.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,16 @@ const baseProps = {
4141
onToggleCollapsed: () => {},
4242
}
4343

44-
const createTimer = (elapsedSeconds: number) => ({
45-
start: () => {},
46-
stop: () => {},
47-
elapsedSeconds,
48-
startTime: elapsedSeconds > 0 ? Date.now() - elapsedSeconds * 1000 : null,
49-
})
44+
const createTimerStartTime = (elapsedSeconds: number): number | null =>
45+
elapsedSeconds > 0 ? Date.now() - elapsedSeconds * 1000 : null
5046

5147
describe('MessageBlock streaming indicator', () => {
5248
test('shows elapsed seconds while streaming', () => {
5349
const markup = renderToStaticMarkup(
5450
<MessageBlock
5551
{...baseProps}
5652
isLoading={true}
57-
timer={createTimer(4)}
53+
timerStartTime={createTimerStartTime(4)}
5854
/>,
5955
)
6056

@@ -66,7 +62,7 @@ describe('MessageBlock streaming indicator', () => {
6662
<MessageBlock
6763
{...baseProps}
6864
isLoading={true}
69-
timer={createTimer(0)}
65+
timerStartTime={createTimerStartTime(0)}
7066
/>,
7167
)
7268

cli/src/components/__tests__/status-indicator.timer.test.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ import { renderToStaticMarkup } from 'react-dom/server'
1616

1717
import * as codebuffClient from '../../utils/codebuff-client'
1818

19-
const createTimer = (elapsedSeconds: number, started: boolean) => ({
20-
start: () => {},
21-
stop: () => {},
22-
elapsedSeconds,
23-
startTime: started ? Date.now() - elapsedSeconds * 1000 : null,
24-
})
19+
const createTimerStartTime = (
20+
elapsedSeconds: number,
21+
started: boolean,
22+
): number | null =>
23+
started ? Date.now() - elapsedSeconds * 1000 : null
2524

2625
describe('StatusIndicator timer rendering', () => {
2726
let getClientSpy: ReturnType<typeof spyOn>
@@ -41,7 +40,7 @@ describe('StatusIndicator timer rendering', () => {
4140
<StatusIndicator
4241
clipboardMessage={null}
4342
isActive={true}
44-
timer={createTimer(5, true)}
43+
timerStartTime={createTimerStartTime(5, true)}
4544
nextCtrlCWillExit={false}
4645
/>,
4746
)
@@ -52,7 +51,7 @@ describe('StatusIndicator timer rendering', () => {
5251
<StatusIndicator
5352
clipboardMessage={null}
5453
isActive={false}
55-
timer={createTimer(0, false)}
54+
timerStartTime={createTimerStartTime(0, false)}
5655
nextCtrlCWillExit={false}
5756
/>,
5857
)
@@ -65,7 +64,7 @@ describe('StatusIndicator timer rendering', () => {
6564
<StatusIndicator
6665
clipboardMessage="Copied!"
6766
isActive={true}
68-
timer={createTimer(12, true)}
67+
timerStartTime={createTimerStartTime(12, true)}
6968
nextCtrlCWillExit={false}
7069
/>,
7170
)

cli/src/components/elapsed-timer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ export const ElapsedTimer = ({
1919
attributes,
2020
}: ElapsedTimerProps) => {
2121
const theme = useTheme()
22-
const [elapsedSeconds, setElapsedSeconds] = useState<number>(0)
22+
23+
// Calculate elapsed seconds synchronously for SSR/initial render
24+
const calculateElapsed = () => {
25+
if (!startTime) return 0
26+
return Math.floor((Date.now() - startTime) / 1000)
27+
}
28+
29+
const [elapsedSeconds, setElapsedSeconds] = useState<number>(calculateElapsed)
2330

2431
useEffect(() => {
2532
if (!startTime) {

0 commit comments

Comments
 (0)