@instructure/emotion 10.20.2-snapshot-2 → 10.20.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 (44) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +15 -12
  3. package/tsconfig.build.json +0 -3
  4. package/tsconfig.build.tsbuildinfo +1 -1
  5. package/es/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +0 -84
  6. package/es/__old-tests__/getComponentThemeOverride.test.js +0 -128
  7. package/es/__old-tests__/useStyle.test.js +0 -226
  8. package/es/__old-tests__/useTheme.test.js +0 -484
  9. package/es/__old-tests__/withStyle.test.js +0 -327
  10. package/es/styleUtils/__old-tests__/getShorthandPropValue.test.js +0 -85
  11. package/es/styleUtils/__old-tests__/makeThemeVars.test.js +0 -45
  12. package/es/styleUtils/__old-tests__/mirrorShorthand.test.js +0 -66
  13. package/lib/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +0 -86
  14. package/lib/__old-tests__/getComponentThemeOverride.test.js +0 -131
  15. package/lib/__old-tests__/useStyle.test.js +0 -228
  16. package/lib/__old-tests__/useTheme.test.js +0 -488
  17. package/lib/__old-tests__/withStyle.test.js +0 -329
  18. package/lib/styleUtils/__old-tests__/getShorthandPropValue.test.js +0 -87
  19. package/lib/styleUtils/__old-tests__/makeThemeVars.test.js +0 -47
  20. package/lib/styleUtils/__old-tests__/mirrorShorthand.test.js +0 -68
  21. package/src/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.tsx +0 -82
  22. package/src/__old-tests__/getComponentThemeOverride.test.ts +0 -182
  23. package/src/__old-tests__/useStyle.test.tsx +0 -272
  24. package/src/__old-tests__/useTheme.test.tsx +0 -510
  25. package/src/__old-tests__/withStyle.test.tsx +0 -389
  26. package/src/styleUtils/__old-tests__/getShorthandPropValue.test.ts +0 -96
  27. package/src/styleUtils/__old-tests__/makeThemeVars.test.ts +0 -48
  28. package/src/styleUtils/__old-tests__/mirrorShorthand.test.ts +0 -77
  29. package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts +0 -2
  30. package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts.map +0 -1
  31. package/types/__old-tests__/getComponentThemeOverride.test.d.ts +0 -2
  32. package/types/__old-tests__/getComponentThemeOverride.test.d.ts.map +0 -1
  33. package/types/__old-tests__/useStyle.test.d.ts +0 -2
  34. package/types/__old-tests__/useStyle.test.d.ts.map +0 -1
  35. package/types/__old-tests__/useTheme.test.d.ts +0 -2
  36. package/types/__old-tests__/useTheme.test.d.ts.map +0 -1
  37. package/types/__old-tests__/withStyle.test.d.ts +0 -2
  38. package/types/__old-tests__/withStyle.test.d.ts.map +0 -1
  39. package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts +0 -2
  40. package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts.map +0 -1
  41. package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts +0 -2
  42. package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts.map +0 -1
  43. package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts +0 -2
  44. package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts.map +0 -1
