-
Notifications
You must be signed in to change notification settings - Fork 5
/
mjml-chart.spec.js
110 lines (103 loc) · 3.17 KB
/
mjml-chart.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
101
102
103
104
105
106
107
108
109
110
/**
*
* mjml-chart test suite
*
* Compile and run the tests:
* npm test
*
*/
import { expect } from 'chai';
import mjml2html from 'mjml';
import {registerComponent, components } from 'mjml-core';
import ChartComponent from '../src';
describe('mjml-chart', () => {
before(() => {
registerComponent(ChartComponent);
});
describe('compile-time error handling', () => {
it('should crash at compile time in case of missing (cht) required attributes', () =>
expect(() =>
mjml2html(`
<mjml>
<mj-body>
<mj-chart
chs="300x200"
chd="t:10,20,30|15,25,35"
chxt="x,y"
chxl="0:|A|B|C" />
</mj-body>
</mjml>`).errors
).to.throw('cht is required'));
it('should crash at compile time in case of bad formatted attributes', () =>
expect(() => mjml2html(`
<mjml>
<mj-body>
<mj-chart
chs="300x200"
chd="t:10,20,30|15,25,35"
cht="aa"
chxt="x,y"
chxl="0:|A|B|C" />
</mj-body>
</mjml>`).errors
).to.throw(
'"aa" is not an valid value for cht. Valid values are: ["bvs","bhs","bvg","bhg","bvo","p","p3","pc","pd","ls","lc","lxy","ls:nda","lc:nda","lxy:nda"]'
));
it('should crash at compile time in case of bad attribute values', () =>
expect(() => {
mjml2html(`
<mjml>
<mj-body>
<mj-chart
chs="300x200"
chd="INVALID_CHD_VALUE"
cht="bvs"
chxt="x,y"
chxl="0:|A|B|C" />
</mj-body>
</mjml>`)
}).to.throw(
'"INVALID_CHD_VALUE" is an invalid value for chd. Examples: t:10,20,30|15,25,35'
));
});
describe('chart generation', () => {
it('should render a mjml chart', () => {
expect(
mjml2html(`
<mjml>
<mj-body>
<mj-chart
chs="300x200"
chd="t:10,20,30|15,25,35"
cht="bvs"
chxt="x,y"
chxl="0:|A|B|C" />
</mj-body>
</mjml>`).html
).to.contain(
'<img\n height="auto" src="https://image-charts.com/chart?cht=bvs&chd=t%3A10%2C20%2C30%7C15%2C25%2C35&chs=300x200&chxt=x%2Cy&chxl=0%3A%7CA%7CB%7CC" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;" width="300"\n />'
);
});
it('should render mjml-image attributes', () => {
expect(
mjml2html(`
<mjml>
<mj-body>
<mj-chart
alt="alt"
align="left"
chs="300x200"
chd="t:10,20,30|15,25,35"
cht="bvg"
chxt="x,y"
chxl="0:|A|B|C" />
</mj-body>
</mjml>`).html
)
.to.contain(`align="left"`)
.contain(
'<img\n alt="alt" height="auto" src="https://image-charts.com/chart?cht=bvg&chd=t%3A10%2C20%2C30%7C15%2C25%2C35&chs=300x200&chxt=x%2Cy&chxl=0%3A%7CA%7CB%7CC" style="border:0;display:block;outline:none;text-decoration:none;height:auto;width:100%;" width="300"\n />'
);
});
});
});