-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathmessage-block.streaming.test.tsx
More file actions
58 lines (49 loc) · 1.64 KB
/
message-block.streaming.test.tsx
File metadata and controls
58 lines (49 loc) · 1.64 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
import React from 'react'
import { describe, test, expect } from 'bun:test'
import { renderToStaticMarkup } from 'react-dom/server'
import { MessageBlock } from '../message-block'
import '../../state/theme-store' // Initialize theme store
import { chatThemes, createMarkdownPalette } from '../../utils/theme-system'
const theme = chatThemes.dark
const markdownPalette = createMarkdownPalette(theme)
const baseProps = {
messageId: 'ai-stream',
blocks: undefined,
content: 'Streaming response...',
isUser: false,
isAi: true,
isComplete: false,
timestamp: '12:00',
completionTime: undefined,
credits: undefined,
textColor: theme.foreground,
timestampColor: theme.muted,
markdownOptions: {
codeBlockWidth: 72,
palette: markdownPalette,
},
availableWidth: 80,
collapsedAgents: new Set<string>(),
streamingAgents: new Set<string>(),
onToggleCollapsed: () => {},
}
const createTimer = (elapsedSeconds: number) => ({
start: () => {},
stop: () => {},
elapsedSeconds,
startTime: elapsedSeconds > 0 ? Date.now() - elapsedSeconds * 1000 : null,
})
describe('MessageBlock streaming indicator', () => {
test('shows elapsed seconds while streaming', () => {
const markup = renderToStaticMarkup(
<MessageBlock {...baseProps} isLoading={true} timer={createTimer(4)} markdownPalette={markdownPalette} />,
)
expect(markup).toContain('4s')
})
test('hides elapsed seconds when timer has not advanced', () => {
const markup = renderToStaticMarkup(
<MessageBlock {...baseProps} isLoading={true} timer={createTimer(0)} markdownPalette={markdownPalette} />,
)
expect(markup).not.toContain('0s')
})
})