mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
<img width="1693" height="1038" alt="image" src="https://github.com/user-attachments/assets/9ef52446-c517-4ea9-ada6-ac6dc57c8af4" /> ## Summary - add an Explorer-specific chat toolbar with rename, chat ID, permission, and branching controls - list searchable non-support chats in Explorer with reactive updates and safe rehydrated-date sorting - add chat creation entry points to Explorer home and navigation menus - route chat recent items correctly and show chat icons across shared tab surfaces - make the assistant sidebar expand action open the active chat in Explorer This is PR 3 of 3 and is stacked on #49031. Review #48973 first, then #49031, then this PR. Compared with its base, this PR contains only discovery, toolbar, and cross-surface integration work. ## To Test - visit /explorer - Create a new chat either via home tab chat input OR the chats sidebar - Validate chats show up in sidebar - Validate chat conversation works - Close the chat tab and open a chat via sidebar - Change permission settings via the chat tab toolbar and verify it persists ## Test plan - `mise exec node@22 -- pnpm --dir apps/studio exec tsc --noEmit` - focused Vitest suite: 4 files / 5 tests covering reactive chat lists, navigation filtering and sorting, recent-item routing, and sidebar handoff - ESLint on changed TypeScript files - Prettier check on changed source files <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added chat creation from the Explorer home, navigation, and new-tab menu. - Added an Explorer chat toolbar with editable names, ID copying, permissions, shortcuts, and metadata warnings. - Added searchable chat history with sorting, active-chat highlighting, and clear empty states. - Chats can now open directly in Explorer from the AI Assistant panel. - Recent items now link correctly to chats and notebooks. - **Bug Fixes** - Improved chat list updates after creation, deletion, and restored sessions. - Added safer handling for chats without update timestamps. - **Tests** - Expanded coverage for chat navigation, creation, metadata warnings, shortcuts, and recent-item links. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { fireEvent, screen } from '@testing-library/react'
|
|
import type { PropsWithChildren } from 'react'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import { ExplorerNavChats } from './ExplorerNavChats'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
|
|
vi.mock('common', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('common')>()
|
|
return { ...actual, useParams: () => ({ id: 'recent-chat' }) }
|
|
})
|
|
|
|
vi.mock('next/router', () => ({
|
|
useRouter: () => ({ pathname: '/project/[ref]/explorer/chat/[id]' }),
|
|
}))
|
|
|
|
vi.mock('./ExplorerLayout.constants', () => ({
|
|
ExplorerNavResourceWrapper: ({
|
|
children,
|
|
search,
|
|
setSearch,
|
|
}: PropsWithChildren<{ search: string; setSearch: (value: string) => void }>) => (
|
|
<div>
|
|
<input
|
|
aria-label="Search chats"
|
|
value={search}
|
|
onChange={(event) => setSearch(event.target.value)}
|
|
/>
|
|
{children}
|
|
</div>
|
|
),
|
|
rowClassName: (isActive: boolean) => (isActive ? 'active' : 'inactive'),
|
|
}))
|
|
|
|
vi.mock('@/components/interfaces/Explorer/hooks', () => ({
|
|
useCreateChat: () => ({ openChat: vi.fn() }),
|
|
}))
|
|
|
|
vi.mock('@/state/ai-assistant-state', () => ({
|
|
useAiAssistantChatList: () => [
|
|
{ id: 'old-chat', name: 'Older investigation', updatedAt: new Date('2026-01-01') },
|
|
{ id: 'missing-date', name: 'Rehydrated chat' },
|
|
{ id: 'recent-chat', name: 'Recent investigation', updatedAt: new Date('2026-02-01') },
|
|
{
|
|
id: 'support',
|
|
name: 'Support conversation',
|
|
updatedAt: new Date('2026-03-01'),
|
|
supportMetadata: { isSupportChat: true },
|
|
},
|
|
],
|
|
}))
|
|
|
|
describe('ExplorerNavChats', () => {
|
|
it('filters support chats, safely sorts rehydrated chats, and marks the route active', () => {
|
|
customRender(<ExplorerNavChats onBack={vi.fn()} />)
|
|
|
|
const chatButtons = screen.getAllByRole('button')
|
|
expect(chatButtons.map((button) => button.textContent)).toEqual([
|
|
'Recent investigation',
|
|
'Older investigation',
|
|
'Rehydrated chat',
|
|
])
|
|
expect(chatButtons[0]).toHaveClass('active')
|
|
expect(screen.queryByText('Support conversation')).not.toBeInTheDocument()
|
|
|
|
fireEvent.change(screen.getByRole('textbox', { name: 'Search chats' }), {
|
|
target: { value: 'rehydrated' },
|
|
})
|
|
|
|
expect(screen.getByRole('button')).toHaveTextContent('Rehydrated chat')
|
|
expect(screen.queryByText('Recent investigation')).not.toBeInTheDocument()
|
|
})
|
|
})
|