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