@instructure/ui-utils 8.52.1-snapshot-6 → 8.52.1-snapshot-11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/__new-tests__/camelize.test.js +40 -0
  3. package/es/__new-tests__/cloneArray.test.js +52 -0
  4. package/es/__new-tests__/createChainedFunction.test.js +50 -0
  5. package/es/__new-tests__/generateId.test.js +60 -0
  6. package/es/__new-tests__/hash.test.js +415 -0
  7. package/es/__new-tests__/mergeDeep.test.js +196 -0
  8. package/es/__new-tests__/ms.test.js +40 -0
  9. package/es/__new-tests__/parseUnit.test.js +69 -0
  10. package/es/__new-tests__/pascalize.test.js +48 -0
  11. package/es/__new-tests__/px.test.js +51 -0
  12. package/es/__new-tests__/within.test.js +41 -0
  13. package/lib/__new-tests__/camelize.test.js +43 -0
  14. package/lib/__new-tests__/cloneArray.test.js +55 -0
  15. package/lib/__new-tests__/createChainedFunction.test.js +52 -0
  16. package/lib/__new-tests__/generateId.test.js +63 -0
  17. package/lib/__new-tests__/hash.test.js +417 -0
  18. package/lib/__new-tests__/mergeDeep.test.js +198 -0
  19. package/lib/__new-tests__/ms.test.js +42 -0
  20. package/lib/__new-tests__/parseUnit.test.js +71 -0
  21. package/lib/__new-tests__/pascalize.test.js +50 -0
  22. package/lib/__new-tests__/px.test.js +53 -0
  23. package/lib/__new-tests__/within.test.js +43 -0
  24. package/package.json +6 -5
  25. package/src/__new-tests__/camelize.test.tsx +42 -0
  26. package/src/__new-tests__/cloneArray.test.tsx +62 -0
  27. package/src/__new-tests__/createChainedFunction.test.tsx +54 -0
  28. package/src/__new-tests__/generateId.test.tsx +69 -0
  29. package/src/__new-tests__/hash.test.tsx +547 -0
  30. package/src/__new-tests__/mergeDeep.test.tsx +133 -0
  31. package/src/__new-tests__/ms.test.tsx +44 -0
  32. package/src/__new-tests__/parseUnit.test.tsx +80 -0
  33. package/src/__new-tests__/pascalize.test.tsx +51 -0
  34. package/src/__new-tests__/px.test.tsx +59 -0
  35. package/src/__new-tests__/within.test.tsx +44 -0
  36. package/tsconfig.build.json +0 -3
  37. package/tsconfig.build.tsbuildinfo +1 -1
  38. package/types/__new-tests__/camelize.test.d.ts +2 -0
  39. package/types/__new-tests__/camelize.test.d.ts.map +1 -0
  40. package/types/__new-tests__/cloneArray.test.d.ts +2 -0
  41. package/types/__new-tests__/cloneArray.test.d.ts.map +1 -0
  42. package/types/__new-tests__/createChainedFunction.test.d.ts +2 -0
  43. package/types/__new-tests__/createChainedFunction.test.d.ts.map +1 -0
  44. package/types/__new-tests__/generateId.test.d.ts +2 -0
  45. package/types/__new-tests__/generateId.test.d.ts.map +1 -0
  46. package/types/__new-tests__/hash.test.d.ts +2 -0
  47. package/types/__new-tests__/hash.test.d.ts.map +1 -0
  48. package/types/__new-tests__/mergeDeep.test.d.ts +2 -0
  49. package/types/__new-tests__/mergeDeep.test.d.ts.map +1 -0
  50. package/types/__new-tests__/ms.test.d.ts +2 -0
  51. package/types/__new-tests__/ms.test.d.ts.map +1 -0
  52. package/types/__new-tests__/parseUnit.test.d.ts +2 -0
  53. package/types/__new-tests__/parseUnit.test.d.ts.map +1 -0
  54. package/types/__new-tests__/pascalize.test.d.ts +2 -0
  55. package/types/__new-tests__/pascalize.test.d.ts.map +1 -0
  56. package/types/__new-tests__/px.test.d.ts +2 -0
  57. package/types/__new-tests__/px.test.d.ts.map +1 -0
  58. package/types/__new-tests__/within.test.d.ts +2 -0
  59. package/types/__new-tests__/within.test.d.ts.map +1 -0
