-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.test.ts
353 lines (295 loc) Β· 13.7 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import chai from 'chai';
const expect = chai.expect;
import Chartscii from './chartscii';
import snap from 'snaptdout';
import { InputData } from './dist/types/types';
const colors = [
'red',
'green',
'yellow',
'blue',
'purple',
'pink',
'cyan',
'orange',
'purple',
'marine',
];
const labels = ['c', 'h', 'a', 'r', 't', 's', 'c', 'i', 'i', 'π₯'];
function generateChartData() {
const data: InputData[] = [];
for (let i = 0; i < colors.length; i++) {
const color = colors[i];
data.push({ value: (i + 1) * 10, label: labels[i], color });
}
return data;
}
describe('chartscii tests', () => {
let data, chart: any;
beforeEach(() => {
data = [...Array(10).keys()];
chart = new Chartscii(data);
});
it('should initialize chart array with all values', () => {
const result = [...chart.chart.values()];
expect(result.length).to.equal(10);
});
it('should support 0 values', () => {
const result = [...chart.chart.values()][0]
expect(result).to.deep.equal({ value: 0, color: undefined, label: '0', scaled: 0, percentage: 0 });
});
it('should support { value }', () => {
const data = [...Array(10).keys()].map((key) => {
return { value: key };
});
chart = new Chartscii(data);
const result = [...chart.chart.values()][0]
expect(result.value).to.equal(0);
});
it('should support { value, label }', () => {
let counter = 0;
const data = [...Array(10).keys()].map((key) => {
return { value: key, label: labels[counter++] };
});
chart = new Chartscii(data);
const result = [...chart.chart.values()][0]
expect(result.label).to.equal('c');
});
it('should support percentage', () => {
const data = generateChartData();
chart = new Chartscii(data, { percentage: true });
const result = [...chart.chart.values()][0];
expect(result.percentage).to.equal(1.8181818181818181);
});
});
describe('examples', () => {
it('should match example', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { color: 'pink', colorLabels: true });
await snap(chart.create(), 'chart');
});
it('should support percentage', async () => {
const data = generateChartData();
const chart = new Chartscii(data, {
color: 'cyan',
colorLabels: true,
percentage: true,
});
await snap(chart.create(), 'percentage');
});
it('should support labeless chart', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { labels: false, padding: 1 });
await snap(chart.create(), 'labeless chart');
});
it('should support labeless colorful chart', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { labels: false });
await snap(chart.create(), 'labeless color chart');
});
it('should support fill', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { fill: 'β', colorLabels: true });
await snap(chart.create(), 'fill');
});
it('should support emoji character', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { char: 'π§¨' });
await snap(chart.create(), 'emojis');
});
it('should support padding', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { padding: 1 });
await snap(chart.create(), 'padding');
});
it('should support barSize', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { barSize: 2 });
await snap(chart.create(), 'barSize');
});
it('should scale according to height', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { height: 100 });
await snap(chart.create(), 'height');
});
it('should support pastel theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'pastel', colorLabels: true });
await snap(chart.create(), 'pastel theme');
});
it('should support lush theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'lush', colorLabels: true });
await snap(chart.create(), 'lush theme');
});
it('should support standard theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'standard', colorLabels: true });
await snap(chart.create(), 'standard theme');
});
it('should support beach theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'beach', colorLabels: true });
await snap(chart.create(), 'beach theme');
});
it('should support default theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { colorLabels: true });
await snap(chart.create(), 'default theme');
});
it('should support styl3 label formatting', async () => {
const data: InputData[] = [];
for (let i = 0; i < 10; i++) {
data.push({ value: i + 1, label: `~dim~ ${i}`, color: colors[i] });
}
const chart = new Chartscii(data, { barSize: 2, width: 100, colorLabels: true, percentage: true });
await snap(chart.create(), 'styl3 formatting');
});
it('should support value labels', async () => {
const data: InputData[] = [];
for (let i = 0; i < colors.length; i++) {
const color = colors[i];
data.push({ value: i + 1, color, label: `@invert ${i}@` });
}
const chart = new Chartscii(data, { barSize: 4, fill: 'β', colorLabels: true, valueLabels: true });
await snap(chart.create(), 'value labels');
});
it('should support value labels no fill', async () => {
const data: InputData[] = [];
for (let i = 0; i < colors.length; i++) {
const color = colors[i];
data.push({ value: i + 1, color, label: `*bold ${i}*` });
}
const chart = new Chartscii(data, { barSize: 4, colorLabels: true, valueLabels: true });
await snap(chart.create(), 'value labels no fill');
});
});
describe('vertical', () => {
it('should support vertical orientation', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { width: 100, color: 'pink', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'vertical');
});
it('should support barSize', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { width: 100, barSize: 5, color: 'green', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'vertical barSize');
});
it('should support color per bar and label', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { width: 100, barSize: 5, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'vertical colors');
});
it('should support labeless vertical chart', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { labels: false, orientation: 'vertical', });
await snap(chart.create(), 'labeless vertical chart');
});
it('should support labeless colorful chart', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { labels: false, orientation: 'vertical', });
await snap(chart.create(), 'labeless color vertical chart');
});
it('should support vertical fill', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { fill: 'β', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'vertical fill');
});
it('should support padding', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { fill: 'β', padding: 4, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'vertical padding');
});
it('should support vertical emoji character', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { char: 'π', barSize: 2, orientation: 'vertical', });
await snap(chart.create(), 'vertical emojis');
});
it('should support pastel theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'pastel', barSize: 2, width: 100, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'pastel theme vertical');
});
it('should support lush theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'lush', barSize: 2, width: 100, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'lush theme vertical');
});
it('should support standard theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'standard', barSize: 2, width: 100, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'standard theme vertical');
});
it('should support beach theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { theme: 'beach', barSize: 2, width: 100, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'beach theme vertical');
});
it('should support default theme', async () => {
const data = generateChartData();
const chart = new Chartscii(data, { barSize: 2, width: 100, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'default theme vertical');
});
it('should support styl3 label formatting', async () => {
const data: InputData[] = [];
for (let i = 0; i < colors.length; i++) {
const color = colors[i];
data.push({ value: i + 1, color, label: `@invert ${i}@` });
}
const chart = new Chartscii(data, { fill: 'β', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'styl3 formatting vertical');
});
it('should support value labels', async () => {
const data: InputData[] = [];
for (let i = 0; i < colors.length; i++) {
const color = colors[i];
data.push({ value: i + 1, color, label: `@invert ${i}@` });
}
const chart = new Chartscii(data, { barSize: 4, fill: 'β', colorLabels: true, orientation: 'vertical', valueLabels: true });
await snap(chart.create(), 'value labels vertical');
});
it('should support value labels no fill', async () => {
const data: InputData[] = [];
for (let i = 0; i < colors.length; i++) {
const color = colors[i];
data.push({ value: i + 1, color, label: `*bold ${i}*` });
}
const chart = new Chartscii(data, { barSize: 4, colorLabels: true, orientation: 'vertical', valueLabels: true });
await snap(chart.create(), 'value labels vertical no fill');
});
});
describe('scale', () => {
const data = generateChartData();
it('should support char of different widths', async () => {
const chart = new Chartscii(data, { width: 100, color: 'pink', char: '++', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'scale char');
});
it('should support char and fill of different widths', async () => {
const chart = new Chartscii(data, { width: 100, color: 'pink', char: 'π₯', fill: 'π§', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'scale char widths');
});
it('should support char and fill of different widths non equally', async () => {
const chart = new Chartscii(data, { width: 100, color: 'pink', char: 'π₯', fill: '+', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'scale char widths non equal');
});
it('should support char and fill of different widths non equally reversed', async () => {
const chart = new Chartscii(data, { color: 'blue', char: '+', fill: 'π₯', colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'scale char widths non equal reversed');
});
it('should support padding and width', async () => {
const chart = new Chartscii(data, { width: 150, color: 'cyan', padding: 2, colorLabels: true, orientation: 'vertical', });
await snap(chart.create(), 'scale char padding');
});
it('should support padding and barSize', async () => {
const chart = new Chartscii(data, { width: 100, color: 'pink', padding: 2, barSize: 4, colorLabels: true, orientation: 'vertical', labels: false });
await snap(chart.create(), 'scale char barSize');
});
it('should support percentage', async () => {
const chart = new Chartscii(data, { width: 150, theme: 'pastel', color: 'blue', padding: 2, colorLabels: true, orientation: 'vertical', percentage: true });
await snap(chart.create(), 'scale label percentage');
});
it('should support auto label placement', async () => {
const chart = new Chartscii(data, { width: 80, theme: 'pastel', color: 'red', padding: 2, colorLabels: true, orientation: 'vertical' });
await snap(chart.create(), 'scale label placement');
});
});