|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | +import { act } from 'react' |
| 5 | +import { createRoot, type Root } from 'react-dom/client' |
| 6 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 7 | + |
| 8 | +const { mockGetBlock } = vi.hoisted(() => ({ |
| 9 | + mockGetBlock: vi.fn(), |
| 10 | +})) |
| 11 | + |
| 12 | +vi.mock('@/blocks/registry', () => ({ |
| 13 | + getBlock: mockGetBlock, |
| 14 | + getBlockByToolName: vi.fn(), |
| 15 | + getLatestBlock: vi.fn(), |
| 16 | +})) |
| 17 | + |
| 18 | +vi.mock('@/lib/auth/auth-client', () => ({ |
| 19 | + useSession: vi.fn(() => ({ data: null, isPending: false })), |
| 20 | +})) |
| 21 | + |
| 22 | +interface MockAgentGroupItem { |
| 23 | + type: string |
| 24 | + data?: { id: string; displayTitle: string } |
| 25 | +} |
| 26 | + |
| 27 | +vi.mock('./components', () => ({ |
| 28 | + AgentGroup: ({ items }: { items: MockAgentGroupItem[] }) => ( |
| 29 | + <div> |
| 30 | + {items.map((item) => item.data && <span key={item.data.id}>{item.data.displayTitle}</span>)} |
| 31 | + </div> |
| 32 | + ), |
| 33 | + ChatContent: () => null, |
| 34 | + CircleStop: () => null, |
| 35 | + Options: () => null, |
| 36 | + PendingTagIndicator: () => null, |
| 37 | +})) |
| 38 | + |
| 39 | +import type { ContentBlock } from '@/app/workspace/[workspaceId]/home/types' |
| 40 | +import { notifyBlockOverlayChanged } from '@/blocks/custom/client-overlay' |
| 41 | +import { MessageContent } from './message-content' |
| 42 | + |
| 43 | +describe('MessageContent custom-block hydration', () => { |
| 44 | + beforeEach(() => { |
| 45 | + vi.clearAllMocks() |
| 46 | + ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true |
| 47 | + }) |
| 48 | + |
| 49 | + it('refreshes a read title when the custom-block registry hydrates after mount', () => { |
| 50 | + mockGetBlock.mockReturnValue(undefined) |
| 51 | + const blocks: ContentBlock[] = [ |
| 52 | + { |
| 53 | + type: 'tool_call', |
| 54 | + toolCall: { |
| 55 | + id: 'read-custom-block', |
| 56 | + name: 'read', |
| 57 | + status: 'success', |
| 58 | + params: { |
| 59 | + path: 'organization/custom-blocks/custom_block_invoice_parser.json', |
| 60 | + }, |
| 61 | + }, |
| 62 | + timestamp: 1, |
| 63 | + }, |
| 64 | + ] |
| 65 | + const container = document.createElement('div') |
| 66 | + const root: Root = createRoot(container) |
| 67 | + |
| 68 | + act(() => { |
| 69 | + root.render(<MessageContent blocks={blocks} fallbackContent='' isStreaming={false} />) |
| 70 | + }) |
| 71 | + expect(container.textContent).toContain('Read Custom block invoice parser') |
| 72 | + |
| 73 | + mockGetBlock.mockReturnValue({ |
| 74 | + type: 'custom_block_invoice_parser', |
| 75 | + name: 'Invoice Parser', |
| 76 | + icon: () => null, |
| 77 | + }) |
| 78 | + act(() => notifyBlockOverlayChanged()) |
| 79 | + |
| 80 | + expect(container.textContent).toContain('Read Invoice Parser') |
| 81 | + expect(container.textContent).not.toContain('Read Custom block invoice parser') |
| 82 | + act(() => root.unmount()) |
| 83 | + }) |
| 84 | +}) |
0 commit comments