2017-03-18 14:13:22 -07:00
|
|
|
import React from 'react';
|
2018-07-25 19:17:34 -04:00
|
|
|
import renderer from 'react-test-renderer';
|
2017-03-18 14:13:22 -07:00
|
|
|
import { padStart } from 'lodash';
|
2018-07-25 19:17:34 -04:00
|
|
|
import MarkdownPreview from '../MarkdownPreview';
|
|
|
|
import { markdownToHtml } from '../serializers';
|
2017-08-31 20:28:11 -04:00
|
|
|
|
2017-08-01 18:51:30 -04:00
|
|
|
describe('Markdown Preview renderer', () => {
|
2017-03-18 14:13:22 -07:00
|
|
|
describe('Markdown rendering', () => {
|
|
|
|
describe('General', () => {
|
|
|
|
it('should render markdown', () => {
|
2016-09-22 22:34:43 +02:00
|
|
|
const value = `
|
2016-09-22 17:36:02 +02:00
|
|
|
# H1
|
|
|
|
|
|
|
|
Text with **bold** & _em_ elements
|
|
|
|
|
|
|
|
## H2
|
|
|
|
|
|
|
|
* ul item 1
|
|
|
|
* ul item 2
|
|
|
|
|
|
|
|
### H3
|
|
|
|
|
|
|
|
1. ol item 1
|
|
|
|
1. ol item 2
|
|
|
|
1. ol item 3
|
|
|
|
|
|
|
|
#### H4
|
|
|
|
|
|
|
|
[link title](http://google.com)
|
|
|
|
|
|
|
|
##### H5
|
|
|
|
|
|
|
|
![alt text](https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg)
|
|
|
|
|
|
|
|
###### H6
|
2018-10-26 14:00:11 -04:00
|
|
|
|
|
|
|
![](https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg)
|
2016-09-23 19:56:35 +02:00
|
|
|
`;
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-23 19:56:35 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-18 14:13:22 -07:00
|
|
|
describe('Headings', () => {
|
2016-09-26 13:18:22 +02:00
|
|
|
for (const heading of [...Array(6).keys()]) {
|
2018-08-07 14:46:54 -06:00
|
|
|
it(`should render Heading ${heading + 1}`, () => {
|
2017-03-18 14:13:22 -07:00
|
|
|
const value = padStart(' Title', heading + 7, '#');
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-26 13:31:36 +02:00
|
|
|
});
|
2016-09-26 13:18:22 +02:00
|
|
|
}
|
2016-09-26 13:31:36 +02:00
|
|
|
});
|
2016-09-26 13:18:22 +02:00
|
|
|
|
2017-03-18 14:13:22 -07:00
|
|
|
describe('Lists', () => {
|
|
|
|
it('should render lists', () => {
|
2016-09-23 19:56:35 +02:00
|
|
|
const value = `
|
|
|
|
1. ol item 1
|
|
|
|
1. ol item 2
|
2017-06-09 23:49:14 -04:00
|
|
|
* Sublist 1
|
|
|
|
* Sublist 2
|
|
|
|
* Sublist 3
|
|
|
|
1. Sub-Sublist 1
|
|
|
|
1. Sub-Sublist 2
|
|
|
|
1. Sub-Sublist 3
|
2016-09-23 19:56:35 +02:00
|
|
|
1. ol item 3
|
2016-09-22 21:52:43 +02:00
|
|
|
`;
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-18 14:13:22 -07:00
|
|
|
describe('Links', () => {
|
|
|
|
it('should render links', () => {
|
2016-09-22 22:34:43 +02:00
|
|
|
const value = `
|
|
|
|
I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3].
|
|
|
|
|
|
|
|
[1]: http://google.com/ "Google"
|
|
|
|
[2]: http://search.yahoo.com/ "Yahoo Search"
|
|
|
|
[3]: http://search.msn.com/ "MSN Search"
|
|
|
|
`;
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-18 14:13:22 -07:00
|
|
|
describe('Code', () => {
|
|
|
|
it('should render code', () => {
|
|
|
|
const value = 'Use the `printf()` function.';
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
|
2017-03-18 14:13:22 -07:00
|
|
|
it('should render code 2', () => {
|
|
|
|
const value = '``There is a literal backtick (`) here.``';
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
2016-09-22 21:52:43 +02:00
|
|
|
|
2017-03-18 14:13:22 -07:00
|
|
|
describe('HTML', () => {
|
|
|
|
it('should render HTML as is when using Markdown', () => {
|
2016-09-22 22:34:43 +02:00
|
|
|
const value = `
|
2016-09-22 21:52:43 +02:00
|
|
|
# Title
|
2016-09-22 17:36:02 +02:00
|
|
|
|
2016-09-27 11:26:28 +02:00
|
|
|
<form action="test">
|
|
|
|
<label for="input">
|
|
|
|
<input type="checkbox" checked="checked" id="input"/> My label
|
2016-12-27 23:16:46 -08:00
|
|
|
</label>
|
2016-09-27 11:26:28 +02:00
|
|
|
<dl class="test-class another-class" style="width: 100%">
|
|
|
|
<dt data-attr="test">Test HTML content</dt>
|
|
|
|
<dt>Testing HTML in Markdown</dt>
|
|
|
|
</dl>
|
|
|
|
</form>
|
2016-09-27 12:18:52 +02:00
|
|
|
|
|
|
|
<h1 style="display: block; border: 10px solid #f00; width: 100%">Test</h1>
|
2016-09-22 17:36:02 +02:00
|
|
|
`;
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
2016-09-22 17:36:02 +02:00
|
|
|
});
|
|
|
|
|
2017-03-18 14:13:22 -07:00
|
|
|
describe('HTML rendering', () => {
|
|
|
|
it('should render HTML', () => {
|
|
|
|
const value = '<p>Paragraph with <em>inline</em> element</p>';
|
2018-07-25 19:17:34 -04:00
|
|
|
expect(
|
2018-08-07 14:46:54 -06:00
|
|
|
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),
|
|
|
|
).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
2016-09-22 17:36:02 +02:00
|
|
|
});
|
|
|
|
});
|