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
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { render } from '@testing-library/react';

import MetaBar from '..';

describe('MetaBar', () => {
it('does not render h5s in the table of contents', () => {
const { queryByText, getByText } = render(
<MetaBar
items={{}}
headings={{
items: [
{
value: 'Heading Level 1',
depth: 1,
data: { id: 'heading-1' },
},
{
value: 'Heading Level 2',
depth: 2,
data: { id: 'heading-2' },
},
{
value: 'Heading Level 3',
depth: 3,
data: { id: 'heading-3' },
},
{
value: 'Heading Level 4',
depth: 4,
data: { id: 'heading-4' },
},
{
value: 'Heading Level 5',
depth: 5,
data: { id: 'heading-5' },
},
{
value: 'Heading Level 6',
depth: 6,
data: { id: 'heading-6' },
},
],
}}
/>
);

const h1Element = queryByText('Heading Level 1');
expect(h1Element).not.toBeInTheDocument();

getByText('Heading Level 2');
getByText('Heading Level 3');
getByText('Heading Level 4');

const h5Element = queryByText('Heading Level 5');
expect(h5Element).not.toBeInTheDocument();

const h6Element = queryByText('Heading Level 6');
expect(h6Element).not.toBeInTheDocument();
});
});
15 changes: 15 additions & 0 deletions apps/site/components/Containers/MetaBar/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ export const Default: Story = {
depth: 3,
data: { id: 'contact_and_future_updates' },
},
{
value: 'Email',
depth: 4,
data: { id: 'email' },
},
{
value: 'Slack',
depth: 4,
data: { id: 'slack' },
},
{
value: '#node-website',
depth: 5, // h5s do not get shown
data: { id: 'node-website' },
},
],
},
},
Expand Down
9 changes: 7 additions & 2 deletions apps/site/components/Containers/MetaBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ const MetaBar: FC<MetaBarProps> = ({ items, headings }) => {
<dd>
<ol>
{heading.map(head => (
<li key={head.value}>
<Link href={`#${head?.data?.id}`}>{head.value}</Link>
<li
key={head.value}
className={
head.depth === 3 ? 'pl-2' : head.depth === 4 ? 'pl-4' : ''
}
>
<Link href={`#${head?.data?.id}`}> {head.value}</Link>
</li>
))}
</ol>
Expand Down
Loading