-
Notifications
You must be signed in to change notification settings - Fork 4
/
tools.test.js
81 lines (74 loc) · 2.93 KB
/
tools.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
const Tools = require('./tools.js');
describe('toID', () => {
it('should return IDs properly', () => expect(Tools.toID('PartMan!')).toBe('partman'));
});
describe('HSL', () => {
it('should return the right non-custom HSL', () => {
expect(Tools.HSL('PartBot')).toEqual({ source: 'partbot', hsl: [265, 50, 57.86516676840277] });
});
it('should return the right custom HSL', () => {
expect(Tools.HSL('PartMan').hsl).toEqual([21, 88, 49]);
});
it('should return the right original HSL', () => {
expect(Tools.HSL('PartMan', true).hsl).toEqual([162, 84, 33]);
});
it('should also import new custom colors', () => {
expect(Tools.HSL('style.css').hsl).toEqual([258, 62, 56.12230272578728]);
});
});
describe('uploadToPastie', function () {
// TODO: Just check the body instead; no need to actually upload
it.skip('should upload the given text', async () => {
const paste = await Tools.uploadToPastie('Test');
const res = await fetch(paste);
expect(await res.text()).toBe('Test');
});
});
describe('escapeHTML', () => {
it('should escape HTML correctly', () => {
expect(Tools.escapeHTML("You've <b>lost the game</b>!")).toBe('You've <b>lost the game</b>!');
});
});
describe('unescapeHTML', () => {
it('should unescape HTML correctly', () => {
expect(Tools.unescapeHTML('You've <b>lost the game</b>!')).toBe("You've <b>lost the game</b>!");
});
});
describe('formatText', () => {
it('should format bold correctly', () => {
expect(Tools.formatText('regular **bold**')).toBe('regular <b>bold</b>');
});
it('should format italics correctly', () => {
expect(Tools.formatText('regular __italic__')).toBe('regular <i>italic</i>');
});
it('should format striked correctly', () => {
expect(Tools.formatText('regular ~~striked~~')).toBe('regular <s>striked</s>');
});
it('should format superscript correctly', () => {
expect(Tools.formatText('regular ^^up^^')).toBe('regular <sup>up</sup>');
});
it('should format subscript correctly', () => {
expect(Tools.formatText('regular \\\\down\\\\')).toBe('regular <sub>down</sub>');
});
it('should format spoilers correctly (||spoiler||)', () => {
expect(Tools.formatText('regular ||text||')).toBe('regular <span class="spoiler">text</span>');
});
it('should format spoilers correctly (spoiler: )', () => {
expect(Tools.formatText('regular spoiler: text')).toBe('regular spoiler: <span class="spoiler">text</span>');
});
it('should format links correctly', () => {
expect(Tools.formatText('regular [[link]]')).toBe(
'regular <a href="//www.google.com/search?ie=UTF-8&btnI&q=link" target="_blank">link</a>'
);
});
it('should format named links correctly', () => {
expect(Tools.formatText('regular [[name<link>]]')).toBe(
'regular <a href="link" rel="noopener" target="_blank">name<small> <link></small></a>'
);
});
});
describe('update', () => {
it('should be able to update the datacenters', () => {
return Tools.update();
});
});