mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 13:19:09 +03:00
* sidebar-manager * storage keys * tests * more ai spots * test fix * revert to default * remove ref * Update apps/studio/state/sidebar-manager-state.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix ts * fix * fux * fux query param * clean * fix * more * mock local storage * simplify * remove provider test * remve useopensidebar * fix(new homepage): open ai assistant on advisor card button clicks * Update apps/studio/components/layouts/ProjectLayout/LayoutSidebar/index.tsx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/studio/state/sidebar-manager-state.tsx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * refine * FIX --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { act, screen, waitFor } from '@testing-library/react'
|
|
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'
|
|
|
|
import { LayoutSidebar } from './index'
|
|
import { LayoutSidebarProvider, SIDEBAR_KEYS } from './LayoutSidebarProvider'
|
|
import { sidebarManagerState } from 'state/sidebar-manager-state'
|
|
import { render } from 'tests/helpers'
|
|
import { routerMock } from 'tests/lib/route-mock'
|
|
import { ResizablePanel, ResizablePanelGroup } from 'ui'
|
|
|
|
vi.mock('components/ui/AIAssistantPanel/AIAssistant', () => ({
|
|
AIAssistant: () => <div data-testid="ai-assistant-sidebar">AI Assistant</div>,
|
|
}))
|
|
|
|
const resetSidebarManagerState = () => {
|
|
Object.keys(sidebarManagerState.sidebars).forEach((id) => {
|
|
sidebarManagerState.unregisterSidebar(id)
|
|
})
|
|
sidebarManagerState.closeActive()
|
|
}
|
|
|
|
describe('LayoutSidebar', () => {
|
|
beforeEach(() => {
|
|
routerMock.setCurrentUrl('/projects/default')
|
|
})
|
|
|
|
afterEach(() => {
|
|
resetSidebarManagerState()
|
|
localStorage.clear()
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
const renderSidebar = () =>
|
|
render(
|
|
<ResizablePanelGroup direction="horizontal">
|
|
<ResizablePanel>
|
|
<div />
|
|
</ResizablePanel>
|
|
<LayoutSidebarProvider>
|
|
<LayoutSidebar />
|
|
</LayoutSidebarProvider>
|
|
</ResizablePanelGroup>
|
|
)
|
|
|
|
it('does not render when there is no active sidebar', () => {
|
|
renderSidebar()
|
|
|
|
expect(screen.queryByTestId('ai-assistant-sidebar')).toBeNull()
|
|
})
|
|
|
|
it('renders the active sidebar content when toggled on', async () => {
|
|
renderSidebar()
|
|
|
|
await waitFor(() => {
|
|
expect(sidebarManagerState.sidebars[SIDEBAR_KEYS.AI_ASSISTANT]).toBeDefined()
|
|
})
|
|
|
|
act(() => {
|
|
sidebarManagerState.toggleSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
|
|
})
|
|
|
|
expect(await screen.findByTestId('ai-assistant-sidebar')).toBeInTheDocument()
|
|
})
|
|
|
|
it('auto-opens when sidebar query param matches a registered sidebar', async () => {
|
|
routerMock.setCurrentUrl(`/?sidebar=${SIDEBAR_KEYS.AI_ASSISTANT}`)
|
|
|
|
renderSidebar()
|
|
|
|
await screen.findByTestId('ai-assistant-sidebar')
|
|
})
|
|
})
|