Files
supabase/apps/docs/components/Navigation/NavigationMenu/DocsSidebarNav.test.tsx
T
anthony lio 02e61b9cda fix(docs): layout v2 reference fixtures (#54233)
## Problem

- after #53761 the option-1 sidebar reference list has no row for
server, middleware and tanstack db
- list marks no row as current on a library page, for example on
`/reference/javascript/select`
- management api intro shows its endpoint list in the right rail and its
toc in an extra column inside the content

## Solution

- adds the server, middleware and tanstack db rows with the new and
experimental badges of the current nav
- fixes the reference list so it marks the library of the current page
- changes the management api to open as its own sidebar level with the
endpoint list on the left
- moves the toc, the links and the feedback of the management api intro
into the right rail + removes the rail on endpoint pages
- adds the "on this page" menu to the management api intro below `lg`
- adds the reference library column to the option-1 nav size allowlist
because it is a list of peer libraries

| before | after |
| -------|------|
| <img width="2880" height="1800" alt="image"
src="https://github.com/user-attachments/assets/3a216c0b-31c1-4629-82a1-0590c7e639ae"
/> | <img width="2880" height="1800" alt="image"
src="https://github.com/user-attachments/assets/c53afc0e-8d15-45d7-9dc8-320443761ed2"
/> |

| before | after |
| -------|------|
| <img width="2880" height="1800" alt="image"
src="https://github.com/user-attachments/assets/5dc79bb9-b160-44e6-a3c5-39182fb71d4f"
/> | <img width="2880" height="1800" alt="image"
src="https://github.com/user-attachments/assets/9e0dff3c-5261-4c70-b1f1-f74314231a08"
/> |

<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. open
[/docs/reference?docs-ia-mvp-v1=option-1](https://docs-ivb0vb1qq-supabase.vercel.app/docs/reference?docs-ia-mvp-v1=option-1)
and do all steps in the same tab because the flag override lasts only
for the tab
2. make sure that the reference list shows server and middleware
3. open
[/docs/reference/javascript/select](https://docs-ivb0vb1qq-supabase.vercel.app/docs/reference/javascript/select)
and make sure that the sidebar marks only the javascript row
4. click `Management API` in the sidebar and make sure that the sidebar
shows `< Management API` with the endpoint list
5. make sure that the right rail shows the toc, the additional links and
the feedback buttons
6. open
[/docs/guides/database/overview](https://docs-ivb0vb1qq-supabase.vercel.app/docs/guides/database/overview)
and make sure that the sidebar and the right rail did not change

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-30 20:19:04 +00:00

280 lines
10 KiB
TypeScript

// @vitest-environment jsdom
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import * as option1NavItems from '~/features/IaNav/option1.constants'
import { useNavItems } from '~/features/IaNav/useNavItems'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
DocsSidebarNav,
DocsSidebarNavProvider,
DocsSidebarNavTop,
DocsSidebarResources,
} from './DocsSidebarNav'
import { useDocsSidebarNav } from './DocsSidebarNavContext'
import { MenuId } from './NavigationMenu'
import * as currentNavItems from './NavigationMenu.constants'
import { getListedMenuId } from './NavigationMenu.utils'
const navigation = vi.hoisted(() => ({ pathname: '/guides/database/overview' }))
vi.mock('~/features/IaNav/IaNavRouteProvider', () => ({
useDocsPathname: () => navigation.pathname,
}))
vi.mock('~/features/IaNav/useIaNavReady', () => ({ useIaNavReady: () => true }))
vi.mock('~/features/IaNav/useNavItems', () => ({ useNavItems: vi.fn() }))
// the guide tree imports the IaNav barrel, and the variant hook there loads browser-only modules
vi.mock('~/features/IaNav/useIaNavVariant', () => ({ useIaNavVariant: () => 'control' }))
vi.mock('next/navigation', () => ({
usePathname: () => navigation.pathname,
}))
const LevelDepth = () => <p>{`depth ${useDocsSidebarNav().stack.length}`}</p>
const sidebar = (
menuId = getListedMenuId({ pathname: navigation.pathname, navItems: vi.mocked(useNavItems)() })
) => (
<DocsSidebarNavProvider menuId={menuId}>
<DocsSidebarNavTop />
<DocsSidebarNav>page tree</DocsSidebarNav>
<LevelDepth />
</DocsSidebarNavProvider>
)
const renderSidebar = (menuId?: MenuId) => render(sidebar(menuId))
describe('DocsSidebarNav', () => {
afterEach(cleanup)
beforeEach(() => {
navigation.pathname = '/guides/database/overview'
vi.mocked(useNavItems).mockReturnValue(currentNavItems)
})
it('starts at the section list when no product holds the page', () => {
navigation.pathname = '/'
renderSidebar(MenuId.Contributing)
expect(screen.getByText('depth 1')).toBeTruthy()
expect(screen.queryByRole('navigation', { name: 'Sidebar levels' })).toBeNull()
})
it('lists Reference with the other sections and opens it with a way back', () => {
navigation.pathname = '/'
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar(MenuId.Contributing)
fireEvent.click(screen.getByRole('button', { name: 'Reference' }))
expect(screen.getByRole('button', { name: 'Reference, back to Home' })).toBeTruthy()
expect(screen.getByRole('link', { name: 'JavaScript' })).toBeTruthy()
})
it('opens the levels of the page from the option-1 nav, with a getting started link its tree leaves out', () => {
navigation.pathname = '/guides/local-development'
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar()
expect(
screen.getByRole('button', { name: 'Local development and CLI, back to Develop and deploy' })
).toBeTruthy()
expect(screen.getByRole('link', { name: 'Getting started' }).getAttribute('href')).toBe(
'/guides/local-development'
)
})
it('picks the option-1 product whose link is the page when products share a path', () => {
navigation.pathname = '/guides/platform/backups'
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar()
expect(
screen.getByRole('button', { name: 'Backups and upgrades, back to Run and manage' })
).toBeTruthy()
})
it.each([
['/guides/realtime/broadcast', 'Realtime, back to Products'],
['/guides/graphql/views', 'REST and GraphQL APIs, back to Products'],
['/guides/observability/cli-logs', 'Logs and monitoring, back to Run and manage'],
['/guides/observability/log-drains', 'Logs and monitoring, back to Run and manage'],
['/guides/deployment/terraform/tutorial', 'Terraform, back to Develop and deploy'],
])('opens the option-1 product whose tree holds %s', (pathname, backButtonName) => {
navigation.pathname = pathname
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar()
expect(screen.getByRole('button', { name: backButtonName })).toBeTruthy()
})
it.each([
['/guides/platform/read-replicas', 'Database, back to Products'],
['/guides/api/rest/generating-types', 'Local development and CLI, back to Develop and deploy'],
])('opens %s in the option-1 section whose tree lists it', (pathname, backButtonName) => {
navigation.pathname = pathname
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar()
expect(screen.getByRole('button', { name: backButtonName })).toBeTruthy()
})
it('marks only the product of the page as current when products share a path', () => {
navigation.pathname = '/guides/platform/backups'
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar()
fireEvent.click(
screen.getByRole('button', { name: 'Backups and upgrades, back to Run and manage' })
)
const currentLinks = screen
.getAllByRole('link')
.filter((link) => link.getAttribute('aria-current') === 'page')
expect(currentLinks.map((link) => link.textContent)).toEqual(['Backups and upgrades'])
})
it('keeps the level when a modified click opens a product in another tab', () => {
renderSidebar()
fireEvent.click(screen.getByRole('button', { name: 'Database, back to Products' }))
fireEvent.click(screen.getByRole('link', { name: 'Auth' }), { metaKey: true })
expect(screen.getByRole('button', { name: 'Products, back to Home' })).toBeTruthy()
})
it('links the resources home when the tree lists only the glossary', () => {
navigation.pathname = '/guides/resources/glossary'
renderSidebar()
expect(screen.getByRole('link', { name: 'Getting started' }).getAttribute('href')).toBe(
'/guides/resources'
)
})
it('names the resources level after its tree on the resources home', () => {
navigation.pathname = '/guides/resources'
renderSidebar()
expect(screen.getByRole('button', { name: 'Resources, back to Home' })).toBeTruthy()
})
it('opens the levels of the new page after browsing away from the last one', () => {
const { rerender } = renderSidebar()
fireEvent.click(screen.getByRole('button', { name: 'Database, back to Products' }))
navigation.pathname = '/guides/auth'
rerender(sidebar())
expect(screen.getByRole('button', { name: 'Auth, back to Products' })).toBeTruthy()
})
it('adds no getting started link when the tree already lists the home page', () => {
renderSidebar()
expect(screen.queryByRole('link', { name: 'Getting started' })).toBeNull()
})
it('goes back one level and names the level it goes to', () => {
renderSidebar()
fireEvent.click(screen.getByRole('button', { name: 'Database, back to Products' }))
expect(screen.getByText('depth 2')).toBeTruthy()
expect(screen.getByRole('button', { name: 'Products, back to Home' })).toBeTruthy()
})
it('keeps keyboard focus in the sidebar when the focused back button goes away', () => {
renderSidebar()
fireEvent.click(screen.getByRole('button', { name: 'Database, back to Products' }))
const backButton = screen.getByRole('button', { name: 'Products, back to Home' })
backButton.focus()
fireEvent.click(backButton)
expect(backButton.isConnected).toBe(false)
expect(document.activeElement).not.toBe(document.body)
})
it('links a product row to its overview and opens its pages', () => {
renderSidebar()
fireEvent.click(screen.getByRole('button', { name: 'Database, back to Products' }))
const authRow = screen.getByRole('link', { name: 'Auth' })
fireEvent.click(authRow)
expect(authRow.getAttribute('href')).toBe('/guides/auth')
expect(screen.getByRole('link', { name: 'Password-based' })).toBeTruthy()
})
it('opens reference pages on the reference list with a way back to the sections', () => {
navigation.pathname = '/reference/javascript'
renderSidebar()
expect(screen.getByText('depth 2')).toBeTruthy()
expect(screen.getByRole('link', { name: 'JavaScript' })).toBeTruthy()
expect(screen.getByRole('button', { name: 'Reference, back to Home' })).toBeTruthy()
})
it.each([
['/reference/server/introduction', MenuId.RefServerV1, '/reference/server'],
['/reference/cli/supabase-login', MenuId.RefCli, '/reference/cli/introduction'],
])(
'marks the library of %s as current in the option-1 reference list',
(pathname, menuId, libraryHref) => {
navigation.pathname = pathname
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar(menuId)
const currentLinks = screen
.getAllByRole('link')
.filter((link) => link.hasAttribute('aria-current'))
expect(currentLinks.map((link) => link.getAttribute('href'))).toEqual([libraryHref])
}
)
it('opens a reference with its nav in the sidebar as a level under the reference list', () => {
navigation.pathname = '/reference/api/introduction'
vi.mocked(useNavItems).mockReturnValue(option1NavItems)
renderSidebar(MenuId.RefApi)
expect(screen.getByRole('button', { name: 'Management API, back to Reference' })).toBeTruthy()
expect(screen.getByText('page tree')).toBeTruthy()
expect(screen.queryByRole('link', { name: 'JavaScript' })).toBeNull()
})
it('puts the knowledge base first in the footer and leaves out the changelog', () => {
render(<DocsSidebarResources />)
const footerLinks = screen.getAllByRole('link')
expect(footerLinks[0].getAttribute('href')).toBe('https://supabase.com/kb')
expect(footerLinks.map((link) => link.textContent)).not.toContain('Changelog')
})
it.each([
['/guides/resources', []],
['/guides/resources/glossary', ['Glossary']],
])('marks a footer link current only on its own page (%s)', (pathname, currentLabels) => {
navigation.pathname = pathname
render(<DocsSidebarResources />)
const currentLinks = screen
.getAllByRole('link')
.filter((link) => link.getAttribute('aria-current') === 'page')
expect(currentLinks.map((link) => link.textContent)).toEqual(currentLabels)
})
})