@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,510 @@
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 {
26
+ canvas,
27
+ canvasHighContrast,
28
+ canvasThemeLocal
29
+ } from '@instructure/ui-themes'
30
+ import { expect, mount, spy } from '@instructure/ui-test-utils'
31
+ import { ThemeRegistry } from '@instructure/theme-registry'
32
+
33
+ import { useTheme } from '../useTheme'
34
+ import { InstUISettingsProvider } from '../InstUISettingsProvider'
35
+ import type { ThemeOrOverride } from '../EmotionTypes'
36
+
37
+ const defaultRegistry = ThemeRegistry.getRegistry()
38
+
39
+ type Props = {
40
+ callback(theme: ThemeOrOverride): void
41
+ }
42
+
43
+ const ExampleComponent = (props: Props) => {
44
+ const theme = useTheme()
45
+
46
+ props.callback(theme)
47
+
48
+ return null
49
+ }
50
+
51
+ describe('useTheme hook', () => {
52
+ beforeEach(() => {
53
+ ThemeRegistry.clearRegistry()
54
+ })
55
+ afterEach(() => {
56
+ //this is needed to not mess up the global Theme Registry
57
+ ThemeRegistry.setRegistry(defaultRegistry)
58
+ })
59
+ describe('with using InstUISettingsProvider', () => {
60
+ it('should use default canvas theme when no "theme" is provided', async () => {
61
+ const callback = spy()
62
+ await mount(
63
+ <InstUISettingsProvider>
64
+ <ExampleComponent callback={callback}></ExampleComponent>
65
+ </InstUISettingsProvider>
66
+ )
67
+
68
+ expect(callback).to.have.been.calledWith(canvas)
69
+ })
70
+ it('should use global theme when no "theme" is provided', async () => {
71
+ const callback = spy()
72
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
73
+ theme.use()
74
+
75
+ await mount(
76
+ <InstUISettingsProvider>
77
+ <ExampleComponent callback={callback}></ExampleComponent>
78
+ </InstUISettingsProvider>
79
+ )
80
+
81
+ expect(callback).to.have.been.calledWith(theme)
82
+ })
83
+ it('should default to canvas theme when no global theme is available and no theme is provided', async () => {
84
+ const callback = spy()
85
+
86
+ await mount(
87
+ <InstUISettingsProvider>
88
+ <ExampleComponent callback={callback}></ExampleComponent>
89
+ </InstUISettingsProvider>
90
+ )
91
+
92
+ expect(callback).to.have.been.calledWith(canvas)
93
+ })
94
+ it('should use provided theme when theme is provided', async () => {
95
+ const callback = spy()
96
+ const theme = ThemeRegistry.registerTheme(canvas)
97
+ theme.use()
98
+
99
+ await mount(
100
+ <InstUISettingsProvider theme={canvasHighContrast}>
101
+ <ExampleComponent callback={callback}></ExampleComponent>
102
+ </InstUISettingsProvider>
103
+ )
104
+
105
+ expect(callback).to.have.been.calledWith(canvasHighContrast)
106
+ })
107
+ it('should override the default theme when no other theme is available', async () => {
108
+ const callback = spy()
109
+ await mount(
110
+ <InstUISettingsProvider
111
+ theme={{
112
+ colors: {
113
+ primitives: {
114
+ white: 'red'
115
+ }
116
+ }
117
+ }}
118
+ >
119
+ <ExampleComponent callback={callback}></ExampleComponent>
120
+ </InstUISettingsProvider>
121
+ )
122
+
123
+ expect(callback).to.have.been.calledWithMatch({
124
+ ...canvas,
125
+ colors: {
126
+ primitives: {
127
+ white: 'red'
128
+ }
129
+ }
130
+ })
131
+ })
132
+ it('should override the global theme if that is the only theme available', async () => {
133
+ const callback = spy()
134
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
135
+ theme.use()
136
+
137
+ await mount(
138
+ <InstUISettingsProvider
139
+ theme={{
140
+ colors: {
141
+ primitives: {
142
+ white: 'red'
143
+ }
144
+ }
145
+ }}
146
+ >
147
+ <ExampleComponent callback={callback}></ExampleComponent>
148
+ </InstUISettingsProvider>
149
+ )
150
+
151
+ expect(callback).to.have.been.calledWithMatch({
152
+ ...theme,
153
+ colors: {
154
+ primitives: {
155
+ white: 'red'
156
+ }
157
+ }
158
+ })
159
+ })
160
+ it('should override the global theme with the "themeOverrides" option if that is the only theme available', async () => {
161
+ const callback = spy()
162
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
163
+ theme.use()
164
+
165
+ await mount(
166
+ <InstUISettingsProvider
167
+ theme={{
168
+ themeOverrides: {
169
+ colors: {
170
+ primitives: {
171
+ white: 'red'
172
+ }
173
+ }
174
+ }
175
+ }}
176
+ >
177
+ <ExampleComponent callback={callback}></ExampleComponent>
178
+ </InstUISettingsProvider>
179
+ )
180
+
181
+ expect(callback).to.have.been.calledWithMatch({
182
+ ...theme,
183
+ colors: {
184
+ primitives: {
185
+ white: 'red'
186
+ }
187
+ }
188
+ })
189
+ })
190
+ it('should override the theme from context when provided', async () => {
191
+ const callback = spy()
192
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
193
+ theme.use()
194
+
195
+ await mount(
196
+ <InstUISettingsProvider theme={canvasHighContrast}>
197
+ <InstUISettingsProvider
198
+ theme={{
199
+ themeOverrides: {
200
+ colors: {
201
+ primitives: {
202
+ white: 'red'
203
+ }
204
+ }
205
+ }
206
+ }}
207
+ >
208
+ <ExampleComponent callback={callback}></ExampleComponent>
209
+ </InstUISettingsProvider>
210
+ </InstUISettingsProvider>
211
+ )
212
+
213
+ expect(callback).to.have.been.calledWithMatch({
214
+ ...canvasHighContrast,
215
+ colors: {
216
+ primitives: {
217
+ white: 'red'
218
+ }
219
+ }
220
+ })
221
+ })
222
+ it('should use local themes correctly', async () => {
223
+ const callback = spy()
224
+ const theme = ThemeRegistry.registerTheme(canvas)
225
+ theme.use()
226
+ await mount(
227
+ <InstUISettingsProvider theme={canvasThemeLocal}>
228
+ <InstUISettingsProvider
229
+ theme={{
230
+ themeOverrides: {
231
+ colors: {
232
+ primitives: {
233
+ white: 'red'
234
+ }
235
+ }
236
+ }
237
+ }}
238
+ >
239
+ <ExampleComponent callback={callback}></ExampleComponent>
240
+ </InstUISettingsProvider>
241
+ </InstUISettingsProvider>
242
+ )
243
+
244
+ expect(callback).to.have.been.calledWithMatch({
245
+ ...canvasThemeLocal,
246
+ colors: {
247
+ primitives: {
248
+ white: 'red'
249
+ }
250
+ }
251
+ })
252
+ })
253
+ })
254
+ describe('without using InstUISettingsProvider', () => {
255
+ it('should use theme from global ThemeRegistry', async () => {
256
+ const callback = spy()
257
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
258
+ theme.use()
259
+
260
+ await mount(<ExampleComponent callback={callback}></ExampleComponent>)
261
+
262
+ expect(callback).to.have.been.calledWith(theme)
263
+ })
264
+ it('should use default "canvas" theme when no theme is used from ThemeRegistry', async () => {
265
+ const callback = spy()
266
+ await mount(<ExampleComponent callback={callback}></ExampleComponent>)
267
+
268
+ expect(callback).to.have.been.calledWith(canvas)
269
+ })
270
+ })
271
+
272
+ describe('with InstUISettingsProvider and global theme', () => {
273
+ it('overrides should work correctly', async () => {
274
+ const [cb1, cb2, cb3, cb4, cb5, cb6] = Array(6)
275
+ .fill(0)
276
+ .map(() => spy())
277
+
278
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
279
+ theme.use({
280
+ overrides: {
281
+ colors: {
282
+ primitives: {
283
+ red12: 'red',
284
+ green12: 'yellow',
285
+ blue12: 'magenta'
286
+ }
287
+ }
288
+ }
289
+ })
290
+
291
+ await mount(
292
+ <>
293
+ {/* no provider -> canvasHighContrast theme */}
294
+ <ExampleComponent callback={cb1}></ExampleComponent>
295
+ <InstUISettingsProvider theme={canvasHighContrast}>
296
+ {/* theme provided -> canvasHighContrast */}
297
+ <ExampleComponent callback={cb2}></ExampleComponent>
298
+ <InstUISettingsProvider theme={canvas}>
299
+ {/* theme provided -> canvas theme */}
300
+ <ExampleComponent callback={cb3}></ExampleComponent>
301
+ <InstUISettingsProvider
302
+ theme={{
303
+ colors: {
304
+ primitives: {
305
+ red12: 'orange'
306
+ }
307
+ },
308
+ themeOverrides: {
309
+ colors: {
310
+ primitives: {
311
+ green12: 'olive'
312
+ }
313
+ }
314
+ }
315
+ }}
316
+ >
317
+ {/* theme provided -> canvas theme with overrides */}
318
+ <ExampleComponent callback={cb4}></ExampleComponent>
319
+ </InstUISettingsProvider>
320
+ </InstUISettingsProvider>
321
+ </InstUISettingsProvider>
322
+ <InstUISettingsProvider>
323
+ {/* no theme provided -> canvasHighContrast theme */}
324
+ <ExampleComponent callback={cb5}></ExampleComponent>
325
+ <InstUISettingsProvider
326
+ theme={{
327
+ colors: {
328
+ primitives: {
329
+ red12: 'brown'
330
+ }
331
+ },
332
+ themeOverrides: {
333
+ colors: {
334
+ primitives: {
335
+ green12: 'pink'
336
+ }
337
+ }
338
+ }
339
+ }}
340
+ >
341
+ {/* no theme provided -> canvasHighContrast theme with overrides */}
342
+ <ExampleComponent callback={cb6}></ExampleComponent>
343
+ </InstUISettingsProvider>
344
+ </InstUISettingsProvider>
345
+ </>
346
+ )
347
+
348
+ expect(cb1).to.have.been.calledWithMatch({
349
+ ...theme,
350
+ colors: {
351
+ primitives: {
352
+ red12: 'red',
353
+ green12: 'yellow',
354
+ blue12: 'magenta'
355
+ }
356
+ }
357
+ })
358
+ expect(cb2).to.have.been.calledWith(canvasHighContrast)
359
+ expect(cb3).to.have.been.calledWith(canvas)
360
+ expect(cb4).to.have.been.calledWithMatch({
361
+ ...canvas,
362
+ colors: {
363
+ primitives: {
364
+ red12: 'orange',
365
+ green12: 'olive'
366
+ }
367
+ }
368
+ })
369
+ expect(cb5).to.have.been.calledWithMatch({
370
+ ...theme,
371
+ colors: {
372
+ primitives: {
373
+ red12: 'red',
374
+ green12: 'yellow',
375
+ blue12: 'magenta'
376
+ }
377
+ }
378
+ })
379
+ expect(cb6).to.have.been.calledWithMatch({
380
+ ...theme,
381
+ colors: {
382
+ primitives: {
383
+ red12: 'brown',
384
+ green12: 'pink',
385
+ blue12: 'magenta'
386
+ }
387
+ }
388
+ })
389
+ })
390
+ it('local themes should work correctly', async () => {
391
+ const [cb1, cb2, cb3, cb4] = Array(6)
392
+ .fill(0)
393
+ .map(() => spy())
394
+
395
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
396
+ theme.use({
397
+ overrides: {
398
+ colors: {
399
+ primitives: {
400
+ red12: 'red',
401
+ green12: 'yellow',
402
+ blue12: 'magenta'
403
+ }
404
+ }
405
+ }
406
+ })
407
+
408
+ await mount(
409
+ <>
410
+ {/* no provider -> canvasHighContrast theme */}
411
+ <ExampleComponent callback={cb1}></ExampleComponent>
412
+ <InstUISettingsProvider theme={canvas}>
413
+ {/* theme provided -> canvas */}
414
+ <ExampleComponent callback={cb2}></ExampleComponent>
415
+ <InstUISettingsProvider theme={canvasThemeLocal}>
416
+ {/* theme provided -> canvasThemeLocal theme */}
417
+ <ExampleComponent callback={cb3}></ExampleComponent>
418
+ <InstUISettingsProvider
419
+ theme={{
420
+ colors: {
421
+ primitives: {
422
+ red12: 'orange'
423
+ }
424
+ },
425
+ themeOverrides: {
426
+ colors: {
427
+ primitives: {
428
+ green12: 'olive'
429
+ }
430
+ }
431
+ }
432
+ }}
433
+ >
434
+ {/* theme provided -> canvas theme with overrides */}
435
+ <ExampleComponent callback={cb4}></ExampleComponent>
436
+ </InstUISettingsProvider>
437
+ </InstUISettingsProvider>
438
+ </InstUISettingsProvider>
439
+ </>
440
+ )
441
+
442
+ expect(cb1).to.have.been.calledWithMatch({
443
+ ...theme,
444
+ colors: {
445
+ primitives: {
446
+ red12: 'red',
447
+ green12: 'yellow',
448
+ blue12: 'magenta'
449
+ }
450
+ }
451
+ })
452
+ expect(cb2).to.have.been.calledWith(canvas)
453
+ expect(cb3).to.have.been.calledWith(canvasThemeLocal)
454
+ expect(cb4).to.have.been.calledWithMatch({
455
+ ...canvasThemeLocal,
456
+ colors: {
457
+ primitives: {
458
+ red12: 'orange',
459
+ green12: 'olive'
460
+ }
461
+ }
462
+ })
463
+ })
464
+ })
465
+ it('should work correctly when multiple React trees is used', async () => {
466
+ const callback1 = spy()
467
+ const callback2 = spy()
468
+
469
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
470
+ theme.use()
471
+
472
+ //first react tree
473
+ await mount(<ExampleComponent callback={callback1}></ExampleComponent>)
474
+
475
+ //second react tree
476
+ await mount(<ExampleComponent callback={callback2}></ExampleComponent>)
477
+
478
+ expect(callback1).to.have.been.calledWith(theme)
479
+ expect(callback2).to.have.been.calledWith(theme)
480
+ })
481
+ it('should work correctly when multiple React trees is used together with InstUISettingsProvider', async () => {
482
+ const callback1 = spy()
483
+ const callback2 = spy()
484
+ const callback3 = spy()
485
+
486
+ const theme = ThemeRegistry.registerTheme(canvasHighContrast)
487
+ theme.use()
488
+
489
+ //first react tree
490
+ await mount(<ExampleComponent callback={callback1}></ExampleComponent>)
491
+
492
+ //second react tree
493
+ await mount(
494
+ <InstUISettingsProvider>
495
+ <ExampleComponent callback={callback2}></ExampleComponent>
496
+ </InstUISettingsProvider>
497
+ )
498
+
499
+ //third react tree
500
+ await mount(
501
+ <InstUISettingsProvider theme={canvasHighContrast}>
502
+ <ExampleComponent callback={callback3}></ExampleComponent>
503
+ </InstUISettingsProvider>
504
+ )
505
+
506
+ expect(callback1).to.have.been.calledWith(theme)
507
+ expect(callback2).to.have.been.calledWith(theme)
508
+ expect(callback3).to.have.been.calledWith(canvasHighContrast)
509
+ })
510
+ })