@instructure/ui-text-input 10.0.1-snapshot-6 → 10.0.1-snapshot-8

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.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [10.0.1-snapshot-6](https://github.com/instructure/instructure-ui/compare/v10.0.0...v10.0.1-snapshot-6) (2024-08-09)
6
+ ## [10.0.1-snapshot-8](https://github.com/instructure/instructure-ui/compare/v10.0.0...v10.0.1-snapshot-8) (2024-08-13)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-text-input
9
9
 
@@ -0,0 +1,221 @@
1
+ var _TextInput, _TextInput2, _TextInput3, _TextInput4, _TextInput5, _TextInput6;
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 React from 'react';
27
+ import { render, screen, waitFor, fireEvent } from '@testing-library/react';
28
+ import userEvent from '@testing-library/user-event';
29
+ import { vi } from 'vitest';
30
+ import '@testing-library/jest-dom';
31
+ import { runAxeCheck } from '@instructure/ui-axe-check';
32
+ import { TextInput } from '../index';
33
+ describe('<TextInput/>', () => {
34
+ let consoleErrorMock;
35
+ beforeEach(() => {
36
+ // Mocking console to prevent test output pollution and expect for messages
37
+ consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
38
+ });
39
+ afterEach(() => {
40
+ consoleErrorMock.mockRestore();
41
+ });
42
+ it('should include a label', async () => {
43
+ const _render = render(_TextInput || (_TextInput = /*#__PURE__*/React.createElement(TextInput, {
44
+ renderLabel: "Name"
45
+ }))),
46
+ container = _render.container;
47
+ const label = container.querySelector('label');
48
+ expect(label).toHaveTextContent('Name');
49
+ });
50
+ it('should focus the input when focus is called', async () => {
51
+ var _ref;
52
+ let ref;
53
+ render( /*#__PURE__*/React.createElement(TextInput, {
54
+ renderLabel: "Name"
55
+ //@ts-expect-error TODO this is coming from ReactComponentWrapper
56
+ ,
57
+ inputRef: el => {
58
+ ref = el;
59
+ }
60
+ }));
61
+ const input = screen.getByRole('textbox');
62
+ (_ref = ref) === null || _ref === void 0 ? void 0 : _ref.focus();
63
+ expect(input).toHaveFocus();
64
+ });
65
+ it('should provide an inputRef prop', async () => {
66
+ const inputRef = vi.fn();
67
+ render( /*#__PURE__*/React.createElement(TextInput, {
68
+ renderLabel: "Name",
69
+ inputRef: inputRef
70
+ }));
71
+ const input = screen.getByRole('textbox');
72
+ expect(inputRef).toHaveBeenCalledWith(input);
73
+ });
74
+ it('should provide a value getter', async () => {
75
+ var _ref2;
76
+ let ref;
77
+ render( /*#__PURE__*/React.createElement(TextInput, {
78
+ renderLabel: "Name",
79
+ defaultValue: "bar"
80
+ //@ts-expect-error TODO this is coming from ReactComponentWrapper
81
+ ,
82
+ inputRef: el => {
83
+ ref = el;
84
+ }
85
+ }));
86
+ expect((_ref2 = ref) === null || _ref2 === void 0 ? void 0 : _ref2.value).toBe('bar');
87
+ });
88
+ it('should provide messageId to FormField', async () => {
89
+ render( /*#__PURE__*/React.createElement(TextInput, {
90
+ renderLabel: "Name",
91
+ messages: [{
92
+ text: 'yup',
93
+ type: 'error'
94
+ }]
95
+ }));
96
+ const input = screen.getByRole('textbox');
97
+ expect(input).toHaveAttribute('aria-describedby');
98
+ });
99
+ it('should have equal messagesId and aria-describedby values', async () => {
100
+ const _render2 = render( /*#__PURE__*/React.createElement(TextInput, {
101
+ renderLabel: "Name",
102
+ messages: [{
103
+ text: 'yup',
104
+ type: 'error'
105
+ }]
106
+ })),
107
+ container = _render2.container;
108
+ const id = screen.getByRole('textbox').getAttribute('aria-describedby');
109
+ const messages = container.querySelector('span[class$="-formFieldMessages"]');
110
+ expect(messages).toHaveAttribute('id', id);
111
+ });
112
+ it('should handle multiple aria-describedby ids', async () => {
113
+ render( /*#__PURE__*/React.createElement(TextInput, {
114
+ renderLabel: "Name",
115
+ "aria-describedby": "assistive-id",
116
+ messages: [{
117
+ text: 'yup',
118
+ type: 'error'
119
+ }]
120
+ }));
121
+ const ids = screen.getByRole('textbox').getAttribute('aria-describedby');
122
+ expect(ids).toMatch('assistive-id TextInput-messages');
123
+ });
124
+ describe('events', () => {
125
+ it('responds to onChange event', async () => {
126
+ const onChange = vi.fn();
127
+ render( /*#__PURE__*/React.createElement(TextInput, {
128
+ renderLabel: "Name",
129
+ onChange: onChange
130
+ }));
131
+ const input = screen.getByRole('textbox');
132
+ fireEvent.change(input, {
133
+ target: {
134
+ value: 'foo'
135
+ }
136
+ });
137
+ await waitFor(() => {
138
+ expect(onChange).toHaveBeenCalledTimes(1);
139
+ });
140
+ });
141
+ it('responds to onBlur event', async () => {
142
+ const onBlur = vi.fn();
143
+ render( /*#__PURE__*/React.createElement(TextInput, {
144
+ renderLabel: "Name",
145
+ onBlur: onBlur
146
+ }));
147
+ userEvent.tab();
148
+ userEvent.tab();
149
+ await waitFor(() => {
150
+ expect(onBlur).toHaveBeenCalled();
151
+ });
152
+ });
153
+ it('responds to onFocus event', async () => {
154
+ const onFocus = vi.fn();
155
+ render( /*#__PURE__*/React.createElement(TextInput, {
156
+ renderLabel: "Name",
157
+ onFocus: onFocus
158
+ }));
159
+ const input = screen.getByRole('textbox');
160
+ input.focus();
161
+ await waitFor(() => {
162
+ expect(onFocus).toHaveBeenCalled();
163
+ });
164
+ });
165
+ });
166
+ describe('interaction', () => {
167
+ it('should set the disabled attribute when `interaction` is disabled', async () => {
168
+ render(_TextInput2 || (_TextInput2 = /*#__PURE__*/React.createElement(TextInput, {
169
+ renderLabel: "Name",
170
+ interaction: "disabled"
171
+ })));
172
+ const input = screen.getByRole('textbox');
173
+ expect(input).toHaveAttribute('disabled');
174
+ });
175
+ it('should set the disabled attribute when `disabled` is set', async () => {
176
+ render(_TextInput3 || (_TextInput3 = /*#__PURE__*/React.createElement(TextInput, {
177
+ renderLabel: "Name",
178
+ disabled: true
179
+ })));
180
+ const input = screen.getByRole('textbox');
181
+ expect(input).toHaveAttribute('disabled');
182
+ });
183
+ it('should set the readonly attribute when `interaction` is readonly', async () => {
184
+ render(_TextInput4 || (_TextInput4 = /*#__PURE__*/React.createElement(TextInput, {
185
+ renderLabel: "Name",
186
+ interaction: "readonly"
187
+ })));
188
+ const input = screen.getByRole('textbox');
189
+ expect(input).toHaveAttribute('readonly');
190
+ });
191
+ it('should set the readonly attribute when `readOnly` is set', async () => {
192
+ render(_TextInput5 || (_TextInput5 = /*#__PURE__*/React.createElement(TextInput, {
193
+ renderLabel: "Name",
194
+ readOnly: true
195
+ })));
196
+ const input = screen.getByRole('textbox');
197
+ expect(input).toHaveAttribute('readonly');
198
+ });
199
+ });
200
+ describe('for a11y', () => {
201
+ it('should meet standards', async () => {
202
+ const _render3 = render(_TextInput6 || (_TextInput6 = /*#__PURE__*/React.createElement(TextInput, {
203
+ renderLabel: "Name"
204
+ }))),
205
+ container = _render3.container;
206
+ const axeCheck = await runAxeCheck(container);
207
+ expect(axeCheck).toBe(true);
208
+ });
209
+ it('should set aria-invalid when errors prop is set', async () => {
210
+ render( /*#__PURE__*/React.createElement(TextInput, {
211
+ renderLabel: "Name",
212
+ messages: [{
213
+ type: 'error',
214
+ text: 'some error message'
215
+ }]
216
+ }));
217
+ const input = screen.getByRole('textbox');
218
+ expect(input).toHaveAttribute('aria-invalid');
219
+ });
220
+ });
221
+ });
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _react2 = require("@testing-library/react");
6
+ var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
7
+ var _vitest = require("vitest");
8
+ require("@testing-library/jest-dom");
9
+ var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
10
+ var _index = require("../index");
11
+ var _TextInput, _TextInput2, _TextInput3, _TextInput4, _TextInput5, _TextInput6;
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('<TextInput/>', () => {
36
+ let consoleErrorMock;
37
+ beforeEach(() => {
38
+ // Mocking console to prevent test output pollution and expect for messages
39
+ consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
40
+ });
41
+ afterEach(() => {
42
+ consoleErrorMock.mockRestore();
43
+ });
44
+ it('should include a label', async () => {
45
+ const _render = (0, _react2.render)(_TextInput || (_TextInput = /*#__PURE__*/_react.default.createElement(_index.TextInput, {
46
+ renderLabel: "Name"
47
+ }))),
48
+ container = _render.container;
49
+ const label = container.querySelector('label');
50
+ expect(label).toHaveTextContent('Name');
51
+ });
52
+ it('should focus the input when focus is called', async () => {
53
+ var _ref;
54
+ let ref;
55
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
56
+ renderLabel: "Name"
57
+ //@ts-expect-error TODO this is coming from ReactComponentWrapper
58
+ ,
59
+ inputRef: el => {
60
+ ref = el;
61
+ }
62
+ }));
63
+ const input = _react2.screen.getByRole('textbox');
64
+ (_ref = ref) === null || _ref === void 0 ? void 0 : _ref.focus();
65
+ expect(input).toHaveFocus();
66
+ });
67
+ it('should provide an inputRef prop', async () => {
68
+ const inputRef = _vitest.vi.fn();
69
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
70
+ renderLabel: "Name",
71
+ inputRef: inputRef
72
+ }));
73
+ const input = _react2.screen.getByRole('textbox');
74
+ expect(inputRef).toHaveBeenCalledWith(input);
75
+ });
76
+ it('should provide a value getter', async () => {
77
+ var _ref2;
78
+ let ref;
79
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
80
+ renderLabel: "Name",
81
+ defaultValue: "bar"
82
+ //@ts-expect-error TODO this is coming from ReactComponentWrapper
83
+ ,
84
+ inputRef: el => {
85
+ ref = el;
86
+ }
87
+ }));
88
+ expect((_ref2 = ref) === null || _ref2 === void 0 ? void 0 : _ref2.value).toBe('bar');
89
+ });
90
+ it('should provide messageId to FormField', async () => {
91
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
92
+ renderLabel: "Name",
93
+ messages: [{
94
+ text: 'yup',
95
+ type: 'error'
96
+ }]
97
+ }));
98
+ const input = _react2.screen.getByRole('textbox');
99
+ expect(input).toHaveAttribute('aria-describedby');
100
+ });
101
+ it('should have equal messagesId and aria-describedby values', async () => {
102
+ const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
103
+ renderLabel: "Name",
104
+ messages: [{
105
+ text: 'yup',
106
+ type: 'error'
107
+ }]
108
+ })),
109
+ container = _render2.container;
110
+ const id = _react2.screen.getByRole('textbox').getAttribute('aria-describedby');
111
+ const messages = container.querySelector('span[class$="-formFieldMessages"]');
112
+ expect(messages).toHaveAttribute('id', id);
113
+ });
114
+ it('should handle multiple aria-describedby ids', async () => {
115
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
116
+ renderLabel: "Name",
117
+ "aria-describedby": "assistive-id",
118
+ messages: [{
119
+ text: 'yup',
120
+ type: 'error'
121
+ }]
122
+ }));
123
+ const ids = _react2.screen.getByRole('textbox').getAttribute('aria-describedby');
124
+ expect(ids).toMatch('assistive-id TextInput-messages');
125
+ });
126
+ describe('events', () => {
127
+ it('responds to onChange event', async () => {
128
+ const onChange = _vitest.vi.fn();
129
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
130
+ renderLabel: "Name",
131
+ onChange: onChange
132
+ }));
133
+ const input = _react2.screen.getByRole('textbox');
134
+ _react2.fireEvent.change(input, {
135
+ target: {
136
+ value: 'foo'
137
+ }
138
+ });
139
+ await (0, _react2.waitFor)(() => {
140
+ expect(onChange).toHaveBeenCalledTimes(1);
141
+ });
142
+ });
143
+ it('responds to onBlur event', async () => {
144
+ const onBlur = _vitest.vi.fn();
145
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
146
+ renderLabel: "Name",
147
+ onBlur: onBlur
148
+ }));
149
+ _userEvent.default.tab();
150
+ _userEvent.default.tab();
151
+ await (0, _react2.waitFor)(() => {
152
+ expect(onBlur).toHaveBeenCalled();
153
+ });
154
+ });
155
+ it('responds to onFocus event', async () => {
156
+ const onFocus = _vitest.vi.fn();
157
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
158
+ renderLabel: "Name",
159
+ onFocus: onFocus
160
+ }));
161
+ const input = _react2.screen.getByRole('textbox');
162
+ input.focus();
163
+ await (0, _react2.waitFor)(() => {
164
+ expect(onFocus).toHaveBeenCalled();
165
+ });
166
+ });
167
+ });
168
+ describe('interaction', () => {
169
+ it('should set the disabled attribute when `interaction` is disabled', async () => {
170
+ (0, _react2.render)(_TextInput2 || (_TextInput2 = /*#__PURE__*/_react.default.createElement(_index.TextInput, {
171
+ renderLabel: "Name",
172
+ interaction: "disabled"
173
+ })));
174
+ const input = _react2.screen.getByRole('textbox');
175
+ expect(input).toHaveAttribute('disabled');
176
+ });
177
+ it('should set the disabled attribute when `disabled` is set', async () => {
178
+ (0, _react2.render)(_TextInput3 || (_TextInput3 = /*#__PURE__*/_react.default.createElement(_index.TextInput, {
179
+ renderLabel: "Name",
180
+ disabled: true
181
+ })));
182
+ const input = _react2.screen.getByRole('textbox');
183
+ expect(input).toHaveAttribute('disabled');
184
+ });
185
+ it('should set the readonly attribute when `interaction` is readonly', async () => {
186
+ (0, _react2.render)(_TextInput4 || (_TextInput4 = /*#__PURE__*/_react.default.createElement(_index.TextInput, {
187
+ renderLabel: "Name",
188
+ interaction: "readonly"
189
+ })));
190
+ const input = _react2.screen.getByRole('textbox');
191
+ expect(input).toHaveAttribute('readonly');
192
+ });
193
+ it('should set the readonly attribute when `readOnly` is set', async () => {
194
+ (0, _react2.render)(_TextInput5 || (_TextInput5 = /*#__PURE__*/_react.default.createElement(_index.TextInput, {
195
+ renderLabel: "Name",
196
+ readOnly: true
197
+ })));
198
+ const input = _react2.screen.getByRole('textbox');
199
+ expect(input).toHaveAttribute('readonly');
200
+ });
201
+ });
202
+ describe('for a11y', () => {
203
+ it('should meet standards', async () => {
204
+ const _render3 = (0, _react2.render)(_TextInput6 || (_TextInput6 = /*#__PURE__*/_react.default.createElement(_index.TextInput, {
205
+ renderLabel: "Name"
206
+ }))),
207
+ container = _render3.container;
208
+ const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
209
+ expect(axeCheck).toBe(true);
210
+ });
211
+ it('should set aria-invalid when errors prop is set', async () => {
212
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TextInput, {
213
+ renderLabel: "Name",
214
+ messages: [{
215
+ type: 'error',
216
+ text: 'some error message'
217
+ }]
218
+ }));
219
+ const input = _react2.screen.getByRole('textbox');
220
+ expect(input).toHaveAttribute('aria-invalid');
221
+ });
222
+ });
223
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-text-input",
3
- "version": "10.0.1-snapshot-6",
3
+ "version": "10.0.1-snapshot-8",
4
4
  "description": "A styled HTML text input component.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,24 +23,28 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "10.0.1-snapshot-6",