@@ -0,0 +1,196 @@
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 '@testing-library/jest-dom';
26
+ import { mergeDeep } from '../mergeDeep';
27
+ describe('mergeDeep', () => {
28
+ it('should merge object properties without affecting any object', () => {
29
+ const obj1 = {
30
+ a: 0,
31
+ b: 1
32
+ };
33
+ const obj2 = {
34
+ c: 2,
35
+ d: 3
36
+ };
37
+ const obj3 = {
38
+ a: 4,
39
+ d: 5
40
+ };
41
+ const expected = {
42
+ a: 4,
43
+ b: 1,
44
+ c: 2,
45
+ d: 5
46
+ };
47
+ expect(mergeDeep({}, obj1, obj2, obj3)).toStrictEqual(expected);
48
+ expect(obj1).not.toStrictEqual(expected);
49
+ expect(obj2).not.toStrictEqual(expected);
50
+ expect(obj3).not.toStrictEqual(expected);
51
+ });
52
+ it('should do a deep merge', () => {
53
+ const obj1 = {
54
+ a: {
55
+ b: 1,
56
+ c: 1,
57
+ d: {
58
+ e: 1,
59
+ f: 1
60
+ }
61
+ }
62
+ };
63
+ const obj2 = {
64
+ a: {
65
+ b: 2,
66
+ d: {
67
+ f: 'f'
68
+ }
69
+ }
70
+ };
71
+ expect(mergeDeep(obj1, obj2)).toStrictEqual({
72
+ a: {
73
+ b: 2,
74
+ c: 1,
75
+ d: {
76
+ e: 1,
77
+ f: 'f'
78
+ }
79
+ }
80
+ });
81
+ });
82
+ it('should not merge strings', () => {
83
+ const obj1 = {
84
+ a: 'foo'
85
+ };
86
+ const obj2 = {
87
+ a: {
88
+ b: 2,
89
+ d: {
90
+ f: 'f'
91
+ }
92
+ }
93
+ };
94
+ const obj3 = {
95
+ a: 'bar'
96
+ };
97
+ const result = mergeDeep(obj1, obj2, obj3);
98
+ expect(result.a).toEqual('bar');
99
+ });
100
+ it('should clone objects during merge', () => {
101
+ const obj1 = {
102
+ a: {
103
+ b: 1
104
+ }
105
+ };
106
+ const obj2 = {
107
+ a: {
108
+ c: 2
109
+ }
110
+ };
111
+ const result = mergeDeep({}, obj1, obj2);
112
+ expect(result).toStrictEqual({
113
+ a: {
114
+ b: 1,
115
+ c: 2
116
+ }
117
+ });
118
+ expect(result.a).not.toStrictEqual(obj1.a);
119
+ expect(result.a).not.toStrictEqual(obj2.a);
120
+ });
121
+ it('should not merge an object into an array', () => {
122
+ const obj1 = {
123
+ a: {
124
+ b: 1
125
+ }
126
+ };
127
+ const obj2 = {
128
+ a: ['foo', 'bar']
129
+ };
130
+ const result = mergeDeep({}, obj1, obj2);
131
+ expect(result).toStrictEqual({
132
+ a: ['foo', 'bar']
133
+ });
134
+ });
135
+ it('should deep clone arrays during merge', () => {
136
+ const obj1 = {
137
+ a: [1, 2, [3, 4]]
138
+ };
139
+ const obj2 = {
140
+ b: [5, 6]
141
+ };
142
+ const result = mergeDeep(obj1, obj2);
143
+ expect(result.a).toStrictEqual([1, 2, [3, 4]]);
144
+ expect(result.a[2]).toStrictEqual([3, 4]);
145
+ expect(result.b).toStrictEqual(obj2.b);
146
+ });
147
+ it('should union when both values are array', () => {
148
+ const obj1 = {
149
+ a: [1, 2, [3, 4]]
150
+ };
151
+ const obj2 = {
152
+ a: [5, 6]
153
+ };
154
+ const result = mergeDeep(obj1, obj2);
155
+ expect(result.a).toStrictEqual([1, 2, [3, 4], 5, 6]);
156
+ expect(result.a[2]).toStrictEqual([3, 4]);
157
+ });
158
+ it('should union when the first value is an array', () => {
159
+ const obj1 = {
160
+ a: [1, 2, [3, 4]]
161
+ };
162
+ const obj2 = {
163
+ a: 5
164
+ };
165
+ const obj3 = {
166
+ a: 6
167
+ };
168
+ const result = mergeDeep(obj1, obj2, obj3);
169
+ expect(result.a).toStrictEqual([1, 2, [3, 4], 5, 6]);
170
+ expect(result.a[2]).toStrictEqual([3, 4]);
171
+ });
172
+ it('should uniquify array values', () => {
173
+ const obj1 = {
174
+ a: ['foo']
175
+ };
176
+ const obj2 = {
177
+ a: ['bar']
178
+ };
179
+ const obj3 = {
180
+ a: 'foo'
181
+ };
182
+ const result = mergeDeep(obj1, obj2, obj3);
183
+ expect(result.a).toStrictEqual(['foo', 'bar']);
184
+ });
185
+ it('should copy source properties', () => {
186
+ expect(mergeDeep({
187
+ test: true
188
+ }).test).toBe(true);
189
+ });
190
+ it('should not clone objects created with custom constructor', () => {
191
+ function TestType() {}
192
+ // @ts-expect-error intentional "new"
193
+ const func = new TestType();
194
+ expect(mergeDeep(func)).toEqual(func);
195
+ });
196
+ });
@@ -0,0 +1,40 @@
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 '@testing-library/jest-dom';
26
+ import { ms } from '../ms';
27
+ describe('ms', () => {
28
+ it('handles ms unit', () => {
29
+ expect(ms('4ms')).toEqual(4);
30
+ });
31
+ it('converts s to ms', () => {
32
+ expect(ms('0.3s')).toEqual(0.3 * 1000);
33
+ });
34
+ it('handles unitless input', () => {
35
+ expect(ms('15')).toEqual(15);
36
+ });
37
+ it('handles numeric input', () => {
38
+ expect(ms(15)).toEqual(15);
39
+ });
40
+ });
@@ -0,0 +1,69 @@
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 '@testing-library/jest-dom';
26
+ import { parseUnit } from '../parseUnit';
27
+ describe('parseUnit', () => {
28
+ it('unitless', () => {
29
+ expect(parseUnit('50')[0]).toEqual(50);
30
+ });
31
+ it('integer', () => {
32
+ expect(parseUnit(50)[0]).toEqual(50);
33
+ });
34
+ it('decimal', () => {
35
+ expect(parseUnit(47.89101)[0]).toEqual(47.89101);
36
+ });
37
+ it('negative', () => {
38
+ expect(parseUnit('-20px')[0]).toEqual(-20);
39
+ expect(parseUnit('-20px')[1]).toEqual('px');
40
+ });
41
+ it('px', () => {
42
+ expect(parseUnit('100.0792px')[0]).toEqual(100.0792);
43
+ expect(parseUnit('100.0792px')[1]).toEqual('px');
44
+ });
45
+ it('rem', () => {
46
+ expect(parseUnit('4000rem')[0]).toEqual(4000);
47
+ expect(parseUnit('4000rem')[1]).toEqual('rem');
48
+ });
49
+ it('em', () => {
50
+ expect(parseUnit('300em')[0]).toEqual(300);
51
+ expect(parseUnit('300em')[1]).toEqual('em');
52
+ });
53
+ it('s', () => {
54
+ expect(parseUnit('5s')[0]).toEqual(5);
55
+ expect(parseUnit('5s')[1]).toEqual('s');
56
+ });
57
+ it('ms', () => {
58
+ expect(parseUnit('20ms')[0]).toEqual(20);
59
+ expect(parseUnit('20ms')[1]).toEqual('ms');
60
+ });
61
+ it('vh', () => {
62
+ expect(parseUnit('327vh')[0]).toEqual(327);
63
+ expect(parseUnit('327vh')[1]).toEqual('vh');
64
+ });
65
+ it('vmin', () => {
66
+ expect(parseUnit('70vmin')[0]).toEqual(70);
67
+ expect(parseUnit('70vmin')[1]).toEqual('vmin');
68
+ });
69
+ });
@@ -0,0 +1,48 @@
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 '@testing-library/jest-dom';
26
+ import { pascalize } from '../pascalize';
27
+ describe('convertCase', () => {
28
+ describe('pascalize', () => {
29
+ it('handles hyphenated strings', () => {
30
+ expect(pascalize('foo-bar')).toEqual('FooBar');
31
+ expect(pascalize('baz-qux-foo')).toEqual('BazQuxFoo');
32
+ expect(pascalize('x-large')).toEqual('XLarge');
33
+ expect(pascalize('x-x-small')).toEqual('XXSmall');
34
+ });
35
+ it('handles camel cased strings', () => {
36
+ expect(pascalize('fooBar')).toEqual('FooBar');
37
+ expect(pascalize('bazQuxFoo')).toEqual('BazQuxFoo');
38
+ expect(pascalize('xLarge')).toEqual('XLarge');
39
+ expect(pascalize('borderRadiusLarge')).toEqual('BorderRadiusLarge');
40
+ });
41
+ it('does not modify already pascal cased strings', () => {
42
+ expect(pascalize('FooBar')).toEqual('FooBar');
43
+ expect(pascalize('BazQuxFoo')).toEqual('BazQuxFoo');
44
+ expect(pascalize('XLarge')).toEqual('XLarge');
45
+ expect(pascalize('BorderRadiusLarge')).toEqual('BorderRadiusLarge');
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,51 @@
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 '@testing-library/jest-dom';
26
+ import { getFontSize } from '@instructure/ui-dom-utils';
27
+ import { px } from '../px';
28
+ describe('px', () => {
29
+ let node;
30
+ beforeEach(() => {
31
+ node = document.createElement('div');
32
+ document.body.appendChild(node);
33
+ });
34
+ afterEach(() => {
35
+ node && node.parentNode && node.parentNode.removeChild(node);
36
+ node = null;
37
+ });
38
+ it('handles px units', () => {
39
+ expect(px('30px')).toEqual(30);
40
+ });
41
+ it('converts rem to px', () => {
42
+ expect(px('50rem')).toEqual(50 * getFontSize());
43
+ });
44
+ it('converts em to px', () => {
45
+ node.style.fontSize = '24px';
46
+ expect(px('10em', node)).toEqual(10 * getFontSize(node));
47
+ });
48
+ it('handles unitless input', () => {
49
+ expect(px('4')).toEqual(4);
50
+ });
51
+ });
@@ -0,0 +1,41 @@
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 '@testing-library/jest-dom';
26
+ import { within } from '../within';
27
+ describe('within', () => {
28
+ it('returns true when values are within range', () => {
29
+ expect(within(10, 8, 2)).toBe(true);
30
+ expect(within(10, 11, 1)).toBe(true);
31
+ expect(within(10, 10, 0)).toBe(true);
32
+ expect(within(10, 9.999, 0.001)).toBe(true);
33
+ expect(within(-10, -15, 5)).toBe(true);
34
+ });
35
+ it('returns false when values are out of range', () => {
36
+ expect(within(10, 8, 1)).toBe(false);
37
+ expect(within(12, 10, 1.9999)).toBe(false);
38
+ expect(within(8.705, 8.7, 0.004)).toBe(false);
39
+ expect(within(-2, -1.5, 0.4)).toBe(false);
40
+ });
41
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _camelize = require("../camelize");
5
+ /*
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2015 - present Instructure, Inc.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ */
28
+
29
+ describe('convertCase', () => {
30
+ describe('camelize', () => {
31
+ it('handles hyphenated strings', () => {
32
+ expect((0, _camelize.camelize)('foo-bar')).toEqual('fooBar');
33
+ expect((0, _camelize.camelize)('baz-qux-foo')).toEqual('bazQuxFoo');
34
+ expect((0, _camelize.camelize)('xx-small')).toEqual('xxSmall');
35
+ expect((0, _camelize.camelize)('border-radius-x-large')).toEqual('borderRadiusXLarge');
36
+ expect((0, _camelize.camelize)('margin-xxLarge')).toEqual('marginXxLarge');
37
+ });
38
+ it('does not modify already camel cased strings', () => {
39
+ expect((0, _camelize.camelize)('fooBar')).toEqual('fooBar');
40
+ expect((0, _camelize.camelize)('bazQuxFoo')).toEqual('bazQuxFoo');
41
+ });
42
+ });
43
+ });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _cloneArray = require("../cloneArray");
5
+ var _deepEqual = require("../deepEqual");
6
+ /*
7
+ * The MIT License (MIT)
8
+ *
9
+ * Copyright (c) 2015 - present Instructure, Inc.
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+ describe('cloneArray', () => {
31
+ it('should return an array', () => {
32
+ const arr = [['one', 'two'], ['three']];
33
+ const newArr = (0, _cloneArray.cloneArray)(arr);
34
+ expect(Array.isArray(newArr)).toBeTruthy();
35
+ });
36
+ it('should preserve sub arrays', () => {
37
+ const arr = [['one', 'two'], ['three'], [4, 5, 6], [7, [8, 9, 10], 11, 12]];
38
+ const newArr = (0, _cloneArray.cloneArray)(arr);
39
+ expect(newArr.length).toEqual(4);
40
+ expect(newArr[0].length).toEqual(2);
41
+ expect(newArr[2][1]).toEqual(5);
42
+ expect(Array.isArray(newArr[3][1])).toEqual(true);
43
+ expect(newArr[3][1][2]).toEqual(10);
44
+ });
45
+ it('should return a new array', () => {
46
+ const arr = [['one', 'two'], ['three']];
47
+ const newArr = (0, _cloneArray.cloneArray)(arr);
48
+ expect((0, _deepEqual.deepEqual)(arr, newArr)).toEqual(true);
49
+ newArr[0][1] = '2';
50
+ expect((0, _deepEqual.deepEqual)(arr, newArr)).toEqual(false);
51
+ const newArr2 = (0, _cloneArray.cloneArray)(arr);
52
+ arr[0][0] = '1';
53
+ expect((0, _deepEqual.deepEqual)(arr, newArr2)).toEqual(false);
54
+ });
55
+ });
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _createChainedFunction = require("../createChainedFunction");
5
+ /*
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2015 - present Instructure, Inc.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ */
28
+
29
+ describe('createChainedFunction', () => {
30
+ it('should return null if no function provided', () => {
31
+ expect((0, _createChainedFunction.createChainedFunction)(null, void 0)).toEqual(null);
32
+ });
33
+ it('should return a function', () => {
34
+ expect(typeof (0, _createChainedFunction.createChainedFunction)(() => {})).toEqual('function');
35
+ });
36
+ it('should throw an error if something other than function, null, undefined provided', () => {
37
+ expect(() => {
38
+ // @ts-expect-error intentionally bad code
39
+ (0, _createChainedFunction.createChainedFunction)(12345);
40
+ }).toThrow(Error);
41
+ });
42
+ it('should execute all the functions', () => {
43
+ const spies = Array.from({
44
+ length: 5
45
+ }, () => jest.fn());
46
+ const chain = (0, _createChainedFunction.createChainedFunction)(...spies);
47
+ chain();
48
+ spies.forEach(spy => {
49
+ expect(spy).toHaveBeenCalledTimes(1);
50
+ });
51
+ });
52
+ });
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _generateId = require("../generateId");
5
+ /*
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2015 - present Instructure, Inc.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ */
28
+
29
+ describe('generateId', () => {
30
+ it('should generate unique ids for the same instance', () => {
31
+ const seed = new Map();
32
+ const component = 'TestComponent';
33
+ const inst1 = (0, _generateId.generateId)(component, seed);
34
+ const inst2 = (0, _generateId.generateId)(component, seed);
35
+ expect(inst1).not.toEqual(inst2);
36
+ });
37
+ it('should create ids deterministicly', () => {
38
+ const seed1 = new Map();
39
+ const component = 'TestComponent';
40
+
41
+ // Simulate rendering component: TestComponent
42
+ const render1 = (0, _generateId.generateId)(component, seed1);
43
+
44
+ // Suppose we have a refresh, meaning the instanceCounter will be reseted:
45
+ const seed2 = new Map();
46
+ const render2 = (0, _generateId.generateId)(component, seed2);
47
+ expect(render1).toEqual(render2);
48
+ });
49
+ it('should not create the same id for the same instance.', () => {
50
+ const counter = new Map();
51
+ const seed = new Map();
52
+ const component = 'TestComponent';
53
+ for (let i = 0; i <= 20000; i++) {
54
+ const id = (0, _generateId.generateId)(component, seed);
55
+ if (!counter.has(id)) {
56
+ counter.set(id, false);
57
+ } else {
58
+ counter.set(id, true);
59
+ }
60
+ expect(counter.get(id)).toBe(false);
61
+ }
62
+ });
63
+ });