Skip to content
This repository has been archived by the owner on Mar 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #315 from RaenonX-DL/dev
Browse files Browse the repository at this point in the history
v2.15.0-beta.2 Release
  • Loading branch information
RaenonX authored Sep 28, 2021
2 parents 8e54a44 + 5faf468 commit e3f7573
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/elements/markdown/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import {MarkdownComponentProps} from '../types';
const headers: Array<Array<React.ReactNode>> = [] as Array<Array<React.ReactNode>>;
let idxCounter = 0;

export const renderTable = ({children}: MarkdownComponentProps) => (
<table>{children}</table>
);
export const renderTable = ({children}: MarkdownComponentProps) => {
// Empty `headers` because a new table is to be rendered
// https://stackoverflow.com/q/1232040
headers.length = 0;

return <table>{children}</table>;
};

export const renderTableHeader = ({children}: MarkdownComponentProps) => {
headers.push(children);
Expand Down
12 changes: 12 additions & 0 deletions src/components/elements/markdown/main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ describe('Markdown', () => {
expect(screen.getByText('Data 2')).toBeInTheDocument();
expect(screen.getAllByText('Header')).toHaveLength(2);
});

it('renders multiple responsive tables correctly', async () => {
const text = `A | B\n:---: | :---:\nA1 | B1\n\nC | D\n:---: | :---:\nC1 | D1`;

renderReact(() => <Markdown>{text}</Markdown>);

// Should only have 2 elements available for each header: 1 for desktop, 1 for mobile (responsive header)
expect(screen.getAllByText('A')).toHaveLength(2);
expect(screen.getAllByText('B')).toHaveLength(2);
expect(screen.getAllByText('C')).toHaveLength(2);
expect(screen.getAllByText('D')).toHaveLength(2);
});
});

describe('Markdown - Syntax Nesting', () => {
Expand Down

0 comments on commit e3f7573

Please sign in to comment.