static-cms/src/components/Widgets/__tests__/MarkitupReactRenderer.spec.js

119 lines
2.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
2016-09-22 21:52:43 +02:00
import { shallow } from 'enzyme';
import markdownSyntax from 'markup-it/syntaxes/markdown';
import htmlSyntax from 'markup-it/syntaxes/html';
import MarkitupReactRenderer from '../MarkitupReactRenderer';
describe('MarkitupReactRenderer', () => {
2016-09-22 21:52:43 +02:00
it('should re-render properly after a value and syntax update', () => {
const component = shallow(
<MarkitupReactRenderer
value="# Title"
syntax={markdownSyntax}
/>
);
const tree1 = component.html();
component.setProps({
value: '<h1>Title</h1>',
syntax: htmlSyntax
});
const tree2 = component.html();
expect(tree1).toEqual(tree2);
});
it('should not update the parser if syntax didn\'t change', () => {
const component = shallow(
<MarkitupReactRenderer
value="# Title"
syntax={markdownSyntax}
/>
);
const syntax1 = component.instance().props.syntax;
component.setProps({
value: '## Title',
});
const syntax2 = component.instance().props.syntax;
expect(syntax1).toEqual(syntax2);
});
it('should render markdown', () => {
const value = `
# 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
2016-09-22 21:52:43 +02:00
`;
const component = shallow(
<MarkitupReactRenderer
value={value}
syntax={markdownSyntax}
/>
);
const tree = component.html();
expect(tree).toMatchSnapshot();
});
it('should render HTML as is using Markdown', () => {
const value = `
# Title
2016-09-22 21:52:43 +02:00
<dl>
<dt>Test HTML content</dt>
<dd>Testing HTML in Markdown</dd>
</dl>
`;
2016-09-22 21:52:43 +02:00
const component = shallow(
<MarkitupReactRenderer
value={value}
syntax={markdownSyntax}
/>
);
2016-09-22 21:52:43 +02:00
const tree = component.html();
expect(tree).toMatchSnapshot();
});
it('should support custom syntax', () => {
const value = '';
2016-09-22 21:52:43 +02:00
const component = shallow(
<MarkitupReactRenderer
value={value}
syntax={markdownSyntax}
/>
);
2016-09-22 21:52:43 +02:00
const tree = component.html();
expect(tree).toMatchSnapshot();
});
it('should render HTML', () => {
const value = '<p class="test class">Paragraph with <em>inline</em> element</p>';
2016-09-22 21:52:43 +02:00
const component = shallow(
<MarkitupReactRenderer
value={value}
syntax={htmlSyntax}
/>
);
2016-09-22 21:52:43 +02:00
const tree = component.html();
expect(tree).toMatchSnapshot();
});
});