mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem - keyboard users hit focus problems in the option-1 docs layout because the on this page rail clips focus rings and Firefox adds an unlabeled tab stop on the sidebar scroll area - skip link to the content does not render - reference sits in a dropdown next to the logo which doesn't feel optimal - header breadcrumbs repeat the sidebar section with group crumbs that never link ## Solution - fixes the focus rings and tab stops in the sidebar, the rails and the footers so each ring is inset and is not clipped - changes the header breadcrumbs to show the parent and the page + links a group crumb to its overview page when it has one - moves reference into the sidebar section list with a back button + removes the sections dropdown and points the logo to the docs home - moves the knowledge base to the top of the sidebar footer and removes the changelog link - removes the hover backgrounds and color transitions from the sidebar and rail rows + fades the sidebar list under the back button on scroll - aligns the home agent prompt with the second framework column and changes the footer separator to a square <!-- ## 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. --> 1. visit [/docs/guides/database/replication/pipelines?docs-ia-mvp-v1=option-1](https://docs-git-antlio-fix-docs-layout-v2-nits-supabase.vercel.app/docs/guides/database/replication/pipelines?docs-ia-mvp-v1=option-1) 2. reload the page and press Tab once to make sure that the first stop is the skip link to the content 3. press Tab through the sidebar, the on this page rail and the page footer to make sure that each ring is inset and round and is not clipped 4. click the back button in the sidebar until the section list shows, then click `Reference` to make sure that it opens the reference list with a back button ## 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)
234 lines
8.2 KiB
TypeScript
234 lines
8.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
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 { getMenuId } from './NavigationMenu.utils'
|
|
import * as option1NavItems from '~/features/IaNav/option1.constants'
|
|
import { useNavItems } from '~/features/IaNav/useNavItems'
|
|
|
|
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 = getMenuId(navigation.pathname)) => (
|
|
<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, restore and upgrades, back to Run and manage' })
|
|
).toBeTruthy()
|
|
})
|
|
|
|
it.each([
|
|
['/guides/realtime/broadcast', 'REST, GraphQL and Realtime APIs, back to Build'],
|
|
['/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('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, restore 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, restore 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('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)
|
|
})
|
|
})
|