-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathextensions.spec.js
100 lines (93 loc) · 3.34 KB
/
extensions.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react';
import { expect } from 'chai';
import { renderToMjml } from '../src';
import {
MjmlComment,
MjmlConditionalComment,
MjmlYahooStyle,
MjmlTrackingPixel,
MjmlHtml,
} from '../src/extensions';
describe('extensions', () => {
describe('simple comment', () => {
it('should render', () => {
const comment = (
<MjmlComment>
First, solve the problem. Then, write the code.
</MjmlComment>
);
const markup = renderToMjml(comment);
expect(markup).to.equal(
'<mj-raw><!--First, solve the problem. Then, write the code.--></mj-raw>',
);
});
it('should not render if comment is empty', () => {
expect(renderToMjml(<MjmlComment />)).to.equal('');
expect(renderToMjml(<MjmlComment>{''}</MjmlComment>)).to.equal('');
expect(renderToMjml(<MjmlComment> </MjmlComment>)).to.equal('');
});
});
describe('conditional comment', () => {
it('should render', () => {
const comment = (
<MjmlConditionalComment>
First, solve the problem. Then, write the code.
</MjmlConditionalComment>
);
const markup = renderToMjml(comment);
expect(markup).to.equal(
'<mj-raw><!--[if gte mso 9]>First, solve the problem. Then, write the code.<![endif]--></mj-raw>',
);
});
it('should allow changing condition', () => {
const comment = (
<MjmlConditionalComment condition="if IE">
First, solve the problem. Then, write the code.
</MjmlConditionalComment>
);
const markup = renderToMjml(comment);
expect(markup).to.equal(
'<mj-raw><!--[if IE]>First, solve the problem. Then, write the code.<![endif]--></mj-raw>',
);
});
it('should not render if comment is empty', () => {
expect(renderToMjml(<MjmlConditionalComment />)).to.equal('');
expect(
renderToMjml(<MjmlConditionalComment>{''}</MjmlConditionalComment>),
).to.equal('');
expect(
renderToMjml(<MjmlConditionalComment> </MjmlConditionalComment>),
).to.equal('');
});
});
describe('yahoo style', () => {
it('should render', () => {
const markup = renderToMjml(
<MjmlYahooStyle>{`a { color: blue; }`}</MjmlYahooStyle>,
);
expect(markup).to.equal(
'<mj-raw><style>@media screen yahoo {a { color: blue; }}</style></mj-raw>',
);
});
});
describe('tracking pixel', () => {
it('should render 1x1 raw image with provided src', () => {
const markup = renderToMjml(<MjmlTrackingPixel src={'tracking-pixel'} />);
expect(markup).to.equal(
'<mj-raw><img src="tracking-pixel" style="display:table;height:1px!important;width:1px!important;border:0!important;margin:0!important;padding:0!important" width="1" height="1" border="0"/></mj-raw>',
);
});
});
describe('html', () => {
it('should allow rendering given HTML using mj-raw tag by default', () => {
const markup = renderToMjml(<MjmlHtml html="<div>hello World</div>" />);
expect(markup).to.equal('<mj-raw><div>hello World</div></mj-raw>');
});
it('should allow rendering given HTML using specified tag', () => {
const markup = renderToMjml(
<MjmlHtml tag="span" html="<div>hello World</div>" />,
);
expect(markup).to.equal('<span><div>hello World</div></span>');
});
});
});