-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
114 lines (104 loc) · 3.39 KB
/
test.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
'use strict';
const brandify = require('./src/index');
const helpers = require('./src/helpers');
const chai = require('chai');
const chaiFiles = require('chai-files');
const expect = chai.expect;
const file = chaiFiles.file;
chai.use(chaiFiles);
describe('helpers', () => {
describe('prepareSimpleIconsJson():', () => {
it('should generate dist/simple-icons.json', (done) => {
helpers.prepareSimpleIconsJson();
expect(file('./dist/simple-icons.json')).to.exist;
done();
});
});
describe('svgPatternReplacer(name, color):', () => {
it('should return empty string', (done) => {
let str = helpers.svgPatternReplacer();
expect(str).is.empty;
done();
});
it('should return empty color', (done) => {
let str = helpers.svgPatternReplacer('aaa');
expect(str).is.equal('class="svg-brandify brandify-icon-aaa" ');
done();
});
it('should return result string with lowercase and without spaces', (done) => {
let str = helpers.svgPatternReplacer('AAA BBB', '000');
expect(str).is.equal('class="svg-brandify brandify-icon-aaabbb" fill="#000" ');
done();
});
});
describe('insertTo(text, position, replacement):', () => {
it('should return empty string', (done) => {
let str = helpers.insertTo();
expect(str).is.empty;
done();
});
it('should return modified string', (done) => {
let str = helpers.insertTo('some text here', 4, 'body');
expect(str).is.equal('somebody text here');
done();
});
});
});
const htmlText = `
<a class="google icon">google</a>
`;
const htmlAndPlainText = `
<a class="google icon">google</a> google
`;
const nestedHtmlTags = `
<p class="linkedin class-icon">
<a class="google icon">
google
</a>
google
</p>
youtube
`;
const list = `<ul class="linkedin class-icon">
<li class="google icon">
google <a class="google icon"> google </a>
</li>
</ul>
`;
describe('brandify', () => {
it('should return empty string', (done) => {
let str = brandify();
expect(str).is.empty;
done();
});
it('should insert before brand names with icons', (done) => {
let str = brandify('I like github!', 'before');
expect(str).is.not.equal('I like github!');
expect(str).is.not.contain('I like github <svg');
expect(str).is.contain('</svg>\n GitHub');
expect(str).is.contain('class="svg-brandify brandify-icon-github"');
done();
});
it('should replace brand names with icons w/o params (by default)', (done) => {
let str = brandify('I like github!');
expect(str).is.not.equal('I like github!');
expect(str).is.not.contain('I like github');
expect(str).is.contain('class="svg-brandify brandify-icon-github"');
done();
});
it('should replace brand names with icons w/ "replace" param', (done) => {
let str = brandify('I like github!', 'replace');
expect(str).is.not.equal('I like github!');
expect(str).is.not.contain('I like github');
expect(str).is.contain('class="svg-brandify brandify-icon-github"');
done();
});
it('should insert after brand names with icons', (done) => {
let str = brandify('I like github!', 'after');
expect(str).is.not.equal('I like github!');
expect(str).is.not.contain('I like <svg');
expect(str).is.contain('I like GitHub <svg');
expect(str).is.contain('class="svg-brandify brandify-icon-github"');
done();
});
});