@@ -1,327 +0,0 @@
1
- var _p;
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 { Component } from 'react';
27
- import ReactDOM from 'react-dom';
28
- import ReactTestUtils from 'react-dom/test-utils';
29
- import PropTypes from 'prop-types';
30
- import { expect, match, mount, stub, within } from '@instructure/ui-test-utils';
31
- import { withStyle, InstUISettingsProvider } from '../index';
32
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
33
- describe('@withStyle', async () => {
34
- var _dec, _class, _ThemeableComponent, _div, _WrapperComponent2, _InstUISettingsProvid, _InstUISettingsProvid2, _InstUISettingsProvid3, _InstUISettingsProvid4, _InstUISettingsProvid5;
35
- const grey1111 = 'rgb(0, 128, 0)';
36
- const green4570 = 'rgb(10, 10, 10)';
37
- const blue4570 = 'rgb(255, 255, 0)';
38
- const exampleTheme = {
39
- key: 'exampleTheme',
40
- colors: {
41
- contrasts: {
42
- grey1111,
43
- green4570,
44
- blue4570
45
- }
46
- }
47
- };
48
- const generateComponentTheme = function (theme) {
49
- const colors = theme.colors;
50
- return {
51
- textColor: colors.contrasts.grey1111,
52
- textColorInverse: colors.contrasts.green4570,
53
- backgroundColor: colors.contrasts.blue4570
54
- };
55
- };
56
- const generateStyle = function (componentTheme, props, state) {
57
- const inverse = props.inverse;
58
- const clearBackground = state.clearBackground;
59
- return {
60
- exampleComponent: {
61
- label: 'exampleComponent',
62
- color: componentTheme.textColor,
63
- background: componentTheme.backgroundColor,
64
- insetInlineStart: '8px',
65
- ...(inverse && {
66
- color: componentTheme.textColorInverse
67
- }),
68
- ...(clearBackground && {
69
- background: 'transparent'
70
- })
71
- }
72
- };
73
- };
74
- let ThemeableComponent = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_ThemeableComponent = class ThemeableComponent extends Component {
75
- constructor(...args) {
76
- super(...args);
77
- this.state = {
78
- clearBackground: false
79
- };
80
- this.handleClick = () => {
81
- this.setState({
82
- clearBackground: true
83
- });
84
- };
85
- }
86
- componentDidMount() {
87
- this.props.makeStyles({
88
- clearBackground: this.state.clearBackground
89
- });
90
- }
91
- componentDidUpdate() {
92
- this.props.makeStyles({
93
- clearBackground: this.state.clearBackground
94
- });
95
- }
96
- render() {
97
- const styles = this.props.styles;
98
- return _jsxs("div", {
99
- css: styles.exampleComponent,
100
- children: [_p || (_p = _jsx("p", {
101
- children: "Hello World"
102
- })), _jsx("button", {
103
- onClick: this.handleClick,
104
- children: "Button"
105
- })]
106
- });
107
- }
108
- }, _ThemeableComponent.displayName = "ThemeableComponent", _ThemeableComponent.propTypes = {
109
- inverse: PropTypes.bool
110
- }, _ThemeableComponent.defaultTypes = {
111
- inverse: false
112
- }, _ThemeableComponent)) || _class);
113
- class WrapperComponent extends Component {
114
- render() {
115
- return _div || (_div = _jsx("div", {
116
- children: _jsx(ThemeableComponent, {})
117
- }));
118
- }
119
- }
120
- WrapperComponent.displayName = "WrapperComponent";
121
- it('can be found and tested with ReactTestUtils', async () => {
122
- const rootNode = document.createElement('div');
123
- document.body.appendChild(rootNode);
124
-
125
- // eslint-disable-next-line react/no-render-return-value
126
- const rendered = ReactDOM.render(_WrapperComponent2 || (_WrapperComponent2 = _jsx(WrapperComponent, {})), rootNode);
127
- ReactTestUtils.findRenderedComponentWithType(rendered, ThemeableComponent.originalType);
128
- });
129
- describe('with theme provided by InstUISettingsProvider', async () => {
130
- it('should add css class suffixed with label', async () => {
131
- const subject = await mount(_InstUISettingsProvid || (_InstUISettingsProvid = _jsx(InstUISettingsProvider, {
132
- theme: exampleTheme,
133
- children: _jsx(ThemeableComponent, {})
134
- })));
135
- const emotionClassRegex = new RegExp(/^css-.+-exampleComponent$/);
136
- expect(subject.getDOMNode().classList[0]).to.match(emotionClassRegex);
137
- });
138
- it('should apply correct css props', async () => {
139
- const subject = await mount(_InstUISettingsProvid2 || (_InstUISettingsProvid2 = _jsx(InstUISettingsProvider, {
140
- theme: exampleTheme,
141
- children: _jsx(ThemeableComponent, {})
142
- })));
143
- const component = subject.getDOMNode();
144
- const computedStyle = getComputedStyle(component);
145
- expect(computedStyle.color).to.equal('rgb(0, 128, 0)');
146
- expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
147
- });
148
- describe('should allow configuration through the themeOverride prop', async () => {
149
- it('when it is an object', async () => {
150
- const subject = await mount(_jsx(InstUISettingsProvider, {
151
- theme: exampleTheme,
152
- children: _jsx(ThemeableComponent, {
153
- themeOverride: {
154
- textColor: 'rgb(128, 0, 128)'
155
- }
156
- })
157
- }));
158
- const component = subject.getDOMNode();
159
- const computedStyle = getComputedStyle(component);
160
- expect(computedStyle.color).to.equal('rgb(128, 0, 128)');
161
- expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
162
- });
163
- it('when it is a function', async () => {
164
- const subject = await mount(_jsx(InstUISettingsProvider, {
165
- theme: exampleTheme,
166
- children: _jsx(ThemeableComponent, {
167
- themeOverride: componentTheme => ({
168
- textColor: componentTheme.backgroundColor
169
- })
170
- })
171
- }));
172
- const component = subject.getDOMNode();
173
- const computedStyle = getComputedStyle(component);
174
- expect(computedStyle.color).to.equal('rgb(255, 255, 0)');
175
- expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
176
- });
177
- });
178
- it('should ignore empty themeOverride props', async () => {
179
- const subject = await mount(_jsx(InstUISettingsProvider, {
180
- theme: exampleTheme,
181
- children: _jsx(ThemeableComponent, {
182
- themeOverride: {}
183
- })
184
- }));
185
- const component = subject.getDOMNode();
186
- const computedStyle = getComputedStyle(component);
187
- expect(computedStyle.color).to.equal('rgb(0, 128, 0)');
188
- expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
189
- });
190
- });
191
- describe('should update css props', async () => {
192
- it('when props are updated', async () => {
193
- // `setProps` can be called on the outer component,
194
- // so have to add the theme ad themeOverride here, and suppress the error
195
- stub(console, 'warn'); // suppress "no theme provided error"
196
-
197
- const subject = await mount(_jsx(ThemeableComponent, {
198
- inverse: false,
199
- themeOverride: {
200
- textColor: grey1111,
201
- textColorInverse: blue4570,
202
- backgroundColor: green4570
203
- }
204
- }));
205
- const component = subject.getDOMNode();
206
- expect(getComputedStyle(component).color).to.equal(grey1111);
207
- await subject.setProps({
208
- inverse: true
209
- });
210
- expect(getComputedStyle(component).color).to.equal(blue4570);
211
- });
212
- it('when state is updated', async () => {
213
- const subject = await mount(_InstUISettingsProvid3 || (_InstUISettingsProvid3 = _jsx(InstUISettingsProvider, {
214
- theme: exampleTheme,
215
- children: _jsx(ThemeableComponent, {})
216
- })));
217
- const main = within(subject.getDOMNode());
218
- const clearBackgroundButton = await main.find('button');
219
- const component = main.getDOMNode();
220
- expect(getComputedStyle(component).backgroundColor).to.equal('rgb(255, 255, 0)');
221
- await clearBackgroundButton.click();
222
- expect(getComputedStyle(component).backgroundColor).to.equal('rgba(0, 0, 0, 0)');
223
- });
224
- });
225
- describe('should apply bi-directional polyfill on styles object', async () => {
226
- it('in default "ltr" mode', async () => {
227
- const subject = await mount(_InstUISettingsProvid4 || (_InstUISettingsProvid4 = _jsx(InstUISettingsProvider, {
228
- theme: exampleTheme,
229
- children: _jsx(ThemeableComponent, {})
230
- })));
231
- const component = subject.getDOMNode();
232
- const computedStyle = getComputedStyle(component);
233
-
234
- // `inset-inline-start` should be transformed to 'left' in 'ltr' mode
235
- expect(computedStyle.left).to.equal('8px');
236
- expect(computedStyle.right).to.equal('auto');
237
- });
238
- it('in "rtl" mode', async () => {
239
- const subject = await mount(_InstUISettingsProvid5 || (_InstUISettingsProvid5 = _jsx(InstUISettingsProvider, {
240
- theme: exampleTheme,
241
- dir: "rtl",
242
- children: _jsx(ThemeableComponent, {})
243
- })));
244
- const component = subject.getDOMNode().firstElementChild;
245
- const computedStyle = getComputedStyle(component);
246
-
247
- // `inset-inline-start` should be transformed to 'right' in 'rtl' mode
248
- expect(computedStyle.left).to.equal('auto');
249
- expect(computedStyle.right).to.equal('8px');
250
- });
251
- });
252
- describe('should not allow manually passing prop', async () => {
253
- it('styles', async () => {
254
- stub(console, 'warn'); // suppress warning
255
-
256
- const subject = await mount(_jsx(InstUISettingsProvider, {
257
- theme: exampleTheme,
258
- children: _jsx(ThemeableComponent, {
259
- styles: {
260
- exampleComponent: {
261
- color: 'red'
262
- }
263
- }
264
- })
265
- }));
266
- const component = subject.getDOMNode();
267
- const computedStyle = getComputedStyle(component);
268
- expect(computedStyle.color).to.equal(grey1111);
269
- });
270
- it('makeStyles', async () => {
271
- stub(console, 'warn'); // suppress warning
272
- const consoleLog = stub(console, 'log');
273
- const subject = await mount(_jsx(InstUISettingsProvider, {
274
- theme: exampleTheme,
275
- children: _jsx(ThemeableComponent, {
276
- makeStyles: () => {
277
- // eslint-disable-next-line no-console
278
-
279
- return {
280
- exampleComponent: {
281
- color: 'red'
282
- }
283
- };
284
- }
285
- })
286
- }));
287
- const component = subject.getDOMNode();
288
- const computedStyle = getComputedStyle(component);
289
- expect(computedStyle.color).to.equal(grey1111);
290
- expect(consoleLog).not.to.have.been.called();
291
- });
292
- });
293
- describe('should throw warning when manually passing prop', async () => {
294
- it('styles', async () => {
295
- const consoleWarning = stub(console, 'warn');
296
- await mount(_jsx(InstUISettingsProvider, {
297
- theme: exampleTheme,
298
- children: _jsx(ThemeableComponent, {
299
- styles: {
300
- exampleComponent: {
301
- color: 'red'
302
- }
303
- }
304
- })
305
- }));
306
- expect(consoleWarning).to.have.been.calledWithMatch(`Warning: Manually passing the "styles" property is not allowed on the ThemeableComponent component. Using the default styles calculated by the @withStyle decorator instead.`, match.object, match.string);
307
- });
308
- it('makeStyles', async () => {
309
- const consoleWarning = stub(console, 'warn');
310
- await mount(_jsx(InstUISettingsProvider, {
311
- theme: exampleTheme,
312
- children: _jsx(ThemeableComponent, {
313
- makeStyles: () => {
314
- // eslint-disable-next-line no-console
315
-
316
- return {
317
- exampleComponent: {
318
- color: 'red'
319
- }
320
- };
321
- }
322
- })
323
- }));
324
- expect(consoleWarning).to.have.been.calledWithMatch(`Manually passing the "makeStyles" property is not allowed on the ThemeableComponent component. Styles are calculated by the @withStyle decorator.`, match.string);
325
- });
326
- });
327
- });
@@ -1,85 +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 { expect } from '@instructure/ui-test-utils';
26
- import { getShorthandPropValue } from '../getShorthandPropValue';
27
- const theme = {
28
- small: '0rem',
29
- borderXSmall: '0.1rem',
30
- borderMedium: '0.2rem',
31
- borderLarge: '0.3rem',
32
- borderXLarge: '0.4rem',
33
- marginXSmall: '1.1rem',
34
- marginMedium: '1.2rem',
35
- marginLarge: '1.3rem',
36
- marginXLarge: '1.4rem',
37
- paddingXSmall: '2.1rem',
38
- paddingMedium: '2.2rem',
39
- paddingLarge: '2.3rem',
40
- paddingXLarge: '2.4rem'
41
- };
42
- const name = 'TestComponent';
43
- describe('getShorthandPropValue', () => {
44
- it('converts 1 value syntax', () => {
45
- const value = 'x-small';
46
- const borderResult = getShorthandPropValue(name, theme, value, 'border');
47
- const marginResult = getShorthandPropValue(name, theme, value, 'margin');
48
- const paddingResult = getShorthandPropValue(name, theme, value, 'padding');
49
- expect(borderResult).to.equal('0.1rem');
50
- expect(marginResult).to.equal('1.1rem');
51
- expect(paddingResult).to.equal('2.1rem');
52
- });
53
- it('converts 2 value syntax', () => {
54
- const values = 'large x-large';
55
- const borderResult = getShorthandPropValue(name, theme, values, 'border');
56
- const marginResult = getShorthandPropValue(name, theme, values, 'margin');
57
- const paddingResult = getShorthandPropValue(name, theme, values, 'padding');
58
- expect(borderResult).to.equal('0.3rem 0.4rem');
59
- expect(marginResult).to.equal('1.3rem 1.4rem');
60
- expect(paddingResult).to.equal('2.3rem 2.4rem');
61
- });
62
- it('converts 3 value syntax', () => {
63
- const values = 'medium x-small x-large';
64
- const borderResult = getShorthandPropValue(name, theme, values, 'border');
65
- const marginResult = getShorthandPropValue(name, theme, values, 'margin');
66
- const paddingResult = getShorthandPropValue(name, theme, values, 'padding');
67
- expect(borderResult).to.equal('0.2rem 0.1rem 0.4rem');
68
- expect(marginResult).to.equal('1.2rem 1.1rem 1.4rem');
69
- expect(paddingResult).to.equal('2.2rem 2.1rem 2.4rem');
70
- });
71
- it('converts 4 value syntax', () => {
72
- const values = 'x-large medium x-small large';
73
- const borderResult = getShorthandPropValue(name, theme, values, 'border');
74
- const marginResult = getShorthandPropValue(name, theme, values, 'margin');
75
- const paddingResult = getShorthandPropValue(name, theme, values, 'padding');
76
- expect(borderResult).to.equal('0.4rem 0.2rem 0.1rem 0.3rem');
77
- expect(marginResult).to.equal('1.4rem 1.2rem 1.1rem 1.3rem');
78
- expect(paddingResult).to.equal('2.4rem 2.2rem 2.1rem 2.3rem');
79
- });
80
- it('returns 0 for none or 0, and returns auto if auto is supplied', () => {
81
- const values = '0 none auto large';
82
- const result = getShorthandPropValue(name, theme, values, 'border');
83
- expect(result).to.equal('0 0 auto 0.3rem');
84
- });
85
- });
@@ -1,45 +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 { expect } from '@instructure/ui-test-utils';
26
- import { makeThemeVars } from '../makeThemeVars';
27
- describe('makeThemeVars', () => {
28
- it('given a list of variables, should append a prefix and camel case each key', () => {
29
- const vars = {
30
- xSmall: 'foo',
31
- medium: 'bar',
32
- xxLarge: 'baz'
33
- };
34
- const result = makeThemeVars('margin', vars);
35
- // @ts-expect-error we expect it to throw error
36
- expect(result['xSmall']).to.not.exist();
37
- // @ts-expect-error we expect it to throw error
38
- expect(result['medium']).to.not.exist();
39
- // @ts-expect-error we expect it to throw error
40
- expect(result['xxLarge']).to.not.exist();
41
- expect(result['marginXSmall']).to.equal('foo');
42
- expect(result['marginMedium']).to.equal('bar');
43
- expect(result['marginXxLarge']).to.equal('baz');
44
- });
45
- });
@@ -1,66 +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 { expect } from '@instructure/ui-test-utils';
26
- import { mirrorShorthandCorners, mirrorShorthandEdges } from '../mirrorShorthand';
27
- describe('convertRtlShorthandEdges', () => {
28
- it('should not modify 1 value syntax', () => {
29
- const value = 'x-small';
30
- const result = mirrorShorthandEdges(value);
31
- expect(result).to.equal(value);
32
- });
33
- it('should not modify 2 value syntax', () => {
34
- const value = 'x-small xx-large';
35
- const result = mirrorShorthandEdges(value);
36
- expect(result).to.equal(value);
37
- });
38
- it('should not modify 3 value syntax', () => {
39
- const value = 'x-small medium x-large';
40
- const result = mirrorShorthandEdges(value);
41
- expect(result).to.equal(value);
42
- });
43
- it('should swap the second and fourth values with 4 value syntax', () => {
44
- const result = mirrorShorthandEdges('auto x-small none x-large');
45
- expect(result).to.equal('auto x-large none x-small');
46
- });
47
- });
48
- describe('convertRtlShorthandCorners', () => {
49
- it('should not modify 1 value syntax', () => {
50
- const value = 'x-small';
51
- const result = mirrorShorthandCorners(value);
52
- expect(result).to.equal(value);
53
- });
54
- it('should swap the first and second values with 2 value syntax', () => {
55
- const result = mirrorShorthandCorners('x-small xx-large');
56
- expect(result).to.equal('xx-large x-small');
57
- });
58
- it('should convert 3 value syntax to 4 value syntax and switch the values appropriately', () => {
59
- const result = mirrorShorthandCorners('x-small medium x-large');
60
- expect(result).to.equal('medium x-small medium x-large');
61
- });
62
- it('should appropriately switch shorthand values to rtl with 4 value syntax', () => {
63
- const result = mirrorShorthandCorners('auto x-small none x-large');
64
- expect(result).to.equal('x-small auto x-large none');
65
- });
66
- });
@@ -1,86 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _react = require("react");
5
- var _uiTestUtils = require("@instructure/ui-test-utils");
6
- var _uiThemes = _interopRequireDefault(require("@instructure/ui-themes"));
7
- var _index = require("../index");
8
- var _textDirectionContextConsumer = require("@instructure/ui-i18n/lib/textDirectionContextConsumer.js");
9
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
- var _dec, _class, _TextDirAwareComponent, _InstUISettingsProvid, _InstUISettingsProvid2, _InstUISettingsProvid3;
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
- let TextDirAwareComponent = (_dec = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec(_class = (_TextDirAwareComponent = class TextDirAwareComponent extends _react.Component {
35
- render() {
36
- return (0, _jsxRuntime.jsx)("div", {
37
- "data-dir": this.props.dir,
38
- children: "hello world"
39
- });
40
- }
41
- }, _TextDirAwareComponent.displayName = "TextDirAwareComponent", _TextDirAwareComponent)) || _class);
42
- describe('InstUISettingsProvider', async () => {
43
- it('can handle nested text direction setting changes', async () => {
44
- const subject = await (0, _uiTestUtils.mount)(_InstUISettingsProvid || (_InstUISettingsProvid = (0, _jsxRuntime.jsx)(_index.InstUISettingsProvider, {
45
- theme: _uiThemes.default,
46
- dir: "rtl",
47
- children: (0, _jsxRuntime.jsx)(_index.InstUISettingsProvider, {
48
- children: (0, _jsxRuntime.jsx)(TextDirAwareComponent, {})
49
- })
50
- })));
51
- let element = subject.getDOMNode().firstElementChild;
52
- (0, _uiTestUtils.expect)(element.getAttribute('data-dir')).to.equal('rtl');
53
- await subject.setProps({
54
- dir: 'ltr'
55
- });
56
- element = subject.getDOMNode().firstElementChild;
57
- (0, _uiTestUtils.expect)(element.getAttribute('data-dir')).to.equal('ltr');
58
- });
59
- it('can handle text direction on native HTML elements', async () => {
60
- const subject = await (0, _uiTestUtils.mount)(_InstUISettingsProvid2 || (_InstUISettingsProvid2 = (0, _jsxRuntime.jsx)(_index.InstUISettingsProvider, {
61
- dir: "rtl",
62
- children: (0, _jsxRuntime.jsx)("div", {
63
- children: "Should be RTL"
64
- })
65
- })));
66
- let element = subject.getDOMNode();
67
- (0, _uiTestUtils.expect)(element.getAttribute('dir')).to.equal('rtl');
68
- await subject.setProps({
69
- dir: 'ltr'
70
- });
71
- element = subject.getDOMNode();
72
- (0, _uiTestUtils.expect)(element.getAttribute('dir')).to.equal('ltr');
73
- });
74
- it('warns when "as" property is used without using the "dir" property', async () => {
75
- const consoleWarning = (0, _uiTestUtils.spy)(console, 'warn');
76
- const warningMessage = "The 'as' property should be used in conjunction with the 'dir' property!";
77
- await (0, _uiTestUtils.mount)(//@ts-expect-error div is required
78
- _InstUISettingsProvid3 || (_InstUISettingsProvid3 = (0, _jsxRuntime.jsx)(_index.InstUISettingsProvider, {
79
- as: "div",
80
- children: (0, _jsxRuntime.jsx)("div", {
81
- children: "text"
82
- })
83
- })));
84
- (0, _uiTestUtils.expect)(consoleWarning).to.has.been.calledWith(warningMessage);
85
- });
86
- });