27
- "@instructure/ui-badge": "10.0.1-snapshot-6",
28
- "@instructure/ui-color-utils": "10.0.1-snapshot-6",
29
- "@instructure/ui-test-utils": "10.0.1-snapshot-6",
30
- "@instructure/ui-themes": "10.0.1-snapshot-6",
31
- "react-dom": "^18.3.1"
26
+ "@instructure/ui-axe-check": "10.0.1-snapshot-8",
27
+ "@instructure/ui-babel-preset": "10.0.1-snapshot-8",
28
+ "@instructure/ui-badge": "10.0.1-snapshot-8",
29
+ "@instructure/ui-color-utils": "10.0.1-snapshot-8",
30
+ "@instructure/ui-test-utils": "10.0.1-snapshot-8",
31
+ "@instructure/ui-themes": "10.0.1-snapshot-8",
32
+ "@testing-library/jest-dom": "^6.4.6",
33
+ "@testing-library/react": "^15.0.7",
34
+ "@testing-library/user-event": "^14.5.2",
35
+ "vitest": "^2.0.2"
32
36
  },
33
37
  "dependencies": {
34
38
  "@babel/runtime": "^7.24.5",
35
- "@instructure/emotion": "10.0.1-snapshot-6",
36
- "@instructure/shared-types": "10.0.1-snapshot-6",
37
- "@instructure/ui-dom-utils": "10.0.1-snapshot-6",
38
- "@instructure/ui-form-field": "10.0.1-snapshot-6",
39
- "@instructure/ui-icons": "10.0.1-snapshot-6",
40
- "@instructure/ui-prop-types": "10.0.1-snapshot-6",
41
- "@instructure/ui-react-utils": "10.0.1-snapshot-6",
42
- "@instructure/ui-tag": "10.0.1-snapshot-6",
43
- "@instructure/ui-testable": "10.0.1-snapshot-6",
39
+ "@instructure/emotion": "10.0.1-snapshot-8",
40
+ "@instructure/shared-types": "10.0.1-snapshot-8",
41
+ "@instructure/ui-dom-utils": "10.0.1-snapshot-8",
42
+ "@instructure/ui-form-field": "10.0.1-snapshot-8",
43
+ "@instructure/ui-icons": "10.0.1-snapshot-8",
44
+ "@instructure/ui-prop-types": "10.0.1-snapshot-8",
45
+ "@instructure/ui-react-utils": "10.0.1-snapshot-8",
46
+ "@instructure/ui-tag": "10.0.1-snapshot-8",
47
+ "@instructure/ui-testable": "10.0.1-snapshot-8",
44
48
  "prop-types": "^15.8.1"
45
49
  },
46
50
  "peerDependencies": {