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
22 changes: 16 additions & 6 deletions __tests__/components/TableOfContents.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const glossaryTerms = [
},
];

describe.skip('Table of Contents', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed skipping the whole block and moved to the failing cases so a few passing test cases can be included.

describe('Table of Contents', () => {
it('should have a header', () => {
const { container } = render(
<TableOfContents>
Expand All @@ -27,7 +27,7 @@ describe.skip('Table of Contents', () => {
expect(container.querySelectorAll('li')[0]).toHaveTextContent('Table of Contents');
});

it('generates TOC from headings', () => {
it.skip('generates TOC from headings', () => {
const txt = '# Heading Zed\n\n# Heading One';
const ast = reactProcessor().parse(txt);
const toc = reactTOC(ast);
Expand All @@ -36,7 +36,7 @@ describe.skip('Table of Contents', () => {
expect(container.querySelectorAll('li > a[href]:not([href="#"])')).toHaveLength(2);
});

it('includes two heading levels', () => {
it.skip('includes two heading levels', () => {
const txt = '# Heading Zed\n\n## Subheading One\n\n### Deep Heading Two';
const ast = reactProcessor().parse(txt);
const toc = reactTOC(ast);
Expand All @@ -46,7 +46,7 @@ describe.skip('Table of Contents', () => {
expect(container.innerHTML).toMatchSnapshot();
});

it('normalizes root depth level', () => {
it.skip('normalizes root depth level', () => {
const txt = '##### Heading Zed\n\n###### Subheading Zed';
const ast = reactProcessor().parse(txt);
const toc = reactTOC(ast);
Expand All @@ -55,7 +55,7 @@ describe.skip('Table of Contents', () => {
expect(container.querySelectorAll('li > a[href]:not([href="#"])')).toHaveLength(2);
});

it('includes variables', () => {
it.skip('includes variables', () => {
const txt = '# Heading <<test>>';
const ast = reactProcessor().parse(txt);
const toc = reactTOC(ast);
Expand All @@ -64,7 +64,7 @@ describe.skip('Table of Contents', () => {
expect(container.querySelector('li > a[href]:not([href="#"])')).toHaveTextContent(`Heading ${variables.user.test}`);
});

it('includes glossary items', () => {
it.skip('includes glossary items', () => {
const txt = '# Heading <<glossary:demo>>';
const ast = reactProcessor().parse(txt);
const toc = reactTOC(ast);
Expand All @@ -74,4 +74,14 @@ describe.skip('Table of Contents', () => {
`Heading ${glossaryTerms[0].term}`,
);
});

it('accepts custom heading', () => {
const { container } = render(
<TableOfContents heading="Custom Heading">
<h1>Heading 1</h1>
</TableOfContents>,
);

expect(container.querySelectorAll('li')[0]).toHaveTextContent('Custom Heading');
});
});
4 changes: 2 additions & 2 deletions components/TableOfContents/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';

function TableOfContents({ children }: React.PropsWithChildren) {
function TableOfContents({ children, heading = 'Table of Contents' }: React.PropsWithChildren<{ heading?: string }>) {
return (
<nav aria-label="Table of contents" role="navigation">
<ul className="toc-list">
<li>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a className="tocHeader" href="#">
<i className="icon icon-text-align-left"></i>
Table of Contents
{heading}
</a>
</li>
<li className="toc-children">{children}</li>
Expand Down
6 changes: 3 additions & 3 deletions lib/run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ const run = (string: string, _opts: RunOpts = {}) => {
</Contexts>
),
toc,
Toc: props =>
Toc: (props: { heading?: string }) =>
Toc ? (
<Components.TableOfContents>
<Toc {...props} />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there are actually any props getting passed in here?

<Components.TableOfContents heading={props.heading}>
<Toc />
</Components.TableOfContents>
) : null,
stylesheet,
Expand Down