@instructure/emotion 10.19.2-snapshot-2 → 10.19.2-snapshot-4

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +84 -0
  3. package/es/__old-tests__/getComponentThemeOverride.test.js +128 -0
  4. package/es/__old-tests__/useStyle.test.js +226 -0
  5. package/es/__old-tests__/useTheme.test.js +484 -0
  6. package/es/__old-tests__/withStyle.test.js +327 -0
  7. package/es/styleUtils/__old-tests__/getShorthandPropValue.test.js +85 -0
  8. package/es/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.js → styleUtils/__old-tests__/makeThemeVars.test.js} +19 -16
  9. package/es/styleUtils/__old-tests__/mirrorShorthand.test.js +66 -0
  10. package/lib/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +86 -0
  11. package/lib/__old-tests__/getComponentThemeOverride.test.js +131 -0
  12. package/lib/__old-tests__/useStyle.test.js +228 -0
  13. package/lib/__old-tests__/useTheme.test.js +488 -0
  14. package/lib/__old-tests__/withStyle.test.js +329 -0
  15. package/lib/styleUtils/__old-tests__/getShorthandPropValue.test.js +87 -0
  16. package/lib/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.js → styleUtils/__old-tests__/makeThemeVars.test.js} +19 -16
  17. package/lib/styleUtils/__old-tests__/mirrorShorthand.test.js +68 -0
  18. package/package.json +11 -11
  19. package/src/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.tsx +82 -0
  20. package/src/__old-tests__/getComponentThemeOverride.test.ts +182 -0
  21. package/src/__old-tests__/useStyle.test.tsx +272 -0
  22. package/src/__old-tests__/useTheme.test.tsx +510 -0
  23. package/src/__old-tests__/withStyle.test.tsx +389 -0
  24. package/src/styleUtils/__old-tests__/getShorthandPropValue.test.ts +96 -0
  25. package/src/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.tsx → styleUtils/__old-tests__/makeThemeVars.test.ts} +19 -14
  26. package/src/styleUtils/__old-tests__/mirrorShorthand.test.ts +77 -0
  27. package/tsconfig.build.tsbuildinfo +1 -1
  28. package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts +2 -0
  29. package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts.map +1 -0
  30. package/types/__old-tests__/getComponentThemeOverride.test.d.ts +2 -0
  31. package/types/__old-tests__/getComponentThemeOverride.test.d.ts.map +1 -0
  32. package/types/__old-tests__/useStyle.test.d.ts +2 -0
  33. package/types/__old-tests__/useStyle.test.d.ts.map +1 -0
  34. package/types/__old-tests__/useTheme.test.d.ts +2 -0
  35. package/types/__old-tests__/useTheme.test.d.ts.map +1 -0
  36. package/types/__old-tests__/withStyle.test.d.ts +2 -0
  37. package/types/__old-tests__/withStyle.test.d.ts.map +1 -0
  38. package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts +2 -0
  39. package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts.map +1 -0
  40. package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts +2 -0
  41. package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts.map +1 -0
  42. package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts +2 -0
  43. package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts.map +1 -0
  44. package/types/InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.d.ts +0 -2
  45. package/types/InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.d.ts.map +0 -1
