-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.js
123 lines (110 loc) · 2.38 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
115
116
117
118
119
120
121
122
123
import test from 'ava';
import xbar, {_create, separator} from './index.js';
test('main', t => {
const actual = _create([
{
text: '❤',
color: 'red',
dropdown: false,
},
separator,
{
text: 'Unicorns',
color: '#ff79d7',
href: 'https://www.youtube.com/watch?v=9auOCbH5Ns4',
submenu: [
{
text: '1st Level Submenu - A',
submenu: [
{
text: '2nd level Submenu',
},
],
},
{
text: '1st Level Submenu - B',
},
separator,
{
text: '1st Level Submenu - C',
},
],
},
separator,
'Ponies',
]);
const expected = `
❤|color="red" dropdown="false"
---
Unicorns|color="#ff79d7" href="https://www.youtube.com/watch?v=9auOCbH5Ns4"
--1st Level Submenu - A|
----2nd level Submenu|
--1st Level Submenu - B|
-----
--1st Level Submenu - C|
---
Ponies|
`.trim();
t.is(actual, expected);
});
test('`text` property validation', t => {
const errorMessage = 'The `text` property is required and should be a string';
t.throws(() => {
xbar([{dropdown: false}]);
}, {message: errorMessage});
t.throws(() => {
xbar([{text: 1}]);
}, {message: errorMessage});
});
test('correctly encodes special characters in the `href` option', t => {
const actual = _create([
{
text: 'Single Quote',
href: 'https://www.youtube.com/watch?v=\'9auOCbH5Ns4',
},
{
text: 'Double Quotes',
href: 'https://www.youtube.com/watch?v="9auOCbH5Ns4"',
},
{
text: 'Ampercent',
href: 'https://www.youtube.com/watch?v=&9auOCbH5Ns4',
},
]);
const expected = `
Single Quote|href="https://www.youtube.com/watch?v=%279auOCbH5Ns4"
Double Quotes|href="https://www.youtube.com/watch?v=%229auOCbH5Ns4%22"
Ampercent|href="https://www.youtube.com/watch?v=%269auOCbH5Ns4"
`.trim();
t.is(actual, expected);
});
test('item options overrides top-level options', t => {
const actual = _create([
{
text: 'Default font',
},
{
text: 'Overriden font',
font: 'Comic Sans MS',
},
], {
font: 'Arial',
});
const expected = `
Default font|font="Arial"
Overriden font|font="Comic Sans MS"
`.trim();
t.is(actual, expected);
});
test('`text` property on top-level options throws TypeError', t => {
const errorMessage = 'The `text` option is not supported as a top-level option. Use it on an item instead.';
t.throws(() => {
xbar([
{
text: '❤',
},
], {
text: 'Override',
});
}, {message: errorMessage});
});