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