2016-09-22 22:34:43 +02:00
|
|
|
/* eslint max-len:0 */
|
|
|
|
|
2017-03-01 15:58:12 -08:00
|
|
|
import React from "react";
|
|
|
|
import { shallow } from "enzyme";
|
|
|
|
import { padStart } from "lodash";
|
|
|
|
import MarkupItReactRenderer from "../";
|
|
|
|
|
|
|
|
describe("MarkitupReactRenderer", () => {
|
|
|
|
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
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
###### H6
|
2016-09-23 19:56:35 +02:00
|
|
|
`;
|
2017-03-01 15:58:12 -08:00
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
2016-09-23 19:56:35 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-01 15:58:12 -08:00
|
|
|
describe("Headings", () => {
|
2016-09-26 13:18:22 +02:00
|
|
|
for (const heading of [...Array(6).keys()]) {
|
2016-10-12 15:52:41 +02:00
|
|
|
it(`should render Heading ${ heading + 1 }`, () => {
|
2017-03-01 15:58:12 -08:00
|
|
|
const value = padStart(" Title", heading + 7, "#");
|
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
|
|
|
});
|
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-01 15:58:12 -08: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
|
|
|
|
* Sublist 1
|
|
|
|
* Sublist 2
|
|
|
|
* Sublist 3
|
|
|
|
1. Sub-Sublist 1
|
|
|
|
1. Sub-Sublist 2
|
|
|
|
1. Sub-Sublist 3
|
|
|
|
1. ol item 3
|
2016-09-22 21:52:43 +02:00
|
|
|
`;
|
2017-03-01 15:58:12 -08:00
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-01 15:58:12 -08: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"
|
|
|
|
`;
|
2017-03-01 15:58:12 -08:00
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-01 15:58:12 -08:00
|
|
|
describe("Code", () => {
|
|
|
|
it("should render code", () => {
|
|
|
|
const value = "Use the `printf()` function.";
|
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
|
2017-03-01 15:58:12 -08:00
|
|
|
it("should render code 2", () => {
|
|
|
|
const value = "``There is a literal backtick (`) here.``";
|
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
2016-09-22 21:52:43 +02:00
|
|
|
|
2017-03-01 15:58:12 -08: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
|
|
|
`;
|
2017-03-01 15:58:12 -08:00
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
|
|
|
});
|
2016-09-22 17:36:02 +02:00
|
|
|
});
|
|
|
|
|
2017-03-01 15:58:12 -08:00
|
|
|
describe("HTML rendering", () => {
|
|
|
|
it("should render HTML", () => {
|
|
|
|
const value = "<p>Paragraph with <em>inline</em> element</p>";
|
|
|
|
const component = shallow(<MarkupItReactRenderer value={value} />);
|
2016-09-26 13:31:36 +02:00
|
|
|
expect(component.html()).toMatchSnapshot();
|
2016-09-22 22:34:43 +02:00
|
|
|
});
|
2016-09-22 17:36:02 +02:00
|
|
|
});
|
|
|
|
});
|