-
Notifications
You must be signed in to change notification settings - Fork 46
Update docs navigation to horizontal #3303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b7ed7a
feat(nav): redesign header with Platform/Products/Examples tabs
m-hulbert 9aeae9e
feat(nav): add ProductBar and restructure layout
m-hulbert 2b7fbfd
feat(nav): add CopyForLLM split button
m-hulbert 3bbfe2d
refactor(nav): flatten left sidebar and move language selector
m-hulbert 8df728a
refactor(nav): extract hasProductBar to layout context and simplify h…
m-hulbert 7996f43
feat(nav): update navigation structure for products
m-hulbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import React, { ReactNode } from 'react'; | ||
| import { render, screen, fireEvent, act, waitFor } from '@testing-library/react'; | ||
| import CopyForLLM from './CopyForLLM'; | ||
|
|
||
| const mockUseLayoutContext = jest.fn(() => ({ | ||
| activePage: { | ||
| language: 'javascript', | ||
| languages: ['javascript'], | ||
| product: 'pubsub', | ||
| page: { | ||
| name: 'Test Page', | ||
| link: '/docs/test-page', | ||
| }, | ||
| tree: [], | ||
| template: 'mdx' as const, | ||
| }, | ||
| })); | ||
|
|
||
| jest.mock('src/contexts/layout-context', () => ({ | ||
| useLayoutContext: () => mockUseLayoutContext(), | ||
| })); | ||
|
|
||
| jest.mock('@reach/router', () => ({ | ||
| useLocation: () => ({ pathname: '/docs/test-page' }), | ||
| })); | ||
|
|
||
| jest.mock('@ably/ui/core/Icon', () => ({ | ||
| __esModule: true, | ||
| default: ({ name }: { name: string }) => <span data-testid={`icon-${name}`}>{name}</span>, | ||
| })); | ||
|
|
||
| jest.mock('@ably/ui/core/insights', () => ({ | ||
| track: jest.fn(), | ||
| })); | ||
|
|
||
| // Mock Radix DropdownMenu to render content directly | ||
| jest.mock('@radix-ui/react-dropdown-menu', () => ({ | ||
| Root: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| Trigger: ({ children }: { children: ReactNode; asChild?: boolean }) => <div>{children}</div>, | ||
| Portal: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| Content: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| Item: ({ | ||
| children, | ||
| onSelect, | ||
| ...props | ||
| }: { | ||
| children: ReactNode; | ||
| onSelect?: (e: Event) => void; | ||
| asChild?: boolean; | ||
| }) => | ||
| props.asChild ? ( | ||
| <>{children}</> | ||
| ) : ( | ||
| <div onClick={() => onSelect?.({ preventDefault: () => undefined } as unknown as Event)}>{children}</div> | ||
| ), | ||
| Separator: () => <hr />, | ||
| })); | ||
|
|
||
| describe('CopyForLLM', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.useRealTimers(); | ||
| jest.restoreAllMocks(); | ||
| jest.clearAllTimers(); | ||
| }); | ||
|
|
||
| it('renders the dropdown trigger button', () => { | ||
| global.fetch = jest.fn(() => Promise.resolve({ ok: false, status: 404 } as Response)); | ||
|
|
||
| render(<CopyForLLM />); | ||
| expect(screen.getByText('Copy for LLM')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders LLM links for ChatGPT and Claude', () => { | ||
| global.fetch = jest.fn(() => Promise.resolve({ ok: false, status: 404 } as Response)); | ||
|
|
||
| render(<CopyForLLM />); | ||
| expect(screen.getByText('Open in ChatGPT')).toBeInTheDocument(); | ||
| expect(screen.getByText('Open in Claude')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows markdown items when content is available', async () => { | ||
| const mockMarkdown = '# Test content'; | ||
|
|
||
| global.fetch = jest.fn(() => | ||
| Promise.resolve({ | ||
| ok: true, | ||
| headers: { | ||
| get: (name: string) => (name === 'Content-Type' ? 'text/markdown' : null), | ||
| }, | ||
| text: () => Promise.resolve(mockMarkdown), | ||
| } as Response), | ||
| ); | ||
|
|
||
| const mockWriteText = jest.fn(); | ||
| Object.assign(navigator, { clipboard: { writeText: mockWriteText } }); | ||
|
|
||
| render(<CopyForLLM />); | ||
|
|
||
| // Wait for the markdown to be fetched and state to update (button becomes enabled) | ||
| const copyButton = await screen.findByText('Copy for LLM'); | ||
| await waitFor(() => { | ||
| expect(copyButton.closest('button')).not.toBeDisabled(); | ||
| }); | ||
|
|
||
| jest.useFakeTimers(); | ||
|
|
||
| // Click copy via the dropdown item | ||
| const copyItem = screen.getByText('Copy as markdown').closest('div'); | ||
| if (copyItem) { | ||
| act(() => { | ||
| fireEvent.click(copyItem); | ||
| }); | ||
| } | ||
|
|
||
| expect(mockWriteText).toHaveBeenCalledWith(mockMarkdown); | ||
|
|
||
| act(() => { | ||
| jest.runOnlyPendingTimers(); | ||
| }); | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| it('disables copy button when fetch fails', async () => { | ||
| global.fetch = jest.fn(() => Promise.resolve({ ok: false, status: 404 } as Response)); | ||
|
|
||
| render(<CopyForLLM />); | ||
|
|
||
| await new Promise<void>((resolve) => setTimeout(resolve, 50)); | ||
|
|
||
| const copyButton = screen.getByText('Copy for LLM').closest('button'); | ||
| expect(copyButton).toBeDisabled(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.