-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
166 lines (148 loc) Β· 4.53 KB
/
index.test.ts
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { expect } from 'chai';
import snap from 'snaptdout';
import style from './style'
import themes from './themes/themes';
const colorList = [
'red',
'green',
'yellow',
'blue',
'purple',
'cyan',
'pink',
'orange',
];
function createPhrases(styles: any, colors: string[] = colorList) {
const maxLabelLength = colors.reduce((acc, key) => Math.max(acc, key.length), 0);
return Object.keys(styles).reduce((acc: string[], key) => {
if (colors.includes(key)) {
const space = ' '.repeat((maxLabelLength - key.length) + 2);
acc.push(styles[key]`${key.toUpperCase() + space}ββββββββββ`);
}
return acc;
}, []);
}
describe('style', () => {
describe('built-in themes', () => {
it('should throw for non-existing theme', async () => {
try {
style({ theme: 'broccoli' });
} catch (error) {
expect(error.message).to.equal('no such theme broccoli')
}
});
it('should create default theme', async () => {
const d = style();
const data = createPhrases(d);
await snap(data.join('\n'), 'default');
});
it('should support all available themes', async () => {
for (const theme in themes) {
const colors = Object.keys(themes[theme as keyof typeof themes]);
const custom = style({ theme });
const data = createPhrases(custom, colors);
await snap(data.join('\n'), `${theme} theme`);
}
});
});
describe('built-in decorators', () => {
it('should support double decorators', async () => {
const s = style();
const data = s.pink`I am SO *!PINK!* `;
await snap(data, 'double decorators');
});
it('should support all major decorators', async () => {
const s = style();
const data = s.lush.pink`*BOLD* !UNDERLINE! @INVERT@ $STRIEKOUT$ %ITALIC%`;
await snap(data, 'major decorators');
});
});
describe('customs', () => {
it('should support custom color theme', async () => {
const custom = style({
theme: 'custom',
colors: {
custom: {
red: '#750404',
green: '#1b7504',
yellow: '#929605',
blue: '#041382',
purple: '#620182',
cyan: '#027678',
pink: '#a3039b',
orange: '#b37202',
},
},
});
const data = createPhrases(custom);
await snap(data.join('\n'), 'custom');
});
it('should support custom symbols map', async () => {
const custom = style({
decorators: {
bold: '-',
underline: '&',
dim: '%',
hidden: '?',
invert: '>',
blink: '<',
},
});
const data = [custom.green`this is -bold-`, custom.red`this is >inverted>`];
await snap(data.join('\n'), 'custom symbols');
});
it('should support partial custom symbols map', async () => {
const cc = style({
decorators: {
underline: '+'
},
});
const data = [cc.purple`this is +underline+`, cc.blue`this is *bold*`];
await snap(data.join('\n'), 'custom partial symbols');
});
it('should support partial custom color overrides', async () => {
const cc = style({
theme: 'custom',
colors: {
custom: {
green: 35
}
},
});
const data = [cc.green`I *should* be green`, cc.green`but I am so !purple!`];
await snap(data.join('\n'), 'custom partial color replace');
});
it('should support partial custom color overrides with themes', async () => {
const cc = style({
theme: 'custom',
colors: {
custom: {
blueish: '#89CFF0',
orangish: '#FFA500',
},
}
});
const data = [cc.blueish`I am blueish`, cc.custom.blueish`still blueish! asd`, cc.orangish`but I am so !orangish!`];
await snap(data.join('\n'), 'custom partial color theme');
});
it('should autocomplete colors', async () => {
const c = style({
theme: 'custom',
colors: {
custom: {
blueish: '#89CFF0',
orangish: '#FFA500',
},
}
});
expect(c).to.have.property('blueish');
expect(c.custom).to.have.property('blueish');
const cc = style({
theme: 'crayons',
});
expect(cc).to.have.property('saffron');
expect(cc.crayons).to.have.property('saffron');
// await snap(data.join('\n'), 'custom partial color theme');
});
});
});