@instructure/ui-text-area 10.19.2-snapshot-2 → 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/TextArea/__new-tests__/TextArea.test.js +0 -217
- package/lib/TextArea/__new-tests__/TextArea.test.js +0 -219
- package/src/TextArea/__new-tests__/TextArea.test.tsx +0 -213
- package/types/TextArea/__new-tests__/TextArea.test.d.ts +0 -2
- package/types/TextArea/__new-tests__/TextArea.test.d.ts.map +0 -1
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
var _TextArea, _TextArea2, _TextArea3, _TextArea4;
|
|
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 { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
27
|
-
import { vi } from 'vitest';
|
|
28
|
-
import userEvent from '@testing-library/user-event';
|
|
29
|
-
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
30
|
-
import '@testing-library/jest-dom';
|
|
31
|
-
import { TextArea } from '../index';
|
|
32
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
33
|
-
describe('TextArea', () => {
|
|
34
|
-
let consoleWarningMock;
|
|
35
|
-
let consoleErrorMock;
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
38
|
-
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
39
|
-
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
40
|
-
});
|
|
41
|
-
afterEach(() => {
|
|
42
|
-
consoleWarningMock.mockRestore();
|
|
43
|
-
consoleErrorMock.mockRestore();
|
|
44
|
-
});
|
|
45
|
-
it('should accept a default value', async () => {
|
|
46
|
-
render(_TextArea || (_TextArea = _jsx(TextArea, {
|
|
47
|
-
label: "Name",
|
|
48
|
-
autoGrow: false,
|
|
49
|
-
defaultValue: "Tom Servo"
|
|
50
|
-
})));
|
|
51
|
-
const input = screen.getByRole('textbox');
|
|
52
|
-
expect(input).toHaveTextContent('Tom Servo');
|
|
53
|
-
});
|
|
54
|
-
it('should include a label', async () => {
|
|
55
|
-
const _render = render(_TextArea2 || (_TextArea2 = _jsx(TextArea, {
|
|
56
|
-
label: "Name",
|
|
57
|
-
autoGrow: false
|
|
58
|
-
}))),
|
|
59
|
-
container = _render.container;
|
|
60
|
-
const textArea = container.querySelector('span[class$="-formFieldLayout__label"]');
|
|
61
|
-
expect(textArea).toHaveTextContent('Name');
|
|
62
|
-
});
|
|
63
|
-
it('should set an initial height', async () => {
|
|
64
|
-
render(_TextArea3 || (_TextArea3 = _jsx(TextArea, {
|
|
65
|
-
label: "Name",
|
|
66
|
-
autoGrow: false,
|
|
67
|
-
height: "100px"
|
|
68
|
-
})));
|
|
69
|
-
const input = screen.getByRole('textbox');
|
|
70
|
-
expect(input).toHaveStyle('height: 100px');
|
|
71
|
-
});
|
|
72
|
-
it('should focus the textarea when focus is called', async () => {
|
|
73
|
-
let ref;
|
|
74
|
-
render(_jsx(TextArea, {
|
|
75
|
-
label: "Name",
|
|
76
|
-
autoGrow: false
|
|
77
|
-
// @ts-expect-error this is managed by the testing framework
|
|
78
|
-
,
|
|
79
|
-
textareaRef: el => ref = el
|
|
80
|
-
}));
|
|
81
|
-
const input = screen.getByRole('textbox');
|
|
82
|
-
ref.focus();
|
|
83
|
-
expect(input).toHaveFocus();
|
|
84
|
-
});
|
|
85
|
-
it('provides a focused getter', async () => {
|
|
86
|
-
let ref;
|
|
87
|
-
render(_jsx(TextArea, {
|
|
88
|
-
label: "Name",
|
|
89
|
-
autoGrow: false,
|
|
90
|
-
ref: el => ref = el
|
|
91
|
-
}));
|
|
92
|
-
ref.focus();
|
|
93
|
-
expect(ref.focused).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
it('should provide an textareaRef prop', async () => {
|
|
96
|
-
const textareaRef = vi.fn();
|
|
97
|
-
render(_jsx(TextArea, {
|
|
98
|
-
label: "Name",
|
|
99
|
-
autoGrow: false,
|
|
100
|
-
textareaRef: textareaRef
|
|
101
|
-
}));
|
|
102
|
-
const input = screen.getByRole('textbox');
|
|
103
|
-
expect(textareaRef).toHaveBeenCalledWith(input);
|
|
104
|
-
});
|
|
105
|
-
it('should provide a value getter', async () => {
|
|
106
|
-
let ref;
|
|
107
|
-
render(_jsx(TextArea, {
|
|
108
|
-
label: "Name",
|
|
109
|
-
autoGrow: false,
|
|
110
|
-
defaultValue: "bar"
|
|
111
|
-
// @ts-expect-error this is managed by the testing framework
|
|
112
|
-
,
|
|
113
|
-
textareaRef: el => ref = el
|
|
114
|
-
}));
|
|
115
|
-
expect(ref.value).toBe('bar');
|
|
116
|
-
});
|
|
117
|
-
describe('events', () => {
|
|
118
|
-
it('responds to onChange event', async () => {
|
|
119
|
-
const onChange = vi.fn();
|
|
120
|
-
render(_jsx(TextArea, {
|
|
121
|
-
label: "Name",
|
|
122
|
-
autoGrow: false,
|
|
123
|
-
onChange: onChange
|
|
124
|
-
}));
|
|
125
|
-
const input = screen.getByRole('textbox');
|
|
126
|
-
fireEvent.change(input, {
|
|
127
|
-
target: {
|
|
128
|
-
value: 'foo'
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
await waitFor(() => {
|
|
132
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
it('does not respond to onChange event when disabled', async () => {
|
|
136
|
-
const onChange = vi.fn();
|
|
137
|
-
render(_jsx(TextArea, {
|
|
138
|
-
disabled: true,
|
|
139
|
-
label: "Name",
|
|
140
|
-
autoGrow: false,
|
|
141
|
-
onChange: onChange
|
|
142
|
-
}));
|
|
143
|
-
const input = screen.getByRole('textbox');
|
|
144
|
-
fireEvent.change(input, {
|
|
145
|
-
target: {
|
|
146
|
-
value: 'foo'
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
150
|
-
});
|
|
151
|
-
it('does not respond to onChange event when readOnly', async () => {
|
|
152
|
-
const onChange = vi.fn();
|
|
153
|
-
render(_jsx(TextArea, {
|
|
154
|
-
readOnly: true,
|
|
155
|
-
label: "Name",
|
|
156
|
-
autoGrow: false,
|
|
157
|
-
onChange: onChange
|
|
158
|
-
}));
|
|
159
|
-
const input = screen.getByRole('textbox');
|
|
160
|
-
fireEvent.change(input, {
|
|
161
|
-
target: {
|
|
162
|
-
value: 'foo'
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
166
|
-
});
|
|
167
|
-
it('responds to onBlur event', async () => {
|
|
168
|
-
const onBlur = vi.fn();
|
|
169
|
-
render(_jsx(TextArea, {
|
|
170
|
-
label: "Name",
|
|
171
|
-
autoGrow: false,
|
|
172
|
-
onBlur: onBlur
|
|
173
|
-
}));
|
|
174
|
-
userEvent.tab();
|
|
175
|
-
userEvent.tab();
|
|
176
|
-
await waitFor(() => {
|
|
177
|
-
expect(onBlur).toHaveBeenCalled();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
it('responds to onFocus event', async () => {
|
|
181
|
-
const onFocus = vi.fn();
|
|
182
|
-
render(_jsx(TextArea, {
|
|
183
|
-
label: "Name",
|
|
184
|
-
autoGrow: false,
|
|
185
|
-
onFocus: onFocus
|
|
186
|
-
}));
|
|
187
|
-
const input = screen.getByRole('textbox');
|
|
188
|
-
input.focus();
|
|
189
|
-
await waitFor(() => {
|
|
190
|
-
expect(onFocus).toHaveBeenCalled();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
describe('for a11y', () => {
|
|
195
|
-
it('should meet standards', async () => {
|
|
196
|
-
const _render2 = render(_TextArea4 || (_TextArea4 = _jsx(TextArea, {
|
|
197
|
-
label: "Name",
|
|
198
|
-
autoGrow: false
|
|
199
|
-
}))),
|
|
200
|
-
container = _render2.container;
|
|
201
|
-
const axeCheck = await runAxeCheck(container);
|
|
202
|
-
expect(axeCheck).toBe(true);
|
|
203
|
-
});
|
|
204
|
-
it('should set aria-invalid when errors prop is set', async () => {
|
|
205
|
-
render(_jsx(TextArea, {
|
|
206
|
-
label: "Name",
|
|
207
|
-
autoGrow: false,
|
|
208
|
-
messages: [{
|
|
209
|
-
type: 'error',
|
|
210
|
-
text: 'some error message'
|
|
211
|
-
}]
|
|
212
|
-
}));
|
|
213
|
-
const input = screen.getByRole('textbox');
|
|
214
|
-
expect(input).toHaveAttribute('aria-invalid');
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react = require("@testing-library/react");
|
|
5
|
-
var _vitest = require("vitest");
|
|
6
|
-
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
|
-
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
8
|
-
require("@testing-library/jest-dom");
|
|
9
|
-
var _index = require("../index");
|
|
10
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
|
-
var _TextArea, _TextArea2, _TextArea3, _TextArea4;
|
|
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('TextArea', () => {
|
|
36
|
-
let consoleWarningMock;
|
|
37
|
-
let consoleErrorMock;
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
40
|
-
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
41
|
-
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
42
|
-
});
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
consoleWarningMock.mockRestore();
|
|
45
|
-
consoleErrorMock.mockRestore();
|
|
46
|
-
});
|
|
47
|
-
it('should accept a default value', async () => {
|
|
48
|
-
(0, _react.render)(_TextArea || (_TextArea = (0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
49
|
-
label: "Name",
|
|
50
|
-
autoGrow: false,
|
|
51
|
-
defaultValue: "Tom Servo"
|
|
52
|
-
})));
|
|
53
|
-
const input = _react.screen.getByRole('textbox');
|
|
54
|
-
expect(input).toHaveTextContent('Tom Servo');
|
|
55
|
-
});
|
|
56
|
-
it('should include a label', async () => {
|
|
57
|
-
const _render = (0, _react.render)(_TextArea2 || (_TextArea2 = (0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
58
|
-
label: "Name",
|
|
59
|
-
autoGrow: false
|
|
60
|
-
}))),
|
|
61
|
-
container = _render.container;
|
|
62
|
-
const textArea = container.querySelector('span[class$="-formFieldLayout__label"]');
|
|
63
|
-
expect(textArea).toHaveTextContent('Name');
|
|
64
|
-
});
|
|
65
|
-
it('should set an initial height', async () => {
|
|
66
|
-
(0, _react.render)(_TextArea3 || (_TextArea3 = (0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
67
|
-
label: "Name",
|
|
68
|
-
autoGrow: false,
|
|
69
|
-
height: "100px"
|
|
70
|
-
})));
|
|
71
|
-
const input = _react.screen.getByRole('textbox');
|
|
72
|
-
expect(input).toHaveStyle('height: 100px');
|
|
73
|
-
});
|
|
74
|
-
it('should focus the textarea when focus is called', async () => {
|
|
75
|
-
let ref;
|
|
76
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
77
|
-
label: "Name",
|
|
78
|
-
autoGrow: false
|
|
79
|
-
// @ts-expect-error this is managed by the testing framework
|
|
80
|
-
,
|
|
81
|
-
textareaRef: el => ref = el
|
|
82
|
-
}));
|
|
83
|
-
const input = _react.screen.getByRole('textbox');
|
|
84
|
-
ref.focus();
|
|
85
|
-
expect(input).toHaveFocus();
|
|
86
|
-
});
|
|
87
|
-
it('provides a focused getter', async () => {
|
|
88
|
-
let ref;
|
|
89
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
90
|
-
label: "Name",
|
|
91
|
-
autoGrow: false,
|
|
92
|
-
ref: el => ref = el
|
|
93
|
-
}));
|
|
94
|
-
ref.focus();
|
|
95
|
-
expect(ref.focused).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
it('should provide an textareaRef prop', async () => {
|
|
98
|
-
const textareaRef = _vitest.vi.fn();
|
|
99
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
100
|
-
label: "Name",
|
|
101
|
-
autoGrow: false,
|
|
102
|
-
textareaRef: textareaRef
|
|
103
|
-
}));
|
|
104
|
-
const input = _react.screen.getByRole('textbox');
|
|
105
|
-
expect(textareaRef).toHaveBeenCalledWith(input);
|
|
106
|
-
});
|
|
107
|
-
it('should provide a value getter', async () => {
|
|
108
|
-
let ref;
|
|
109
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
110
|
-
label: "Name",
|
|
111
|
-
autoGrow: false,
|
|
112
|
-
defaultValue: "bar"
|
|
113
|
-
// @ts-expect-error this is managed by the testing framework
|
|
114
|
-
,
|
|
115
|
-
textareaRef: el => ref = el
|
|
116
|
-
}));
|
|
117
|
-
expect(ref.value).toBe('bar');
|
|
118
|
-
});
|
|
119
|
-
describe('events', () => {
|
|
120
|
-
it('responds to onChange event', async () => {
|
|
121
|
-
const onChange = _vitest.vi.fn();
|
|
122
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
123
|
-
label: "Name",
|
|
124
|
-
autoGrow: false,
|
|
125
|
-
onChange: onChange
|
|
126
|
-
}));
|
|
127
|
-
const input = _react.screen.getByRole('textbox');
|
|
128
|
-
_react.fireEvent.change(input, {
|
|
129
|
-
target: {
|
|
130
|
-
value: 'foo'
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
await (0, _react.waitFor)(() => {
|
|
134
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
it('does not respond to onChange event when disabled', async () => {
|
|
138
|
-
const onChange = _vitest.vi.fn();
|
|
139
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
140
|
-
disabled: true,
|
|
141
|
-
label: "Name",
|
|
142
|
-
autoGrow: false,
|
|
143
|
-
onChange: onChange
|
|
144
|
-
}));
|
|
145
|
-
const input = _react.screen.getByRole('textbox');
|
|
146
|
-
_react.fireEvent.change(input, {
|
|
147
|
-
target: {
|
|
148
|
-
value: 'foo'
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
152
|
-
});
|
|
153
|
-
it('does not respond to onChange event when readOnly', async () => {
|
|
154
|
-
const onChange = _vitest.vi.fn();
|
|
155
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
156
|
-
readOnly: true,
|
|
157
|
-
label: "Name",
|
|
158
|
-
autoGrow: false,
|
|
159
|
-
onChange: onChange
|
|
160
|
-
}));
|
|
161
|
-
const input = _react.screen.getByRole('textbox');
|
|
162
|
-
_react.fireEvent.change(input, {
|
|
163
|
-
target: {
|
|
164
|
-
value: 'foo'
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
168
|
-
});
|
|
169
|
-
it('responds to onBlur event', async () => {
|
|
170
|
-
const onBlur = _vitest.vi.fn();
|
|
171
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
172
|
-
label: "Name",
|
|
173
|
-
autoGrow: false,
|
|
174
|
-
onBlur: onBlur
|
|
175
|
-
}));
|
|
176
|
-
_userEvent.default.tab();
|
|
177
|
-
_userEvent.default.tab();
|
|
178
|
-
await (0, _react.waitFor)(() => {
|
|
179
|
-
expect(onBlur).toHaveBeenCalled();
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
it('responds to onFocus event', async () => {
|
|
183
|
-
const onFocus = _vitest.vi.fn();
|
|
184
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
185
|
-
label: "Name",
|
|
186
|
-
autoGrow: false,
|
|
187
|
-
onFocus: onFocus
|
|
188
|
-
}));
|
|
189
|
-
const input = _react.screen.getByRole('textbox');
|
|
190
|
-
input.focus();
|
|
191
|
-
await (0, _react.waitFor)(() => {
|
|
192
|
-
expect(onFocus).toHaveBeenCalled();
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
describe('for a11y', () => {
|
|
197
|
-
it('should meet standards', async () => {
|
|
198
|
-
const _render2 = (0, _react.render)(_TextArea4 || (_TextArea4 = (0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
199
|
-
label: "Name",
|
|
200
|
-
autoGrow: false
|
|
201
|
-
}))),
|
|
202
|
-
container = _render2.container;
|
|
203
|
-
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
204
|
-
expect(axeCheck).toBe(true);
|
|
205
|
-
});
|
|
206
|
-
it('should set aria-invalid when errors prop is set', async () => {
|
|
207
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TextArea, {
|
|
208
|
-
label: "Name",
|
|
209
|
-
autoGrow: false,
|
|
210
|
-
messages: [{
|
|
211
|
-
type: 'error',
|
|
212
|
-
text: 'some error message'
|
|
213
|
-
}]
|
|
214
|
-
}));
|
|
215
|
-
const input = _react.screen.getByRole('textbox');
|
|
216
|
-
expect(input).toHaveAttribute('aria-invalid');
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
@@ -1,213 +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 { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
27
|
-
import userEvent from '@testing-library/user-event'
|
|
28
|
-
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
29
|
-
import '@testing-library/jest-dom'
|
|
30
|
-
|
|
31
|
-
import { TextArea } from '../index'
|
|
32
|
-
|
|
33
|
-
describe('TextArea', () => {
|
|
34
|
-
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
35
|
-
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
36
|
-
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
// Mocking console to prevent test output pollution and expect for messages
|
|
39
|
-
consoleWarningMock = vi
|
|
40
|
-
.spyOn(console, 'warn')
|
|
41
|
-
.mockImplementation(() => {}) as any
|
|
42
|
-
consoleErrorMock = vi
|
|
43
|
-
.spyOn(console, 'error')
|
|
44
|
-
.mockImplementation(() => {}) as any
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
consoleWarningMock.mockRestore()
|
|
49
|
-
consoleErrorMock.mockRestore()
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should accept a default value', async () => {
|
|
53
|
-
render(<TextArea label="Name" autoGrow={false} defaultValue="Tom Servo" />)
|
|
54
|
-
const input = screen.getByRole('textbox')
|
|
55
|
-
|
|
56
|
-
expect(input).toHaveTextContent('Tom Servo')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should include a label', async () => {
|
|
60
|
-
const { container } = render(<TextArea label="Name" autoGrow={false} />)
|
|
61
|
-
const textArea = container.querySelector(
|
|
62
|
-
'span[class$="-formFieldLayout__label"]'
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
expect(textArea).toHaveTextContent('Name')
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('should set an initial height', async () => {
|
|
69
|
-
render(<TextArea label="Name" autoGrow={false} height="100px" />)
|
|
70
|
-
const input = screen.getByRole('textbox')
|
|
71
|
-
|
|
72
|
-
expect(input).toHaveStyle('height: 100px')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should focus the textarea when focus is called', async () => {
|
|
76
|
-
let ref: TextArea
|
|
77
|
-
render(
|
|
78
|
-
<TextArea
|
|
79
|
-
label="Name"
|
|
80
|
-
autoGrow={false}
|
|
81
|
-
// @ts-expect-error this is managed by the testing framework
|
|
82
|
-
textareaRef={(el: TextArea) => (ref = el)}
|
|
83
|
-
/>
|
|
84
|
-
)
|
|
85
|
-
const input = screen.getByRole('textbox')
|
|
86
|
-
|
|
87
|
-
ref!.focus()
|
|
88
|
-
|
|
89
|
-
expect(input).toHaveFocus()
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('provides a focused getter', async () => {
|
|
93
|
-
let ref: TextArea
|
|
94
|
-
render(
|
|
95
|
-
<TextArea
|
|
96
|
-
label="Name"
|
|
97
|
-
autoGrow={false}
|
|
98
|
-
ref={(el: TextArea) => (ref = el)}
|
|
99
|
-
/>
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
ref!.focus()
|
|
103
|
-
|
|
104
|
-
expect(ref!.focused).toBe(true)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('should provide an textareaRef prop', async () => {
|
|
108
|
-
const textareaRef = vi.fn()
|
|
109
|
-
render(<TextArea label="Name" autoGrow={false} textareaRef={textareaRef} />)
|
|
110
|
-
const input = screen.getByRole('textbox')
|
|
111
|
-
|
|
112
|
-
expect(textareaRef).toHaveBeenCalledWith(input)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it('should provide a value getter', async () => {
|
|
116
|
-
let ref: TextArea
|
|
117
|
-
render(
|
|
118
|
-
<TextArea
|
|
119
|
-
label="Name"
|
|
120
|
-
autoGrow={false}
|
|
121
|
-
defaultValue="bar"
|
|
122
|
-
// @ts-expect-error this is managed by the testing framework
|
|
123
|
-
textareaRef={(el: TextArea) => (ref = el)}
|
|
124
|
-
/>
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
expect(ref!.value).toBe('bar')
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
describe('events', () => {
|
|
131
|
-
it('responds to onChange event', async () => {
|
|
132
|
-
const onChange = vi.fn()
|
|
133
|
-
render(<TextArea label="Name" autoGrow={false} onChange={onChange} />)
|
|
134
|
-
const input = screen.getByRole('textbox')
|
|
135
|
-
|
|
136
|
-
fireEvent.change(input, { target: { value: 'foo' } })
|
|
137
|
-
|
|
138
|
-
await waitFor(() => {
|
|
139
|
-
expect(onChange).toHaveBeenCalledTimes(1)
|
|
140
|
-
})
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
it('does not respond to onChange event when disabled', async () => {
|
|
144
|
-
const onChange = vi.fn()
|
|
145
|
-
render(
|
|
146
|
-
<TextArea disabled label="Name" autoGrow={false} onChange={onChange} />
|
|
147
|
-
)
|
|
148
|
-
const input = screen.getByRole('textbox')
|
|
149
|
-
|
|
150
|
-
fireEvent.change(input, { target: { value: 'foo' } })
|
|
151
|
-
|
|
152
|
-
expect(onChange).not.toHaveBeenCalled()
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
it('does not respond to onChange event when readOnly', async () => {
|
|
156
|
-
const onChange = vi.fn()
|
|
157
|
-
render(
|
|
158
|
-
<TextArea readOnly label="Name" autoGrow={false} onChange={onChange} />
|
|
159
|
-
)
|
|
160
|
-
const input = screen.getByRole('textbox')
|
|
161
|
-
|
|
162
|
-
fireEvent.change(input, { target: { value: 'foo' } })
|
|
163
|
-
|
|
164
|
-
expect(onChange).not.toHaveBeenCalled()
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('responds to onBlur event', async () => {
|
|
168
|
-
const onBlur = vi.fn()
|
|
169
|
-
render(<TextArea label="Name" autoGrow={false} onBlur={onBlur} />)
|
|
170
|
-
|
|
171
|
-
userEvent.tab()
|
|
172
|
-
userEvent.tab()
|
|
173
|
-
|
|
174
|
-
await waitFor(() => {
|
|
175
|
-
expect(onBlur).toHaveBeenCalled()
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('responds to onFocus event', async () => {
|
|
180
|
-
const onFocus = vi.fn()
|
|
181
|
-
render(<TextArea label="Name" autoGrow={false} onFocus={onFocus} />)
|
|
182
|
-
const input = screen.getByRole('textbox')
|
|
183
|
-
|
|
184
|
-
input.focus()
|
|
185
|
-
|
|
186
|
-
await waitFor(() => {
|
|
187
|
-
expect(onFocus).toHaveBeenCalled()
|
|
188
|
-
})
|
|
189
|
-
})
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
describe('for a11y', () => {
|
|
193
|
-
it('should meet standards', async () => {
|
|
194
|
-
const { container } = render(<TextArea label="Name" autoGrow={false} />)
|
|
195
|
-
const axeCheck = await runAxeCheck(container)
|
|
196
|
-
|
|
197
|
-
expect(axeCheck).toBe(true)
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('should set aria-invalid when errors prop is set', async () => {
|
|
201
|
-
render(
|
|
202
|
-
<TextArea
|
|
203
|
-
label="Name"
|
|
204
|
-
autoGrow={false}
|
|
205
|
-
messages={[{ type: 'error', text: 'some error message' }]}
|
|
206
|
-
/>
|
|
207
|
-
)
|
|
208
|
-
const input = screen.getByRole('textbox')
|
|
209
|
-
|
|
210
|
-
expect(input).toHaveAttribute('aria-invalid')
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.test.d.ts","sourceRoot":"","sources":["../../../src/TextArea/__new-tests__/TextArea.test.tsx"],"names":[],"mappings":"AA4BA,OAAO,2BAA2B,CAAA"}
|