-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.test.js
76 lines (62 loc) · 1.58 KB
/
main.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
import fetchColors from './index';
test('for hex EFDECD returns Almond', async () => {
const res = await fetchColors({
hex: 'EFDECD',
});
expect(res.length).toEqual(1);
expect(res[0].name).toEqual('Almond');
});
test('for name periwinkle returns Periwinkle', async () => {
const res = await fetchColors({
name: 'periwinkle',
});
expect(res.length).toEqual(1);
expect(res[0].hex).toEqual('C5D0E6');
});
test('for compName White Ice returns Sea Green', async () => {
const res = await fetchColors({
compName: 'white Ice',
});
expect(res.length).toEqual(1);
expect(res[0].hex).toEqual('9FE2BF');
});
test('for compHex 627BA5 returns Shadow', async () => {
const res = await fetchColors({
compHex: '627BA5',
});
expect(res.length).toEqual(1);
expect(res[0].hex).toEqual('8A795D');
});
test('for compName Black returns Black and Shadow', async () => {
const res = await fetchColors({
compName: 'Black',
});
expect(res.length).toEqual(2);
expect(res.find((c) => c.hex === '8A795D')).not.toBeUndefined();
expect(res.find((c) => c.hex === '000000')).not.toBeUndefined();
});
test('for compHex FFFFFF the expected 14 colors', async () => {
const res = await fetchColors({
compHex: 'FFFFFF',
});
const expected = [
'EFDECD',
'FDD9B5',
'FAE7B5',
'FFAACC',
'FFBCD9',
'FCB4D5',
'FDBCB4',
'FFCFAB',
'C5D0E6',
'FDDDE6',
'ECEABE',
'EBC7DF',
'DBD7D2',
'FFFFFF',
].sort();
const received = res.map((r) => r.hex).sort();
expected.forEach((e, i) => {
expect(received[i]).toBe(e);
});
});