-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathutils.spec.js
111 lines (101 loc) · 3.65 KB
/
utils.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
111
import { expect } from 'chai';
import {
namedEntityToHexCode,
fixConditionalComment,
useHttps,
toMobileFontSize,
getTextAlign,
addQueryParams,
} from '../src/utils/index';
describe('utils', () => {
describe('namedEntityToHexCode', () => {
it('should not replace incomplete entity', () => {
expect(namedEntityToHexCode('&')).to.equal('&');
});
it('should not replace unknown entity', () => {
expect(namedEntityToHexCode('&rambo;')).to.equal('&rambo;');
});
it('should not replace entity in hex code', () => {
expect(namedEntityToHexCode('&')).to.equal('&');
});
it('should replace known entity to hex code', () => {
expect(namedEntityToHexCode('&')).to.equal('&');
expect(namedEntityToHexCode(''')).to.equal(''');
});
});
describe('fixConditionalComment', () => {
it('should not replace if there is no MSO conditionals', () => {
expect(
fixConditionalComment('<!--no changes-->', 'what ever', 'if IE'),
).to.equal('<!--no changes-->');
});
it('should replace condition matching the content', () => {
expect(
fixConditionalComment('<!--[if mso]>...<![endif]-->', '...', 'if IE'),
).to.equal('<!--[if IE]>...<![endif]-->');
});
});
describe('useHttps', () => {
it('should not alter falsy url', () => {
expect(useHttps('')).to.equal('');
});
it('should not alter valid url', () => {
expect(useHttps('https://www.wix.com')).to.equal('https://www.wix.com');
});
it('should replace http://', () => {
expect(useHttps('http://www.wix.com')).to.equal('https://www.wix.com');
});
it('should replace //', () => {
expect(useHttps('//www.wix.com')).to.equal('https://www.wix.com');
});
it('should not add missing schema', () => {
expect(useHttps('www.wix.com')).to.equal('www.wix.com');
});
});
describe('toMobileFontSize', () => {
it('minimum should be 12', () => {
[...Array(12).keys()].forEach((value) => {
expect(toMobileFontSize(value)).to.equal(12);
expect(toMobileFontSize(`${value}px`)).to.equal(12);
});
});
it('not modified from 12 to 26', () => {
Array.from(Array(14).keys()).forEach((value) => {
expect(toMobileFontSize(value + 12)).to.equal(value + 12);
expect(toMobileFontSize(`${value + 12}px`)).to.equal(value + 12);
});
});
it('max should be 50', () => {
expect(toMobileFontSize(200)).to.equal(50);
});
});
describe('getTextAlign', () => {
it('should return default alignment', () => {
expect(getTextAlign()).to.equal('center');
expect(getTextAlign(null, 'left')).to.equal('left');
});
it('should return default alignment if value is unrecognized', () => {
expect(getTextAlign('blah')).to.equal('center');
});
it('should return a valid text align', () => {
expect(getTextAlign('left')).to.equal('left');
expect(getTextAlign('right')).to.equal('right');
expect(getTextAlign('center')).to.equal('center');
expect(getTextAlign('inherit')).to.equal('inherit');
expect(getTextAlign('justify')).to.equal('justify');
});
});
describe('addQueryParams', () => {
it('should add a single query param', () => {
expect(addQueryParams('url', { one: 'two' })).to.equal('url?one=two');
});
it('should add multiple query params', () => {
expect(addQueryParams('url', { one: 'two', three: 'four' })).to.equal(
'url?one=two&three=four',
);
});
it('should escape param value', () => {
expect(addQueryParams('url', { one: '?two' })).to.equal('url?one=%3Ftwo');
});
});
});