-
Notifications
You must be signed in to change notification settings - Fork 50
/
utils.spec.js
76 lines (66 loc) · 2.42 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
import {expect} from 'chai';
import {
namedEntityToHexCode,
fixConditionalComment,
useHttps,
toMobileFontSize
} 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: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(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);
});
});
});