Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/landing/src/components/header.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Header } from './header';

describe('Header', () => {
it('points Features at the home-page section, not a same-page fragment', () => {
// Regression: a bare `#features` resolved against the current path
// (e.g. /docs/#features) when the header rendered on a sub-page.
render(<Header />);
expect(screen.getByRole('link', { name: /features/i })).toHaveAttribute(
'href',
'/#features',
);
});

it('links Docs, Privacy, and Changelog to their routes', () => {
// Next's Link normalizes the trailing slash in the rendered DOM, so
// match the route with an optional trailing slash rather than exact.
render(<Header />);
expect(screen.getByRole('link', { name: /docs/i }).getAttribute('href')).toMatch(
/^\/docs\/?$/,
);
expect(screen.getByRole('link', { name: /privacy/i }).getAttribute('href')).toMatch(
/^\/privacy\/?$/,
);
expect(screen.getByRole('link', { name: /changelog/i }).getAttribute('href')).toMatch(
/^\/changelog\/?$/,
);
});
});
6 changes: 5 additions & 1 deletion packages/landing/src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import Link from 'next/link';
import { ThemeToggle } from './theme-toggle';
import { Button } from './ui/button';

// `/#features` is absolute on purpose: the header renders on every route, so
// a bare `#features` would resolve against the current path (e.g.
// `/docs/#features`) and go nowhere. The leading slash always targets the
// Features section on the home page.
const NAV_LINKS = [
{ href: '#features', label: 'Features' },
{ href: '/#features', label: 'Features' },
{ href: '/docs/', label: 'Docs' },
{ href: '/privacy/', label: 'Privacy' },
{ href: '/changelog/', label: 'Changelog' },
Expand Down
Loading