forked from adobe/leonardo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchColors.test.mjs
104 lines (85 loc) · 3.35 KB
/
searchColors.test.mjs
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
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
/* global test, expect */
import { Color } from "../index";
import { searchColors, convertColorValue } from "../utils";
test('should return blue color of 3.12:1 against white', () => {
const color = new Color({
name: 'blue',
colorKeys: ['#0000ff'],
colorspace: 'LAB',
ratios: [3.12]
});
const bgRgbArray = [255, 255, 255];
const baseV = 100;
const contrastColors = searchColors(color, bgRgbArray, baseV, color.ratios).map((clr) => convertColorValue(clr, 'RGB'));
expect(contrastColors).toEqual(['rgb(163, 121, 255)']);
});
test('should return blue color of 3.12:1 against black', () => {
const color = new Color({
name: 'blue',
colorKeys: ['#0000ff'],
colorspace: 'LAB',
ratios: [3.12]
});
const bgRgbArray = [0, 0, 0];
const baseV = 0;
const contrastColors = searchColors(color, bgRgbArray, baseV, color.ratios).map((clr) => convertColorValue(clr, 'RGB'));
expect(contrastColors).toEqual(['rgb(80, 43, 255)']); // 3.13
});
test('should return blue colors of 3:1 and 4.5:1 against white', () => {
const color = new Color({
name: 'blue',
colorKeys: ['#0000ff'],
colorspace: 'LAB',
ratios: [3, 4.5]
});
const bgRgbArray = [255, 255, 255];
const baseV = 100;
const contrastColors = searchColors(color, bgRgbArray, baseV, color.ratios).map((clr) => convertColorValue(clr, 'RGB'));
expect(contrastColors).toEqual(['rgb(167, 124, 255)', 'rgb(129, 84, 255)']); // 3.01 & 4.52
});
test('should return blue colors of 3:1 and 4.5:1 against black', () => {
const color = new Color({
name: 'blue',
colorKeys: ['#0000ff'],
colorspace: 'LAB',
ratios: [3, 4.5]
});
const bgRgbArray = [0, 0, 0];
const baseV = 0;
const contrastColors = searchColors(color, bgRgbArray, baseV, color.ratios).map((clr) => convertColorValue(clr, 'RGB'));
expect(contrastColors).toEqual(['rgb(73, 38, 255)', 'rgb(126, 81, 255)']); // 3 & 4.51
});
test('should return blue color of -1.3 against light gray', () => {
const color = new Color({
name: 'blue',
colorKeys: ['#0000ff'],
colorspace: 'LAB',
ratios: [-1.3]
});
const bgRgbArray = [166, 166, 166];
const baseV = 65;
const contrastColors = searchColors(color, bgRgbArray, baseV, color.ratios).map((clr) => convertColorValue(clr, 'RGB'));
expect(contrastColors).toEqual(['rgb(207, 176, 255)']); // 1.31
});
test('should return blue color of -2 against dark gray', () => {
const color = new Color({
name: 'blue',
colorKeys: ['#0000ff'],
colorspace: 'LAB',
ratios: [-2]
});
const bgRgbArray = [99, 99, 99];
const baseV = 40;
const contrastColors = searchColors(color, bgRgbArray, baseV, color.ratios).map((clr) => convertColorValue(clr, 'RGB'));
expect(contrastColors).toEqual(['rgb(167, 125, 255)']); // 2.01
});