@instructure/ui-color-picker 11.7.2 → 11.7.3-snapshot-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +24 -24
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/ColorContrast/v2/ColorContrast.test.js +0 -229
- package/es/ColorPicker/v2/ColorPicker.test.js +0 -499
- package/lib/ColorContrast/v2/ColorContrast.test.js +0 -231
- package/lib/ColorPicker/v2/ColorPicker.test.js +0 -501
- package/src/ColorContrast/v2/ColorContrast.test.tsx +0 -263
- package/src/ColorPicker/v2/ColorPicker.test.tsx +0 -618
- package/types/ColorContrast/v2/ColorContrast.test.d.ts +0 -2
- package/types/ColorContrast/v2/ColorContrast.test.d.ts.map +0 -1
- package/types/ColorPicker/v2/ColorPicker.test.d.ts +0 -2
- package/types/ColorPicker/v2/ColorPicker.test.d.ts.map +0 -1
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { render, screen } from '@testing-library/react';
|
|
26
|
-
import { vi } from 'vitest';
|
|
27
|
-
import '@testing-library/jest-dom';
|
|
28
|
-
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
29
|
-
import { contrast } from '@instructure/ui-color-utils';
|
|
30
|
-
import { ColorContrast } from "./index.js";
|
|
31
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
32
|
-
const testColors = {
|
|
33
|
-
firstColor: '#FF0000',
|
|
34
|
-
secondColor: '#FFFF00'
|
|
35
|
-
};
|
|
36
|
-
const testLabels = {
|
|
37
|
-
label: 'Color Contrast Ratio',
|
|
38
|
-
successLabel: 'PASS',
|
|
39
|
-
failureLabel: 'FAIL',
|
|
40
|
-
normalTextLabel: 'Normal text',
|
|
41
|
-
largeTextLabel: 'Large text',
|
|
42
|
-
graphicsTextLabel: 'Graphics text',
|
|
43
|
-
firstColorLabel: 'Background',
|
|
44
|
-
secondColorLabel: 'Foreground'
|
|
45
|
-
};
|
|
46
|
-
describe('<ColorContrast />', () => {
|
|
47
|
-
describe('elementRef prop', () => {
|
|
48
|
-
it('should provide ref', async () => {
|
|
49
|
-
const elementRef = vi.fn();
|
|
50
|
-
const _render = render(_jsx(ColorContrast, {
|
|
51
|
-
...testColors,
|
|
52
|
-
...testLabels,
|
|
53
|
-
elementRef: elementRef
|
|
54
|
-
})),
|
|
55
|
-
container = _render.container;
|
|
56
|
-
expect(elementRef).toHaveBeenCalledWith(container.firstChild);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe('labels are displayed:', () => {
|
|
60
|
-
Object.entries(testLabels).forEach(([label, text]) => {
|
|
61
|
-
it(label, async () => {
|
|
62
|
-
const _render2 = render(_jsx(ColorContrast, {
|
|
63
|
-
...testColors,
|
|
64
|
-
...testLabels
|
|
65
|
-
})),
|
|
66
|
-
container = _render2.container;
|
|
67
|
-
expect(container).toHaveTextContent(text);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
describe('labelLevel prop', () => {
|
|
72
|
-
it('should render label as div when labelLevel is not provided', async () => {
|
|
73
|
-
render(_jsx(ColorContrast, {
|
|
74
|
-
...testColors,
|
|
75
|
-
...testLabels
|
|
76
|
-
}));
|
|
77
|
-
const heading = screen.queryByRole('heading', {
|
|
78
|
-
name: testLabels.label
|
|
79
|
-
});
|
|
80
|
-
expect(heading).not.toBeInTheDocument();
|
|
81
|
-
const labelText = screen.getByText(testLabels.label);
|
|
82
|
-
expect(labelText).toBeInTheDocument();
|
|
83
|
-
expect(labelText.tagName.toLowerCase()).toBe('div');
|
|
84
|
-
});
|
|
85
|
-
it('should render label as Heading when labelLevel is provided', async () => {
|
|
86
|
-
render(_jsx(ColorContrast, {
|
|
87
|
-
...testColors,
|
|
88
|
-
...testLabels,
|
|
89
|
-
labelLevel: "h2"
|
|
90
|
-
}));
|
|
91
|
-
const heading = screen.getByRole('heading', {
|
|
92
|
-
name: testLabels.label,
|
|
93
|
-
level: 2
|
|
94
|
-
});
|
|
95
|
-
expect(heading).toBeInTheDocument();
|
|
96
|
-
});
|
|
97
|
-
it('should render correct heading level', async () => {
|
|
98
|
-
const _render3 = render(_jsx(ColorContrast, {
|
|
99
|
-
...testColors,
|
|
100
|
-
...testLabels,
|
|
101
|
-
labelLevel: "h3"
|
|
102
|
-
})),
|
|
103
|
-
rerender = _render3.rerender;
|
|
104
|
-
let heading = screen.getByRole('heading', {
|
|
105
|
-
name: testLabels.label,
|
|
106
|
-
level: 3
|
|
107
|
-
});
|
|
108
|
-
expect(heading).toBeInTheDocument();
|
|
109
|
-
rerender(_jsx(ColorContrast, {
|
|
110
|
-
...testColors,
|
|
111
|
-
...testLabels,
|
|
112
|
-
labelLevel: "h1"
|
|
113
|
-
}));
|
|
114
|
-
heading = screen.getByRole('heading', {
|
|
115
|
-
name: testLabels.label,
|
|
116
|
-
level: 1
|
|
117
|
-
});
|
|
118
|
-
expect(heading).toBeInTheDocument();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
describe('should calculate contrast correctly', () => {
|
|
122
|
-
it('on opaque colors', async () => {
|
|
123
|
-
const color1 = '#fff';
|
|
124
|
-
const color2 = '#088';
|
|
125
|
-
const _render4 = render(_jsx(ColorContrast, {
|
|
126
|
-
...testLabels,
|
|
127
|
-
firstColor: color1,
|
|
128
|
-
secondColor: color2
|
|
129
|
-
})),
|
|
130
|
-
container = _render4.container;
|
|
131
|
-
const contrastResult = contrast(color1, color2, 2);
|
|
132
|
-
expect(container).toHaveTextContent(contrastResult + ':1');
|
|
133
|
-
});
|
|
134
|
-
it('on transparent colors', async () => {
|
|
135
|
-
const color1 = '#fff';
|
|
136
|
-
const color2 = '#00888880';
|
|
137
|
-
const _render5 = render(_jsx(ColorContrast, {
|
|
138
|
-
...testLabels,
|
|
139
|
-
firstColor: color1,
|
|
140
|
-
secondColor: color2
|
|
141
|
-
})),
|
|
142
|
-
container = _render5.container;
|
|
143
|
-
|
|
144
|
-
// this is the result of a complicated "blended color" calculation
|
|
145
|
-
// in the component, not simple `contrast()` check
|
|
146
|
-
expect(container).toHaveTextContent('2:1');
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe('withoutColorPreview prop', () => {
|
|
150
|
-
it('should be false by default, should display preview', async () => {
|
|
151
|
-
const _render6 = render(_jsx(ColorContrast, {
|
|
152
|
-
...testColors,
|
|
153
|
-
...testLabels
|
|
154
|
-
})),
|
|
155
|
-
container = _render6.container;
|
|
156
|
-
const preview = container.querySelector("[class$='-colorContrast__colorPreview']");
|
|
157
|
-
expect(preview).toBeInTheDocument();
|
|
158
|
-
});
|
|
159
|
-
it('should hide preview', async () => {
|
|
160
|
-
const _render7 = render(_jsx(ColorContrast, {
|
|
161
|
-
...testColors,
|
|
162
|
-
...testLabels,
|
|
163
|
-
withoutColorPreview: true
|
|
164
|
-
})),
|
|
165
|
-
container = _render7.container;
|
|
166
|
-
const preview = container.querySelector("[class$='-colorContrast__colorPreview']");
|
|
167
|
-
expect(preview).not.toBeInTheDocument();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
describe('contrast check', () => {
|
|
171
|
-
const checkContrastPills = (title, firstColor, secondColor, expectedResult) => {
|
|
172
|
-
describe(title, () => {
|
|
173
|
-
it(`normal text should ${expectedResult.normal.toLowerCase()}`, async () => {
|
|
174
|
-
const _render8 = render(_jsx(ColorContrast, {
|
|
175
|
-
...testLabels,
|
|
176
|
-
firstColor: firstColor,
|
|
177
|
-
secondColor: secondColor
|
|
178
|
-
})),
|
|
179
|
-
container = _render8.container;
|
|
180
|
-
expect(container).toHaveTextContent(expectedResult.normal);
|
|
181
|
-
});
|
|
182
|
-
it(`large text should ${expectedResult.large.toLowerCase()}`, async () => {
|
|
183
|
-
const _render9 = render(_jsx(ColorContrast, {
|
|
184
|
-
...testLabels,
|
|
185
|
-
firstColor: firstColor,
|
|
186
|
-
secondColor: secondColor
|
|
187
|
-
})),
|
|
188
|
-
container = _render9.container;
|
|
189
|
-
expect(container).toHaveTextContent(expectedResult.large);
|
|
190
|
-
});
|
|
191
|
-
it(`graphics should ${expectedResult.graphics.toLowerCase()}`, async () => {
|
|
192
|
-
const _render0 = render(_jsx(ColorContrast, {
|
|
193
|
-
...testLabels,
|
|
194
|
-
firstColor: firstColor,
|
|
195
|
-
secondColor: secondColor
|
|
196
|
-
})),
|
|
197
|
-
container = _render0.container;
|
|
198
|
-
expect(container).toHaveTextContent(expectedResult.graphics);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
checkContrastPills('on x < 3 contrast', '#fff', '#aaa', {
|
|
203
|
-
normal: 'FAIL',
|
|
204
|
-
large: 'FAIL',
|
|
205
|
-
graphics: 'FAIL'
|
|
206
|
-
});
|
|
207
|
-
checkContrastPills('on small 3 < x < 4.5 contrast', '#fff', '#0c89bf', {
|
|
208
|
-
normal: 'FAIL',
|
|
209
|
-
large: 'PASS',
|
|
210
|
-
graphics: 'PASS'
|
|
211
|
-
});
|
|
212
|
-
checkContrastPills('on small x > 4.5 contrast', '#fff', '#333', {
|
|
213
|
-
normal: 'PASS',
|
|
214
|
-
large: 'PASS',
|
|
215
|
-
graphics: 'PASS'
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
describe('should be accessible', () => {
|
|
219
|
-
it('a11y', async () => {
|
|
220
|
-
const _render1 = render(_jsx(ColorContrast, {
|
|
221
|
-
...testColors,
|
|
222
|
-
...testLabels
|
|
223
|
-
})),
|
|
224
|
-
container = _render1.container;
|
|
225
|
-
const axeCheck = await runAxeCheck(container);
|
|
226
|
-
expect(axeCheck).toBe(true);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
});
|