-
Notifications
You must be signed in to change notification settings - Fork 50
/
utils.spec.js
146 lines (134 loc) · 4.95 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { expect } from 'chai';
import {
namedEntityToHexCode,
fixConditionalComment,
useHttps,
toMobileFontSize,
getTextAlign,
addQueryParams,
} from '../src/utils/index';
import { isValidColor } from '../src/utils';
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:https://', () => {
expect(useHttps('http:https://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');
});
});
describe('isValidColor', () => {
it('should return true if #ffffff is passed', () => {
expect(isValidColor('#ffffff')).to.equal(true);
});
it('should return false if #fafafaf is passed', () => {
expect(isValidColor('#fafafaf')).to.equal(false);
});
it('should return false if #g6labc is passed', () => {
expect(isValidColor('#g6labc')).to.equal(false);
});
it('should return true if #fab is passed', () => {
expect(isValidColor('#fab')).to.equal(true);
});
it('should return true if white is passed', () => {
expect(isValidColor('white')).to.equal(true);
});
it('should return true if transparent is passed', () => {
expect(isValidColor('transparent')).to.equal(true);
});
it('should return true if rgb(255,0,0) is passed', () => {
expect(isValidColor('rgb(255,0,0)')).to.equal(true);
});
it('should return false if rgb(255,2) is passed', () => {
expect(isValidColor('rgb(255,2)')).to.equal(false);
});
it('should return true if rgba(255,0,0,0.1) is passed', () => {
expect(isValidColor('rgb(255,0,0,0.1)')).to.equal(true);
});
it('should return false if rgba(255,0) is passed', () => {
expect(isValidColor('rgba(255,0)')).to.equal(false);
});
});
});