@instructure/ui-i18n 10.16.1 → 10.16.3

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 (29) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/es/ApplyLocale/__new-tests__/ApplyLocale.test.js +62 -0
  3. package/es/__new-tests__/DateTime.test.js +154 -0
  4. package/es/__new-tests__/I18nPropTypes.test.js +53 -0
  5. package/es/__new-tests__/Locale.test.js +52 -0
  6. package/es/__new-tests__/textDirectionContextConsumer.test.js +108 -0
  7. package/lib/ApplyLocale/__new-tests__/ApplyLocale.test.js +64 -0
  8. package/lib/__new-tests__/DateTime.test.js +157 -0
  9. package/lib/__new-tests__/I18nPropTypes.test.js +56 -0
  10. package/lib/__new-tests__/Locale.test.js +54 -0
  11. package/lib/__new-tests__/textDirectionContextConsumer.test.js +110 -0
  12. package/package.json +12 -10
  13. package/src/ApplyLocale/__new-tests__/ApplyLocale.test.tsx +63 -0
  14. package/src/__new-tests__/DateTime.test.tsx +224 -0
  15. package/src/__new-tests__/I18nPropTypes.test.tsx +119 -0
  16. package/src/__new-tests__/Locale.test.tsx +55 -0
  17. package/src/__new-tests__/textDirectionContextConsumer.test.tsx +125 -0
  18. package/tsconfig.build.json +1 -2
  19. package/tsconfig.build.tsbuildinfo +1 -1
  20. package/types/ApplyLocale/__new-tests__/ApplyLocale.test.d.ts +2 -0
  21. package/types/ApplyLocale/__new-tests__/ApplyLocale.test.d.ts.map +1 -0
  22. package/types/__new-tests__/DateTime.test.d.ts +2 -0
  23. package/types/__new-tests__/DateTime.test.d.ts.map +1 -0
  24. package/types/__new-tests__/I18nPropTypes.test.d.ts +2 -0
  25. package/types/__new-tests__/I18nPropTypes.test.d.ts.map +1 -0
  26. package/types/__new-tests__/Locale.test.d.ts +2 -0
  27. package/types/__new-tests__/Locale.test.d.ts.map +1 -0
  28. package/types/__new-tests__/textDirectionContextConsumer.test.d.ts +2 -0
  29. package/types/__new-tests__/textDirectionContextConsumer.test.d.ts.map +1 -0
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _vitest = require("vitest");
5
+ var _DateTime = require("../DateTime");
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
+ const now = _DateTime.DateTime.now,
31
+ isValid = _DateTime.DateTime.isValid,
32
+ browserTimeZone = _DateTime.DateTime.browserTimeZone,
33
+ parse = _DateTime.DateTime.parse,
34
+ toLocaleString = _DateTime.DateTime.toLocaleString,
35
+ getFirstDayOfWeek = _DateTime.DateTime.getFirstDayOfWeek,
36
+ getLocalDayNamesOfTheWeek = _DateTime.DateTime.getLocalDayNamesOfTheWeek;
37
+ describe('DateTime', () => {
38
+ const timezone = 'America/Halifax'; // -3
39
+ const locale = 'en';
40
+ it('checks params', () => {
41
+ let whoops = false;
42
+ try {
43
+ // @ts-expect-error intentionally wrong
44
+ now();
45
+ } catch (ex) {
46
+ whoops = true;
47
+ } finally {
48
+ (0, _vitest.expect)(whoops).toBe(true);
49
+ }
50
+ whoops = false;
51
+ try {
52
+ // @ts-expect-error intentionally wrong
53
+ now(locale);
54
+ } catch (ex) {
55
+ whoops = true;
56
+ } finally {
57
+ (0, _vitest.expect)(whoops).toBe(true);
58
+ }
59
+ });
60
+ it('knows when now is', () => {
61
+ // not much of a test, but I need it for coverage stats
62
+ const result = now(locale, timezone);
63
+ (0, _vitest.expect)(result).toBeDefined();
64
+ });
65
+ it("can figure out the browser's timezone", () => {
66
+ const result = browserTimeZone();
67
+ (0, _vitest.expect)(result).toBeDefined();
68
+ });
69
+ it('validates', () => {
70
+ (0, _vitest.expect)(isValid('2018-04-15T23:30:00Z')).toBe(true);
71
+ (0, _vitest.expect)(isValid('2018-04-15T23:30')).toBe(true);
72
+ (0, _vitest.expect)(isValid('2018-04-15')).toBe(true);
73
+ });
74
+ it('parses iso8601', () => {
75
+ const result = parse('2018-04-15T20:30:00-03:00', locale, timezone).toISOString();
76
+ (0, _vitest.expect)(result).toEqual('2018-04-15T23:30:00.000Z');
77
+ });
78
+ it('parses llll', () => {
79
+ const result = parse('Sun, Apr 15, 2018 8:30 PM', locale, timezone).toISOString();
80
+ (0, _vitest.expect)(result).toEqual('2018-04-15T23:30:00.000Z');
81
+ });
82
+ it('parses LLLL', () => {
83
+ const result = parse('Sunday, April 15, 2018 8:30 PM', locale, timezone).toISOString();
84
+ (0, _vitest.expect)(result).toEqual('2018-04-15T23:30:00.000Z');
85
+ });
86
+ it('parses lll', () => {
87
+ const result = parse('Apr 15, 2018 8:30 PM', locale, timezone).toISOString();
88
+ (0, _vitest.expect)(result).toEqual('2018-04-15T23:30:00.000Z');
89
+ });
90
+ it('parses LLL', () => {
91
+ const result = parse('April 15, 2018 8:30 PM', locale, timezone).toISOString();
92
+ (0, _vitest.expect)(result).toEqual('2018-04-15T23:30:00.000Z');
93
+ });
94
+ it('parses ll', () => {
95
+ const result = parse('Apr 15, 2018', locale, timezone).toISOString();
96
+ (0, _vitest.expect)(result).toEqual('2018-04-15T03:00:00.000Z');
97
+ });
98
+ it('parses LL', () => {
99
+ const result = parse('April 15, 2018', locale, timezone).toISOString();
100
+ (0, _vitest.expect)(result).toEqual('2018-04-15T03:00:00.000Z');
101
+ });
102
+ it('parses l', () => {
103
+ const result = parse('4/15/2018', locale, timezone).toISOString();
104
+ (0, _vitest.expect)(result).toEqual('2018-04-15T03:00:00.000Z');
105
+ });
106
+ it('parses L', () => {
107
+ const result = parse('04/15/2018', locale, timezone).toISOString();
108
+ (0, _vitest.expect)(result).toEqual('2018-04-15T03:00:00.000Z');
109
+ });
110
+ it('parses French L', () => {
111
+ const result = parse('15/04/2018', 'fr', timezone).toISOString();
112
+ (0, _vitest.expect)(result).toEqual('2018-04-15T03:00:00.000Z');
113
+ });
114
+ it('parses French LL', () => {
115
+ const result = parse('15 Avril, 2018', 'fr', timezone).toISOString();
116
+ (0, _vitest.expect)(result).toEqual('2018-04-15T03:00:00.000Z');
117
+ });
118
+ it('returns localized string', () => {
119
+ let result = toLocaleString('2018-04-15T13:00Z', 'en', 'UTC', 'LLL');
120
+ (0, _vitest.expect)(result).toEqual('April 15, 2018 1:00 PM');
121
+ result = toLocaleString('2018-04-15T13:00Z', 'fr', 'UTC', 'LLL');
122
+ (0, _vitest.expect)(result).toEqual('15 avril 2018 13:00');
123
+ // iso8601 in given timezone
124
+ result = toLocaleString('2018-04-15T13:00Z', 'fr', 'America/Halifax'); // -3
125
+ (0, _vitest.expect)(result).toEqual('2018-04-15T10:00:00.000-03:00');
126
+ });
127
+ it('calculates the first day of the week', () => {
128
+ // normal case
129
+ const d11 = _DateTime.DateTime.parse('2021-09-15T20:30:00Z', 'hu-hu', 'UTC');
130
+ (0, _vitest.expect)(getFirstDayOfWeek(d11).date()).toEqual(13);
131
+ const d12 = _DateTime.DateTime.parse('2021-09-15T20:30:00Z', 'en-us', 'UTC');
132
+ (0, _vitest.expect)(getFirstDayOfWeek(d12).date()).toEqual(12);
133
+ // date wraps month/year
134
+ const d21 = _DateTime.DateTime.parse('2022-01-01T20:30:00Z', 'hu-hu', 'UTC');
135
+ (0, _vitest.expect)(getFirstDayOfWeek(d21).date()).toEqual(27);
136
+ const d22 = _DateTime.DateTime.parse('2022-01-01T20:30:00Z', 'en-us', 'UTC');
137
+ (0, _vitest.expect)(getFirstDayOfWeek(d22).date()).toEqual(26);
138
+
139
+ // Monday
140
+ const d31 = _DateTime.DateTime.parse('2021-12-05T20:30:00Z', 'hu-hu', 'UTC');
141
+ (0, _vitest.expect)(getFirstDayOfWeek(d31).date()).toEqual(29);
142
+ // Sunday
143
+ const d32 = _DateTime.DateTime.parse('2021-12-05T20:30:00Z', 'en-us', 'UTC');
144
+ (0, _vitest.expect)(getFirstDayOfWeek(d32).date()).toEqual(5);
145
+ // Sunday (but in other systems Friday)
146
+ const d33 = _DateTime.DateTime.parse('2021-12-05T20:30:00Z', 'bn-bd', 'UTC');
147
+ (0, _vitest.expect)(getFirstDayOfWeek(d33).date()).toEqual(5);
148
+ });
149
+ it('calculates the local day names of the week', () => {
150
+ // short names
151
+ (0, _vitest.expect)(getLocalDayNamesOfTheWeek('hu-hu', 'short')).toEqual(['h', 'k', 'sze', 'cs', 'p', 'szo', 'v']);
152
+ (0, _vitest.expect)(getLocalDayNamesOfTheWeek('en-us', 'short')).toEqual(['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']);
153
+ // long
154
+ (0, _vitest.expect)(getLocalDayNamesOfTheWeek('en-us', 'long')).toEqual(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']);
155
+ (0, _vitest.expect)(getLocalDayNamesOfTheWeek('es-mx', 'long')).toEqual(['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado']);
156
+ });
157
+ });
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _vitest = require("vitest");
5
+ var _I18nPropTypes = require("../I18nPropTypes");
6
+ /*
7
+ * The MIT License (MIT)
8
+ *
9
+ * Copyright (c) 2018 - 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('I18nPropTypes', () => {
31
+ describe('iso8601', () => {
32
+ const iso8601 = _I18nPropTypes.I18nPropTypes.iso8601;
33
+
34
+ // Test cases taken from https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
35
+ it('should not return error when provided with a valid ISO8601 string', () => {
36
+ const props = {
37
+ date: null
38
+ };
39
+ const validISO8601Strings = ['2009-12T12:34', '2009', '2009-05-19', '20090519', '2009123', '2009-05', '2009-123', '2009-222', '2009-001', '2009-W01-1', '2009-W51-1', '2009-W511', '2009-W33', '2009W511', '2009-05-19', '2009-05-19 00:00', '2009-05-19 14', '2009-05-19 14:31', '2009-05-19 14:39:22', '2009-05-19T14:39Z', '2009-W21-2', '2009-W21-2T01:22', '2009-139', '2009-05-19 14:39:22-06:00', '2009-05-19 14:39:22+0600', '2009-05-19 14:39:22-01', '20090621T0545Z', '2007-04-06T00:00', '2007-04-05T24:00', '2010-02-18T16:23:48.5', '2010-02-18T16:23:48,444', '2010-02-18T16:23:48,3-06:00', '2010-02-18T16:23.4', '2010-02-18T16:23,25', '2010-02-18T16:23.33+0600', '2010-02-18T16.23334444', '2010-02-18T16,2283', '2009-05-19 143922.500', '2009-05-19 1439,55'];
40
+ validISO8601Strings.forEach(iso8601string => {
41
+ props.date = iso8601string;
42
+ (0, _vitest.expect)(iso8601(props, 'date', 'TestComponent', '', '')).toBe(null);
43
+ });
44
+ });
45
+ it('should return error when provided with an invalid ISO8601 string', () => {
46
+ const props = {
47
+ date: null
48
+ };
49
+ const invalidISO8601Strings = ['some text', 'June 27, 1990', '200905', '2009367', '2009-', '2007-04-05T24:50', '2009-000', '2009-M511', '2009M511', '2009-05-19T14a39r', '2009-05-19T14:3924', '2009-0519', '2009-05-1914:39', '2009-05-19 14:', '2009-05-19r14:39', '2009-05-19 14a39a22', '200912-01', '2009-05-19 14:39:22+06a00', '2009-05-19 146922.500', '2010-02-18T16.5:23.35:48', '2010-02-18T16:23.35:48', '2010-02-18T16:23.35:48.45', '2009-05-19 14.5.44', '2010-02-18T16:23.33.600', '2010-02-18T16,25:23:48,444'];
50
+ invalidISO8601Strings.forEach(iso8601string => {
51
+ props.date = iso8601string;
52
+ (0, _vitest.expect)(iso8601(props, 'date', 'TestComponent', '', '')).toBeInstanceOf(Error);
53
+ });
54
+ });
55
+ });
56
+ });
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _vitest = require("vitest");
5
+ var _Locale = require("../Locale");
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('browserLocale', () => {
31
+ it('returns the navigator language if a navigator is explicity passed', () => {
32
+ const navigator = {
33
+ language: 'de'
34
+ };
35
+ (0, _vitest.expect)(_Locale.Locale.browserLocale(navigator)).toBe('de');
36
+ });
37
+ describe('with document lang attribute', () => {
38
+ it('returns the document locale if no navigator is passed', () => {
39
+ const original = document.documentElement.lang;
40
+ document.documentElement.lang = 'fr';
41
+ (0, _vitest.expect)(_Locale.Locale.browserLocale()).toBe('fr');
42
+
43
+ // Restore global
44
+ document.documentElement.lang = original;
45
+ });
46
+ });
47
+ it('returns the browser locale if no navigator is passed, or "en-US" if no browser locale is set', () => {
48
+ const expectedLanguage = navigator ? navigator.language : 'en-US';
49
+ (0, _vitest.expect)(_Locale.Locale.browserLocale()).toBe(expectedLanguage);
50
+ });
51
+ it('returns the default "en-US" if navigator is undefined and the DOM is unavailable', () => {
52
+ (0, _vitest.expect)(_Locale.Locale.browserLocale(null, false)).toBe('en-US');
53
+ });
54
+ });
@@ -0,0 +1,110 @@
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 _react2 = require("@testing-library/react");
8
+ require("@testing-library/jest-dom");
9
+ var _vitest = require("vitest");
10
+ var _textDirectionContextConsumer = require("../textDirectionContextConsumer");
11
+ var _TextDirectionContext4 = require("../TextDirectionContext");
12
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
13
+ var _dec, _class, _TextDirectionContextConsumerComponent, _div, _TextDirectionContext, _WrapperComponent2, _TextDirectionContext2, _TextDirectionContext3;
14
+ /*
15
+ * The MIT License (MIT)
16
+ *
17
+ * Copyright (c) 2015 - present Instructure, Inc.
18
+ *
19
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
20
+ * of this software and associated documentation files (the "Software"), to deal
21
+ * in the Software without restriction, including without limitation the rights
22
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
+ * copies of the Software, and to permit persons to whom the Software is
24
+ * furnished to do so, subject to the following conditions:
25
+ *
26
+ * The above copyright notice and this permission notice shall be included in all
27
+ * copies or substantial portions of the Software.
28
+ *
29
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ * SOFTWARE.
36
+ */
37
+ let TextDirectionContextConsumerComponent = (_dec = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec(_class = (_TextDirectionContextConsumerComponent = class TextDirectionContextConsumerComponent extends _react.Component {
38
+ render() {
39
+ return (0, _jsxRuntime.jsx)("div", {
40
+ "data-dir": this.props.dir,
41
+ dir: this.props.dir,
42
+ children: this.props.children
43
+ });
44
+ }
45
+ }, _TextDirectionContextConsumerComponent.displayName = "TextDirectionContextConsumerComponent", _TextDirectionContextConsumerComponent)) || _class);
46
+ class WrapperComponent extends _react.Component {
47
+ render() {
48
+ return _div || (_div = (0, _jsxRuntime.jsx)("div", {
49
+ children: (0, _jsxRuntime.jsx)(TextDirectionContextConsumerComponent, {})
50
+ }));
51
+ }
52
+ }
53
+ WrapperComponent.displayName = "WrapperComponent";
54
+ describe('@textDirectionContextConsumer', () => {
55
+ let consoleErrorMock;
56
+ beforeEach(() => {
57
+ // Mocking console to prevent test output pollution
58
+ consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
59
+ });
60
+ afterEach(() => {
61
+ consoleErrorMock.mockRestore();
62
+ });
63
+ it('should take on the direction of the document by default', async () => {
64
+ const _render = (0, _react2.render)(_TextDirectionContext || (_TextDirectionContext = (0, _jsxRuntime.jsx)(TextDirectionContextConsumerComponent, {}))),
65
+ container = _render.container;
66
+ (0, _vitest.expect)(container.firstChild).toHaveAttribute('data-dir', 'ltr');
67
+ });
68
+ it('can be found and tested with ReactTestUtils', async () => {
69
+ const rootNode = document.createElement('div');
70
+ document.body.appendChild(rootNode);
71
+
72
+ // eslint-disable-next-line react/no-render-return-value
73
+ const rendered = _reactDom.default.render(_WrapperComponent2 || (_WrapperComponent2 = (0, _jsxRuntime.jsx)(WrapperComponent, {})), rootNode);
74
+ const foundComponent = _testUtils.default.findRenderedComponentWithType(rendered, TextDirectionContextConsumerComponent.originalType);
75
+ (0, _vitest.expect)(foundComponent).toBeDefined();
76
+ });
77
+ it('should set the text direction via props', async () => {
78
+ const _render2 = (0, _react2.render)(_TextDirectionContext2 || (_TextDirectionContext2 = (0, _jsxRuntime.jsx)(TextDirectionContextConsumerComponent, {
79
+ dir: "rtl"
80
+ }))),
81
+ container = _render2.container;
82
+ (0, _vitest.expect)(container.firstChild).toHaveAttribute('data-dir', 'rtl');
83
+ });
84
+
85
+ /* TODO re-enable this test when we allow 'auto' text direction
86
+ it('setting "auto" from context figures out text direction from the text', async () => {
87
+ const subject = await mount(
88
+ <TextDirectionContextConsumerComponent dir="auto">
89
+ <span>
90
+ هذه الفقرة باللغة العربية ، لذا يجب الانتقال من اليمين إلى اليسار.
91
+ </span>
92
+ </TextDirectionContextConsumerComponent>
93
+ )
94
+ expect(
95
+ getComputedStyle(subject.getDOMNode().childNodes[0] as Element).direction
96
+ ).to.equal('rtl')
97
+ })
98
+ */
99
+
100
+ it('should give props preference when context and context are present', async () => {
101
+ const _render3 = (0, _react2.render)(_TextDirectionContext3 || (_TextDirectionContext3 = (0, _jsxRuntime.jsx)(_TextDirectionContext4.TextDirectionContext.Provider, {
102
+ value: "ltr",
103
+ children: (0, _jsxRuntime.jsx)(TextDirectionContextConsumerComponent, {
104
+ dir: "rtl"
105
+ })
106
+ }))),
107
+ container = _render3.container;
108
+ (0, _vitest.expect)(container.firstChild).toHaveAttribute('data-dir', 'rtl');
109
+ });
110
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-i18n",
3
- "version": "10.16.1",
3
+ "version": "10.16.3",
4
4
  "description": "Helper components and utilities for internationalization.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,19 +23,21 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "10.16.1",
27
- "@instructure/ui-test-utils": "10.16.1",
26
+ "@instructure/ui-babel-preset": "10.16.3",
27
+ "@testing-library/jest-dom": "^6.6.3",
28
+ "@testing-library/react": "^16.0.1",
28
29
  "@types/hoist-non-react-statics": "^3.3.5",
29
- "react-dom": "^18.3.1"
30
+ "react-dom": "^18.3.1",
31
+ "vitest": "^2.1.8"
30
32
  },
31
33
  "dependencies": {
32
34
  "@babel/runtime": "^7.26.0",
33
- "@instructure/shared-types": "10.16.1",
34
- "@instructure/ui-decorator": "10.16.1",
35
- "@instructure/ui-dom-utils": "10.16.1",
36
- "@instructure/ui-prop-types": "10.16.1",
37
- "@instructure/ui-react-utils": "10.16.1",
38
- "@instructure/ui-utils": "10.16.1",
35
+ "@instructure/shared-types": "10.16.3",
36
+ "@instructure/ui-decorator": "10.16.3",
37
+ "@instructure/ui-dom-utils": "10.16.3",
38
+ "@instructure/ui-prop-types": "10.16.3",
39
+ "@instructure/ui-react-utils": "10.16.3",
40
+ "@instructure/ui-utils": "10.16.3",
39
41
  "hoist-non-react-statics": "^3.3.2",
40
42
  "moment-timezone": "^0.5.45",
41
43
  "prop-types": "^15.8.1"
@@ -0,0 +1,63 @@
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
+ import { Component } from 'react'
25
+ import { render } from '@testing-library/react'
26
+ import '@testing-library/jest-dom'
27
+ import { expect } from 'vitest'
28
+ import { ApplyLocale } from '../index'
29
+ import { ApplyLocaleContext } from '../ApplyLocaleContext'
30
+
31
+ class LocalizableComponent extends Component {
32
+ declare context: React.ContextType<typeof ApplyLocaleContext>
33
+ static contextType = ApplyLocaleContext
34
+
35
+ render() {
36
+ return (
37
+ <div>
38
+ <span>{this.context.locale}</span>
39
+ <span>{this.context.timezone}</span>
40
+ </div>
41
+ )
42
+ }
43
+ }
44
+
45
+ describe('<ApplyLocale />', async () => {
46
+ it('applies locale context', async () => {
47
+ const { container } = render(
48
+ <ApplyLocale locale="fr">
49
+ <LocalizableComponent />
50
+ </ApplyLocale>
51
+ )
52
+ expect(container).toHaveTextContent('fr')
53
+ })
54
+
55
+ it('applies timezone context', async () => {
56
+ const { container } = render(
57
+ <ApplyLocale timezone="Europe/Paris">
58
+ <LocalizableComponent />
59
+ </ApplyLocale>
60
+ )
61
+ expect(container).toHaveTextContent('Europe/Paris')
62
+ })
63
+ })