@instructure/ui-text-input 10.19.2-snapshot-3 → 10.19.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.
- package/CHANGELOG.md +1 -1
- package/package.json +16 -16
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/TextInput/__new-tests__/TextInput.test.js +0 -193
- package/lib/TextInput/__new-tests__/TextInput.test.js +0 -195
- package/src/TextInput/__new-tests__/TextInput.test.tsx +0 -186
- package/types/TextInput/__new-tests__/TextInput.test.d.ts +0 -2
- package/types/TextInput/__new-tests__/TextInput.test.d.ts.map +0 -1
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
var _TextInput, _TextInput2, _TextInput3, _TextInput4, _TextInput5, _TextInput6, _TextInput7;
|
|
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 { render, screen, waitFor, fireEvent } from '@testing-library/react';
|
|
27
|
-
import userEvent from '@testing-library/user-event';
|
|
28
|
-
import { vi } from 'vitest';
|
|
29
|
-
import '@testing-library/jest-dom';
|
|
30
|
-
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
31
|
-
import { TextInput } from '../index';
|
|
32
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
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 = _jsx(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(_jsx(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(_jsx(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(_jsx(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 let aria-describedby through', async () => {
|
|
89
|
-
render(_TextInput2 || (_TextInput2 = _jsx(TextInput, {
|
|
90
|
-
renderLabel: "Name",
|
|
91
|
-
"aria-describedby": "abcd"
|
|
92
|
-
})));
|
|
93
|
-
const input = screen.getByRole('textbox');
|
|
94
|
-
expect(input).toHaveAttribute('aria-describedby', 'abcd');
|
|
95
|
-
});
|
|
96
|
-
describe('events', () => {
|
|
97
|
-
it('responds to onChange event', async () => {
|
|
98
|
-
const onChange = vi.fn();
|
|
99
|
-
render(_jsx(TextInput, {
|
|
100
|
-
renderLabel: "Name",
|
|
101
|
-
onChange: onChange
|
|
102
|
-
}));
|
|
103
|
-
const input = screen.getByRole('textbox');
|
|
104
|
-
fireEvent.change(input, {
|
|
105
|
-
target: {
|
|
106
|
-
value: 'foo'
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
await waitFor(() => {
|
|
110
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
it('responds to onBlur event', async () => {
|
|
114
|
-
const onBlur = vi.fn();
|
|
115
|
-
render(_jsx(TextInput, {
|
|
116
|
-
renderLabel: "Name",
|
|
117
|
-
onBlur: onBlur
|
|
118
|
-
}));
|
|
119
|
-
userEvent.tab();
|
|
120
|
-
userEvent.tab();
|
|
121
|
-
await waitFor(() => {
|
|
122
|
-
expect(onBlur).toHaveBeenCalled();
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
it('responds to onFocus event', async () => {
|
|
126
|
-
const onFocus = vi.fn();
|
|
127
|
-
render(_jsx(TextInput, {
|
|
128
|
-
renderLabel: "Name",
|
|
129
|
-
onFocus: onFocus
|
|
130
|
-
}));
|
|
131
|
-
const input = screen.getByRole('textbox');
|
|
132
|
-
input.focus();
|
|
133
|
-
await waitFor(() => {
|
|
134
|
-
expect(onFocus).toHaveBeenCalled();
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
describe('interaction', () => {
|
|
139
|
-
it('should set the disabled attribute when `interaction` is disabled', async () => {
|
|
140
|
-
render(_TextInput3 || (_TextInput3 = _jsx(TextInput, {
|
|
141
|
-
renderLabel: "Name",
|
|
142
|
-
interaction: "disabled"
|
|
143
|
-
})));
|
|
144
|
-
const input = screen.getByRole('textbox');
|
|
145
|
-
expect(input).toHaveAttribute('disabled');
|
|
146
|
-
});
|
|
147
|
-
it('should set the disabled attribute when `disabled` is set', async () => {
|
|
148
|
-
render(_TextInput4 || (_TextInput4 = _jsx(TextInput, {
|
|
149
|
-
renderLabel: "Name",
|
|
150
|
-
disabled: true
|
|
151
|
-
})));
|
|
152
|
-
const input = screen.getByRole('textbox');
|
|
153
|
-
expect(input).toHaveAttribute('disabled');
|
|
154
|
-
});
|
|
155
|
-
it('should set the readonly attribute when `interaction` is readonly', async () => {
|
|
156
|
-
render(_TextInput5 || (_TextInput5 = _jsx(TextInput, {
|
|
157
|
-
renderLabel: "Name",
|
|
158
|
-
interaction: "readonly"
|
|
159
|
-
})));
|
|
160
|
-
const input = screen.getByRole('textbox');
|
|
161
|
-
expect(input).toHaveAttribute('readonly');
|
|
162
|
-
});
|
|
163
|
-
it('should set the readonly attribute when `readOnly` is set', async () => {
|
|
164
|
-
render(_TextInput6 || (_TextInput6 = _jsx(TextInput, {
|
|
165
|
-
renderLabel: "Name",
|
|
166
|
-
readOnly: true
|
|
167
|
-
})));
|
|
168
|
-
const input = screen.getByRole('textbox');
|
|
169
|
-
expect(input).toHaveAttribute('readonly');
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
describe('for a11y', () => {
|
|
173
|
-
it('should meet standards', async () => {
|
|
174
|
-
const _render2 = render(_TextInput7 || (_TextInput7 = _jsx(TextInput, {
|
|
175
|
-
renderLabel: "Name"
|
|
176
|
-
}))),
|
|
177
|
-
container = _render2.container;
|
|
178
|
-
const axeCheck = await runAxeCheck(container);
|
|
179
|
-
expect(axeCheck).toBe(true);
|
|
180
|
-
});
|
|
181
|
-
it('should set aria-invalid when errors prop is set', async () => {
|
|
182
|
-
render(_jsx(TextInput, {
|
|
183
|
-
renderLabel: "Name",
|
|
184
|
-
messages: [{
|
|
185
|
-
type: 'error',
|
|
186
|
-
text: 'some error message'
|
|
187
|
-
}]
|
|
188
|
-
}));
|
|
189
|
-
const input = screen.getByRole('textbox');
|
|
190
|
-
expect(input).toHaveAttribute('aria-invalid');
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react = require("@testing-library/react");
|
|
5
|
-
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
6
|
-
var _vitest = require("vitest");
|
|
7
|
-
require("@testing-library/jest-dom");
|
|
8
|
-
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
9
|
-
var _index = require("../index");
|
|
10
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
|
-
var _TextInput, _TextInput2, _TextInput3, _TextInput4, _TextInput5, _TextInput6, _TextInput7;
|
|
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, _react.render)(_TextInput || (_TextInput = (0, _jsxRuntime.jsx)(_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, _react.render)((0, _jsxRuntime.jsx)(_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 = _react.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, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
70
|
-
renderLabel: "Name",
|
|
71
|
-
inputRef: inputRef
|
|
72
|
-
}));
|
|
73
|
-
const input = _react.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, _react.render)((0, _jsxRuntime.jsx)(_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 let aria-describedby through', async () => {
|
|
91
|
-
(0, _react.render)(_TextInput2 || (_TextInput2 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
92
|
-
renderLabel: "Name",
|
|
93
|
-
"aria-describedby": "abcd"
|
|
94
|
-
})));
|
|
95
|
-
const input = _react.screen.getByRole('textbox');
|
|
96
|
-
expect(input).toHaveAttribute('aria-describedby', 'abcd');
|
|
97
|
-
});
|
|
98
|
-
describe('events', () => {
|
|
99
|
-
it('responds to onChange event', async () => {
|
|
100
|
-
const onChange = _vitest.vi.fn();
|
|
101
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
102
|
-
renderLabel: "Name",
|
|
103
|
-
onChange: onChange
|
|
104
|
-
}));
|
|
105
|
-
const input = _react.screen.getByRole('textbox');
|
|
106
|
-
_react.fireEvent.change(input, {
|
|
107
|
-
target: {
|
|
108
|
-
value: 'foo'
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
await (0, _react.waitFor)(() => {
|
|
112
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it('responds to onBlur event', async () => {
|
|
116
|
-
const onBlur = _vitest.vi.fn();
|
|
117
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
118
|
-
renderLabel: "Name",
|
|
119
|
-
onBlur: onBlur
|
|
120
|
-
}));
|
|
121
|
-
_userEvent.default.tab();
|
|
122
|
-
_userEvent.default.tab();
|
|
123
|
-
await (0, _react.waitFor)(() => {
|
|
124
|
-
expect(onBlur).toHaveBeenCalled();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
it('responds to onFocus event', async () => {
|
|
128
|
-
const onFocus = _vitest.vi.fn();
|
|
129
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
130
|
-
renderLabel: "Name",
|
|
131
|
-
onFocus: onFocus
|
|
132
|
-
}));
|
|
133
|
-
const input = _react.screen.getByRole('textbox');
|
|
134
|
-
input.focus();
|
|
135
|
-
await (0, _react.waitFor)(() => {
|
|
136
|
-
expect(onFocus).toHaveBeenCalled();
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
describe('interaction', () => {
|
|
141
|
-
it('should set the disabled attribute when `interaction` is disabled', async () => {
|
|
142
|
-
(0, _react.render)(_TextInput3 || (_TextInput3 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
143
|
-
renderLabel: "Name",
|
|
144
|
-
interaction: "disabled"
|
|
145
|
-
})));
|
|
146
|
-
const input = _react.screen.getByRole('textbox');
|
|
147
|
-
expect(input).toHaveAttribute('disabled');
|
|
148
|
-
});
|
|
149
|
-
it('should set the disabled attribute when `disabled` is set', async () => {
|
|
150
|
-
(0, _react.render)(_TextInput4 || (_TextInput4 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
151
|
-
renderLabel: "Name",
|
|
152
|
-
disabled: true
|
|
153
|
-
})));
|
|
154
|
-
const input = _react.screen.getByRole('textbox');
|
|
155
|
-
expect(input).toHaveAttribute('disabled');
|
|
156
|
-
});
|
|
157
|
-
it('should set the readonly attribute when `interaction` is readonly', async () => {
|
|
158
|
-
(0, _react.render)(_TextInput5 || (_TextInput5 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
159
|
-
renderLabel: "Name",
|
|
160
|
-
interaction: "readonly"
|
|
161
|
-
})));
|
|
162
|
-
const input = _react.screen.getByRole('textbox');
|
|
163
|
-
expect(input).toHaveAttribute('readonly');
|
|
164
|
-
});
|
|
165
|
-
it('should set the readonly attribute when `readOnly` is set', async () => {
|
|
166
|
-
(0, _react.render)(_TextInput6 || (_TextInput6 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
167
|
-
renderLabel: "Name",
|
|
168
|
-
readOnly: true
|
|
169
|
-
})));
|
|
170
|
-
const input = _react.screen.getByRole('textbox');
|
|
171
|
-
expect(input).toHaveAttribute('readonly');
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
describe('for a11y', () => {
|
|
175
|
-
it('should meet standards', async () => {
|
|
176
|
-
const _render2 = (0, _react.render)(_TextInput7 || (_TextInput7 = (0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
177
|
-
renderLabel: "Name"
|
|
178
|
-
}))),
|
|
179
|
-
container = _render2.container;
|
|
180
|
-
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
181
|
-
expect(axeCheck).toBe(true);
|
|
182
|
-
});
|
|
183
|
-
it('should set aria-invalid when errors prop is set', async () => {
|
|
184
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextInput, {
|
|
185
|
-
renderLabel: "Name",
|
|
186
|
-
messages: [{
|
|
187
|
-
type: 'error',
|
|
188
|
-
text: 'some error message'
|
|
189
|
-
}]
|
|
190
|
-
}));
|
|
191
|
-
const input = _react.screen.getByRole('textbox');
|
|
192
|
-
expect(input).toHaveAttribute('aria-invalid');
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
@@ -1,186 +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 { render, screen, waitFor, fireEvent } from '@testing-library/react'
|
|
26
|
-
import userEvent from '@testing-library/user-event'
|
|
27
|
-
import { vi } from 'vitest'
|
|
28
|
-
import '@testing-library/jest-dom'
|
|
29
|
-
|
|
30
|
-
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
31
|
-
import { TextInput } from '../index'
|
|
32
|
-
|
|
33
|
-
describe('<TextInput/>', () => {
|
|
34
|
-
let consoleErrorMock: any
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
38
|
-
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
afterEach(() => {
|
|
42
|
-
consoleErrorMock.mockRestore()
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('should include a label', async () => {
|
|
46
|
-
const { container } = render(<TextInput renderLabel="Name" />)
|
|
47
|
-
const label = container.querySelector('label')
|
|
48
|
-
expect(label).toHaveTextContent('Name')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('should focus the input when focus is called', async () => {
|
|
52
|
-
let ref: TextInput | undefined
|
|
53
|
-
render(
|
|
54
|
-
<TextInput
|
|
55
|
-
renderLabel="Name"
|
|
56
|
-
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
57
|
-
inputRef={(el: TextInput) => {
|
|
58
|
-
ref = el
|
|
59
|
-
}}
|
|
60
|
-
/>
|
|
61
|
-
)
|
|
62
|
-
const input = screen.getByRole('textbox')
|
|
63
|
-
|
|
64
|
-
ref?.focus()
|
|
65
|
-
|
|
66
|
-
expect(input).toHaveFocus()
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('should provide an inputRef prop', async () => {
|
|
70
|
-
const inputRef = vi.fn()
|
|
71
|
-
render(<TextInput renderLabel="Name" inputRef={inputRef} />)
|
|
72
|
-
const input = screen.getByRole('textbox')
|
|
73
|
-
|
|
74
|
-
expect(inputRef).toHaveBeenCalledWith(input)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('should provide a value getter', async () => {
|
|
78
|
-
let ref: TextInput | undefined
|
|
79
|
-
render(
|
|
80
|
-
<TextInput
|
|
81
|
-
renderLabel="Name"
|
|
82
|
-
defaultValue="bar"
|
|
83
|
-
//@ts-expect-error TODO this is coming from ReactComponentWrapper
|
|
84
|
-
inputRef={(el: TextInput) => {
|
|
85
|
-
ref = el
|
|
86
|
-
}}
|
|
87
|
-
/>
|
|
88
|
-
)
|
|
89
|
-
expect(ref?.value).toBe('bar')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('should let aria-describedby through', async () => {
|
|
93
|
-
render(<TextInput renderLabel="Name" aria-describedby="abcd" />)
|
|
94
|
-
const input = screen.getByRole('textbox')
|
|
95
|
-
|
|
96
|
-
expect(input).toHaveAttribute('aria-describedby', 'abcd')
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
describe('events', () => {
|
|
100
|
-
it('responds to onChange event', async () => {
|
|
101
|
-
const onChange = vi.fn()
|
|
102
|
-
render(<TextInput renderLabel="Name" onChange={onChange} />)
|
|
103
|
-
const input = screen.getByRole('textbox')
|
|
104
|
-
fireEvent.change(input, { target: { value: 'foo' } })
|
|
105
|
-
|
|
106
|
-
await waitFor(() => {
|
|
107
|
-
expect(onChange).toHaveBeenCalledTimes(1)
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('responds to onBlur event', async () => {
|
|
112
|
-
const onBlur = vi.fn()
|
|
113
|
-
render(<TextInput renderLabel="Name" onBlur={onBlur} />)
|
|
114
|
-
|
|
115
|
-
userEvent.tab()
|
|
116
|
-
userEvent.tab()
|
|
117
|
-
|
|
118
|
-
await waitFor(() => {
|
|
119
|
-
expect(onBlur).toHaveBeenCalled()
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('responds to onFocus event', async () => {
|
|
124
|
-
const onFocus = vi.fn()
|
|
125
|
-
render(<TextInput renderLabel="Name" onFocus={onFocus} />)
|
|
126
|
-
const input = screen.getByRole('textbox')
|
|
127
|
-
|
|
128
|
-
input.focus()
|
|
129
|
-
|
|
130
|
-
await waitFor(() => {
|
|
131
|
-
expect(onFocus).toHaveBeenCalled()
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
describe('interaction', () => {
|
|
137
|
-
it('should set the disabled attribute when `interaction` is disabled', async () => {
|
|
138
|
-
render(<TextInput renderLabel="Name" interaction="disabled" />)
|
|
139
|
-
const input = screen.getByRole('textbox')
|
|
140
|
-
|
|
141
|
-
expect(input).toHaveAttribute('disabled')
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('should set the disabled attribute when `disabled` is set', async () => {
|
|
145
|
-
render(<TextInput renderLabel="Name" disabled />)
|
|
146
|
-
const input = screen.getByRole('textbox')
|
|
147
|
-
|
|
148
|
-
expect(input).toHaveAttribute('disabled')
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('should set the readonly attribute when `interaction` is readonly', async () => {
|
|
152
|
-
render(<TextInput renderLabel="Name" interaction="readonly" />)
|
|
153
|
-
const input = screen.getByRole('textbox')
|
|
154
|
-
|
|
155
|
-
expect(input).toHaveAttribute('readonly')
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
it('should set the readonly attribute when `readOnly` is set', async () => {
|
|
159
|
-
render(<TextInput renderLabel="Name" readOnly />)
|
|
160
|
-
const input = screen.getByRole('textbox')
|
|
161
|
-
|
|
162
|
-
expect(input).toHaveAttribute('readonly')
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
describe('for a11y', () => {
|
|
167
|
-
it('should meet standards', async () => {
|
|
168
|
-
const { container } = render(<TextInput renderLabel="Name" />)
|
|
169
|
-
const axeCheck = await runAxeCheck(container)
|
|
170
|
-
|
|
171
|
-
expect(axeCheck).toBe(true)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('should set aria-invalid when errors prop is set', async () => {
|
|
175
|
-
render(
|
|
176
|
-
<TextInput
|
|
177
|
-
renderLabel="Name"
|
|
178
|
-
messages={[{ type: 'error', text: 'some error message' }]}
|
|
179
|
-
/>
|
|
180
|
-
)
|
|
181
|
-
const input = screen.getByRole('textbox')
|
|
182
|
-
|
|
183
|
-
expect(input).toHaveAttribute('aria-invalid')
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.test.d.ts","sourceRoot":"","sources":["../../../src/TextInput/__new-tests__/TextInput.test.tsx"],"names":[],"mappings":"AA2BA,OAAO,2BAA2B,CAAA"}
|