@@ -0,0 +1,484 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { canvas, canvasHighContrast, canvasThemeLocal } from '@instructure/ui-themes';
27
+ import { expect, mount, spy } from '@instructure/ui-test-utils';
28
+ import { ThemeRegistry } from '@instructure/theme-registry';
29
+ import { useTheme } from '../useTheme';
30
+ import { InstUISettingsProvider } from '../InstUISettingsProvider';
31
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
32
+ const defaultRegistry = ThemeRegistry.getRegistry();
33
+ const ExampleComponent = props => {
34
+ const theme = useTheme();
35
+ props.callback(theme);
36
+ return null;
37
+ };
38
+ describe('useTheme hook', () => {
39
+ beforeEach(() => {
40
+ ThemeRegistry.clearRegistry();
41
+ });
42
+ afterEach(() => {
43
+ //this is needed to not mess up the global Theme Registry
44
+ ThemeRegistry.setRegistry(defaultRegistry);
45
+ });
46
+ describe('with using InstUISettingsProvider', () => {
47
+ it('should use default canvas theme when no "theme" is provided', async () => {
48
+ const callback = spy();
49
+ await mount(_jsx(InstUISettingsProvider, {
50
+ children: _jsx(ExampleComponent, {
51
+ callback: callback
52
+ })
53
+ }));
54
+ expect(callback).to.have.been.calledWith(canvas);
55
+ });
56
+ it('should use global theme when no "theme" is provided', async () => {
57
+ const callback = spy();
58
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
59
+ theme.use();
60
+ await mount(_jsx(InstUISettingsProvider, {
61
+ children: _jsx(ExampleComponent, {
62
+ callback: callback
63
+ })
64
+ }));
65
+ expect(callback).to.have.been.calledWith(theme);
66
+ });
67
+ it('should default to canvas theme when no global theme is available and no theme is provided', async () => {
68
+ const callback = spy();
69
+ await mount(_jsx(InstUISettingsProvider, {
70
+ children: _jsx(ExampleComponent, {
71
+ callback: callback
72
+ })
73
+ }));
74
+ expect(callback).to.have.been.calledWith(canvas);
75
+ });
76
+ it('should use provided theme when theme is provided', async () => {
77
+ const callback = spy();
78
+ const theme = ThemeRegistry.registerTheme(canvas);
79
+ theme.use();
80
+ await mount(_jsx(InstUISettingsProvider, {
81
+ theme: canvasHighContrast,
82
+ children: _jsx(ExampleComponent, {
83
+ callback: callback
84
+ })
85
+ }));
86
+ expect(callback).to.have.been.calledWith(canvasHighContrast);
87
+ });
88
+ it('should override the default theme when no other theme is available', async () => {
89
+ const callback = spy();
90
+ await mount(_jsx(InstUISettingsProvider, {
91
+ theme: {
92
+ colors: {
93
+ primitives: {
94
+ white: 'red'
95
+ }
96
+ }
97
+ },
98
+ children: _jsx(ExampleComponent, {
99
+ callback: callback
100
+ })
101
+ }));
102
+ expect(callback).to.have.been.calledWithMatch({
103
+ ...canvas,
104
+ colors: {
105
+ primitives: {
106
+ white: 'red'
107
+ }
108
+ }
109
+ });
110
+ });
111
+ it('should override the global theme if that is the only theme available', async () => {
112
+ const callback = spy();
113
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
114
+ theme.use();
115
+ await mount(_jsx(InstUISettingsProvider, {
116
+ theme: {
117
+ colors: {
118
+ primitives: {
119
+ white: 'red'
120
+ }
121
+ }
122
+ },
123
+ children: _jsx(ExampleComponent, {
124
+ callback: callback
125
+ })
126
+ }));
127
+ expect(callback).to.have.been.calledWithMatch({
128
+ ...theme,
129
+ colors: {
130
+ primitives: {
131
+ white: 'red'
132
+ }
133
+ }
134
+ });
135
+ });
136
+ it('should override the global theme with the "themeOverrides" option if that is the only theme available', async () => {
137
+ const callback = spy();
138
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
139
+ theme.use();
140
+ await mount(_jsx(InstUISettingsProvider, {
141
+ theme: {
142
+ themeOverrides: {
143
+ colors: {
144
+ primitives: {
145
+ white: 'red'
146
+ }
147
+ }
148
+ }
149
+ },
150
+ children: _jsx(ExampleComponent, {
151
+ callback: callback
152
+ })
153
+ }));
154
+ expect(callback).to.have.been.calledWithMatch({
155
+ ...theme,
156
+ colors: {
157
+ primitives: {
158
+ white: 'red'
159
+ }
160
+ }
161
+ });
162
+ });
163
+ it('should override the theme from context when provided', async () => {
164
+ const callback = spy();
165
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
166
+ theme.use();
167
+ await mount(_jsx(InstUISettingsProvider, {
168
+ theme: canvasHighContrast,
169
+ children: _jsx(InstUISettingsProvider, {
170
+ theme: {
171
+ themeOverrides: {
172
+ colors: {
173
+ primitives: {
174
+ white: 'red'
175
+ }
176
+ }
177
+ }
178
+ },
179
+ children: _jsx(ExampleComponent, {
180
+ callback: callback
181
+ })
182
+ })
183
+ }));
184
+ expect(callback).to.have.been.calledWithMatch({
185
+ ...canvasHighContrast,
186
+ colors: {
187
+ primitives: {
188
+ white: 'red'
189
+ }
190
+ }
191
+ });
192
+ });
193
+ it('should use local themes correctly', async () => {
194
+ const callback = spy();
195
+ const theme = ThemeRegistry.registerTheme(canvas);
196
+ theme.use();
197
+ await mount(_jsx(InstUISettingsProvider, {
198
+ theme: canvasThemeLocal,
199
+ children: _jsx(InstUISettingsProvider, {
200
+ theme: {
201
+ themeOverrides: {
202
+ colors: {
203
+ primitives: {
204
+ white: 'red'
205
+ }
206
+ }
207
+ }
208
+ },
209
+ children: _jsx(ExampleComponent, {
210
+ callback: callback
211
+ })
212
+ })
213
+ }));
214
+ expect(callback).to.have.been.calledWithMatch({
215
+ ...canvasThemeLocal,
216
+ colors: {
217
+ primitives: {
218
+ white: 'red'
219
+ }
220
+ }
221
+ });
222
+ });
223
+ });
224
+ describe('without using InstUISettingsProvider', () => {
225
+ it('should use theme from global ThemeRegistry', async () => {
226
+ const callback = spy();
227
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
228
+ theme.use();
229
+ await mount(_jsx(ExampleComponent, {
230
+ callback: callback
231
+ }));
232
+ expect(callback).to.have.been.calledWith(theme);
233
+ });
234
+ it('should use default "canvas" theme when no theme is used from ThemeRegistry', async () => {
235
+ const callback = spy();
236
+ await mount(_jsx(ExampleComponent, {
237
+ callback: callback
238
+ }));
239
+ expect(callback).to.have.been.calledWith(canvas);
240
+ });
241
+ });
242
+ describe('with InstUISettingsProvider and global theme', () => {
243
+ it('overrides should work correctly', async () => {
244
+ const _Array$fill$map = Array(6).fill(0).map(() => spy()),
245
+ _Array$fill$map2 = _slicedToArray(_Array$fill$map, 6),
246
+ cb1 = _Array$fill$map2[0],
247
+ cb2 = _Array$fill$map2[1],
248
+ cb3 = _Array$fill$map2[2],
249
+ cb4 = _Array$fill$map2[3],
250
+ cb5 = _Array$fill$map2[4],
251
+ cb6 = _Array$fill$map2[5];
252
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
253
+ theme.use({
254
+ overrides: {
255
+ colors: {
256
+ primitives: {
257
+ red12: 'red',
258
+ green12: 'yellow',
259
+ blue12: 'magenta'
260
+ }
261
+ }
262
+ }
263
+ });
264
+ await mount(_jsxs(_Fragment, {
265
+ children: [_jsx(ExampleComponent, {
266
+ callback: cb1
267
+ }), _jsxs(InstUISettingsProvider, {
268
+ theme: canvasHighContrast,
269
+ children: [_jsx(ExampleComponent, {
270
+ callback: cb2
271
+ }), _jsxs(InstUISettingsProvider, {
272
+ theme: canvas,
273
+ children: [_jsx(ExampleComponent, {
274
+ callback: cb3
275
+ }), _jsx(InstUISettingsProvider, {
276
+ theme: {
277
+ colors: {
278
+ primitives: {
279
+ red12: 'orange'
280
+ }
281
+ },
282
+ themeOverrides: {
283
+ colors: {
284
+ primitives: {
285
+ green12: 'olive'
286
+ }
287
+ }
288
+ }
289
+ },
290
+ children: _jsx(ExampleComponent, {
291
+ callback: cb4
292
+ })
293
+ })]
294
+ })]
295
+ }), _jsxs(InstUISettingsProvider, {
296
+ children: [_jsx(ExampleComponent, {
297
+ callback: cb5
298
+ }), _jsx(InstUISettingsProvider, {
299
+ theme: {
300
+ colors: {
301
+ primitives: {
302
+ red12: 'brown'
303
+ }
304
+ },
305
+ themeOverrides: {
306
+ colors: {
307
+ primitives: {
308
+ green12: 'pink'
309
+ }
310
+ }
311
+ }
312
+ },
313
+ children: _jsx(ExampleComponent, {
314
+ callback: cb6
315
+ })
316
+ })]
317
+ })]
318
+ }));
319
+ expect(cb1).to.have.been.calledWithMatch({
320
+ ...theme,
321
+ colors: {
322
+ primitives: {
323
+ red12: 'red',
324
+ green12: 'yellow',
325
+ blue12: 'magenta'
326
+ }
327
+ }
328
+ });
329
+ expect(cb2).to.have.been.calledWith(canvasHighContrast);
330
+ expect(cb3).to.have.been.calledWith(canvas);
331
+ expect(cb4).to.have.been.calledWithMatch({
332
+ ...canvas,
333
+ colors: {
334
+ primitives: {
335
+ red12: 'orange',
336
+ green12: 'olive'
337
+ }
338
+ }
339
+ });
340
+ expect(cb5).to.have.been.calledWithMatch({
341
+ ...theme,
342
+ colors: {
343
+ primitives: {
344
+ red12: 'red',
345
+ green12: 'yellow',
346
+ blue12: 'magenta'
347
+ }
348
+ }
349
+ });
350
+ expect(cb6).to.have.been.calledWithMatch({
351
+ ...theme,
352
+ colors: {
353
+ primitives: {
354
+ red12: 'brown',
355
+ green12: 'pink',
356
+ blue12: 'magenta'
357
+ }
358
+ }
359
+ });
360
+ });
361
+ it('local themes should work correctly', async () => {
362
+ const _Array$fill$map3 = Array(6).fill(0).map(() => spy()),
363
+ _Array$fill$map4 = _slicedToArray(_Array$fill$map3, 4),
364
+ cb1 = _Array$fill$map4[0],
365
+ cb2 = _Array$fill$map4[1],
366
+ cb3 = _Array$fill$map4[2],
367
+ cb4 = _Array$fill$map4[3];
368
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
369
+ theme.use({
370
+ overrides: {
371
+ colors: {
372
+ primitives: {
373
+ red12: 'red',
374
+ green12: 'yellow',
375
+ blue12: 'magenta'
376
+ }
377
+ }
378
+ }
379
+ });
380
+ await mount(_jsxs(_Fragment, {
381
+ children: [_jsx(ExampleComponent, {
382
+ callback: cb1
383
+ }), _jsxs(InstUISettingsProvider, {
384
+ theme: canvas,
385
+ children: [_jsx(ExampleComponent, {
386
+ callback: cb2
387
+ }), _jsxs(InstUISettingsProvider, {
388
+ theme: canvasThemeLocal,
389
+ children: [_jsx(ExampleComponent, {
390
+ callback: cb3
391
+ }), _jsx(InstUISettingsProvider, {
392
+ theme: {
393
+ colors: {
394
+ primitives: {
395
+ red12: 'orange'
396
+ }
397
+ },
398
+ themeOverrides: {
399
+ colors: {
400
+ primitives: {
401
+ green12: 'olive'
402
+ }
403
+ }
404
+ }
405
+ },
406
+ children: _jsx(ExampleComponent, {
407
+ callback: cb4
408
+ })
409
+ })]
410
+ })]
411
+ })]
412
+ }));
413
+ expect(cb1).to.have.been.calledWithMatch({
414
+ ...theme,
415
+ colors: {
416
+ primitives: {
417
+ red12: 'red',
418
+ green12: 'yellow',
419
+ blue12: 'magenta'
420
+ }
421
+ }
422
+ });
423
+ expect(cb2).to.have.been.calledWith(canvas);
424
+ expect(cb3).to.have.been.calledWith(canvasThemeLocal);
425
+ expect(cb4).to.have.been.calledWithMatch({
426
+ ...canvasThemeLocal,
427
+ colors: {
428
+ primitives: {
429
+ red12: 'orange',
430
+ green12: 'olive'
431
+ }
432
+ }
433
+ });
434
+ });
435
+ });
436
+ it('should work correctly when multiple React trees is used', async () => {
437
+ const callback1 = spy();
438
+ const callback2 = spy();
439
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
440
+ theme.use();
441
+
442
+ //first react tree
443
+ await mount(_jsx(ExampleComponent, {
444
+ callback: callback1
445
+ }));
446
+
447
+ //second react tree
448
+ await mount(_jsx(ExampleComponent, {
449
+ callback: callback2
450
+ }));
451
+ expect(callback1).to.have.been.calledWith(theme);
452
+ expect(callback2).to.have.been.calledWith(theme);
453
+ });
454
+ it('should work correctly when multiple React trees is used together with InstUISettingsProvider', async () => {
455
+ const callback1 = spy();
456
+ const callback2 = spy();
457
+ const callback3 = spy();
458
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast);
459
+ theme.use();
460
+
461
+ //first react tree
462
+ await mount(_jsx(ExampleComponent, {
463
+ callback: callback1
464
+ }));
465
+
466
+ //second react tree
467
+ await mount(_jsx(InstUISettingsProvider, {
468
+ children: _jsx(ExampleComponent, {
469
+ callback: callback2
470
+ })
471
+ }));
472
+
473
+ //third react tree
474
+ await mount(_jsx(InstUISettingsProvider, {
475
+ theme: canvasHighContrast,
476
+ children: _jsx(ExampleComponent, {
477
+ callback: callback3
478
+ })
479
+ }));
480
+ expect(callback1).to.have.been.calledWith(theme);
481
+ expect(callback2).to.have.been.calledWith(theme);
482
+ expect(callback3).to.have.been.calledWith(canvasHighContrast);
483
+ });
484
+ });