import { expect } from 'chai';
import {
getContents,
getDescription,
getTitle,
getHeaders,
getCodeblock,
renderMarkdown,
createRender,
} from './parseMarkdown.mjs';
describe('parseMarkdown', () => {
describe('getTitle', () => {
it('remove backticks', () => {
expect(
getTitle(`
# \`@mui/styled-engine\`
Configuring your preferred styling library.
`),
).to.equal('@mui/styled-engine');
});
});
describe('getDescription', () => {
it('trims the description', () => {
expect(
getDescription(`
Some description
`),
).to.equal('Some description');
});
it('remove backticks', () => {
expect(
getDescription(`
Some \`description\`
`),
).to.equal('Some description');
});
it('should not be greedy', () => {
expect(
getDescription(`
Some description
## Foo
bar
`),
).to.equal('Some description');
});
});
describe('getHeaders', () => {
it('should return a correct result', () => {
expect(
getHeaders(`
---
title: React Alert component
components: Alert, AlertTitle
hooks: useAlert
githubLabel: 'scope: alert'
packageName: '@mui/lab'
waiAria: https://www.w3.org/TR/wai-aria-practices/#alert
authors: ['foo', 'bar']
---
`),
).to.deep.equal({
components: ['Alert', 'AlertTitle'],
hooks: ['useAlert'],
githubLabel: 'scope: alert',
packageName: '@mui/lab',
title: 'React Alert component',
waiAria: 'https://www.w3.org/TR/wai-aria-practices/#alert',
authors: ['foo', 'bar'],
});
});
it('should work with authors broken in two lines', () => {
expect(
getHeaders(`
---
title: React Alert component
components: Alert, AlertTitle
authors:
['foo', 'bar']
---
`),
).to.deep.equal({
components: ['Alert', 'AlertTitle'],
hooks: [],
title: 'React Alert component',
authors: ['foo', 'bar'],
});
});
it('should work with one author per line', () => {
expect(
getHeaders(`
---
title: React Alert component
components: Alert, AlertTitle
authors:
[
'foo',
'bar',
]
---
`),
).to.deep.equal({
components: ['Alert', 'AlertTitle'],
hooks: [],
title: 'React Alert component',
authors: ['foo', 'bar'],
});
});
it('should work with quotes', () => {
expect(
getHeaders(`
---
title: "Our docs just got a major upgrade—here's what that means for you"
---
`),
).to.deep.equal({
title: "Our docs just got a major upgrade—here's what that means for you",
components: [],
hooks: [],
});
});
});
describe('getContents', () => {
describe('Split markdown into an array, separating demos', () => {
it('returns a single entry without a demo', () => {
expect(getContents('# SomeGuide\nwhich has no demo')).to.deep.equal([
'# SomeGuide\nwhich has no demo',
]);
});
it('uses a `{{"demo"` marker to split', () => {
expect(
getContents('# SomeGuide\n{{"demo": "GuideDemo.js" }}\n## NextHeading'),
).to.deep.equal(['# SomeGuide\n', '"demo": "GuideDemo.js" ', '\n## NextHeading']);
});
it('ignores possible code', () => {
expect(getContents('# SomeGuide\n```jsx\n