Files
supabase/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHeader.test.tsx
+8 e273d2b818 chore(studio): move Explorer SQL Editor link to sidebar footer (#50829)
## What

- Moves the temporary "Switch to SQL Editor" button out of the Explorer
sidebar header into a footer section ("Looking for snippets?") with a
short explanation and an **Open SQL Editor** button.
- Replaces the header slot with a menu for the Explorer startup
preference (**Start page** / **SQL query**), instead of linking out to
account preferences.

## How to test

1. Enable the Explorer feature preview and open
`/project/<ref>/explorer`.
2. **Header menu:** click the ⋮ button next to the Explorer title. Pick
**SQL query**, then check that **Explorer startup** on `/account/me`
shows the same value (and vice versa).
3. **Footer:** click **Open SQL Editor**. You should land in the SQL
Editor with the **Back to Explorer** button in its title bar.
4. Open **Notebooks** or **Chats** in the sidebar and check that the
menu and footer are hidden there, like the old button was.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Choose whether the Explorer opens to the Start page or SQL query from
the Explorer preferences menu. Your selection is saved and retained when
you reopen the menu.
  * Access the SQL Editor from the Explorer’s sidebar footer.
* Explorer preferences are available from the Explorer navigation
header.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Tyler <dshukertjr@gmail.com>
Co-authored-by: Nik Richers <nrichers@gmail.com>
Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Jordi Enric <37541088+jordienr@users.noreply.github.com>
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
Co-authored-by: Katerina Skroumpelou <mandarini@users.noreply.github.com>
Co-authored-by: Franek <franek@ferly.co.uk>
Co-authored-by: Franek Richardson <franek@supabase.io>
Co-authored-by: Michał Olszewski <35968924+charconstpointer@users.noreply.github.com>
Co-authored-by: Steven Eubank <47563310+smeubank@users.noreply.github.com>
Co-authored-by: Anthony Lio <lionnet.ant@gmail.com>
Co-authored-by: Joey Lei <6957385+leizerbeam@users.noreply.github.com>
Co-authored-by: Ali Waseem <waseema393@gmail.com>
Co-authored-by: Samir Ketema <6003000+samirketema@users.noreply.github.com>
Co-authored-by: K-Dog (Kevin) <k.grueneberg1994@gmail.com>
2026-09-25 14:31:46 +08:00

86 lines
3.4 KiB
TypeScript

import { screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { ExplorerResourceType } from './ExplorerLayout.constants'
import { ExplorerNavHeader } from './ExplorerNavHeader'
import { ProductMenuBar } from '@/components/layouts/Navigation/ProductMenuBar'
import { customRender } from '@/tests/lib/custom-render'
const createNotebook = vi.fn()
const createChat = vi.fn()
vi.mock('@/components/interfaces/Explorer/hooks', () => ({
useCreateNotebook: () => ({ createNotebook }),
useCreateChat: () => ({ createChat }),
}))
function renderHeader(section?: ExplorerResourceType) {
const onBack = vi.fn()
customRender(
<ProductMenuBar
title="Explorer"
header={
<ExplorerNavHeader
section={section}
onBack={onBack}
rootAction={<span>Explorer preferences</span>}
/>
}
/>
)
return { onBack }
}
describe('Explorer sidebar header', () => {
beforeEach(() => vi.clearAllMocks())
it('shows the smaller root title with the preferences action', () => {
renderHeader()
expect(screen.getAllByText('Explorer')).toHaveLength(1)
expect(screen.getByText('Explorer')).toHaveClass('text-sm')
expect(screen.getByText('Explorer preferences')).toBeInTheDocument()
expect(screen.queryByRole('button')).not.toBeInTheDocument()
})
it.each([
{ section: 'notebook', parent: 'Explorer', current: 'Notebooks' },
{ section: 'chat', parent: 'Explorer', current: 'Chats' },
] satisfies { section: ExplorerResourceType; parent: string; current: string }[])(
'shows only $parent → $current and returns via the parent breadcrumb',
async ({ section, parent, current }) => {
const { onBack } = renderHeader(section)
const breadcrumb = screen.getByRole('navigation', { name: 'Explorer navigation' })
expect(within(breadcrumb).getByRole('button', { name: parent })).toBeInTheDocument()
expect(within(breadcrumb).getByRole('link', { name: current })).toHaveAttribute(
'aria-current',
'page'
)
expect(within(breadcrumb).getAllByRole('listitem')).toHaveLength(2)
expect(screen.queryByText('Explorer preferences')).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument()
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: parent }))
expect(onBack).toHaveBeenCalledOnce()
screen.getByRole('button', { name: parent }).focus()
await user.keyboard('{Enter}')
expect(onBack).toHaveBeenCalledTimes(2)
}
)
it.each(['notebook', 'chat'] as const)(
'shows the create action only for the current %s level',
async (level) => {
renderHeader(level)
await userEvent.click(screen.getByRole('button', { name: `New ${level}` }))
expect(level === 'notebook' ? createNotebook : createChat).toHaveBeenCalledOnce()
expect(level === 'notebook' ? createChat : createNotebook).not.toHaveBeenCalled()
}
)
it('keeps the default title and badge for other product sidebars', () => {
customRender(<ProductMenuBar title="Database" titleBadge={<span>Preview</span>} />)
expect(screen.getByRole('heading', { name: 'Database' })).toHaveClass('text-sm')
expect(screen.getByText('Preview')).toBeInTheDocument()
})
})