@instructure/ui-source-code-editor 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 +15 -15
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.js +0 -301
- package/lib/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.js +0 -304
- package/src/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.tsx +0 -362
- package/types/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.d.ts +0 -2
- package/types/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.d.ts.map +0 -1
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
var _SourceCodeEditor, _SourceCodeEditor2, _SourceCodeEditor3, _SourceCodeEditor4, _SourceCodeEditor5, _SourceCodeEditor6, _SourceCodeEditor7, _SourceCodeEditor8, _SourceCodeEditor9, _SourceCodeEditor10, _SourceCodeEditor11, _SourceCodeEditor12, _SourceCodeEditor13, _SourceCodeEditor14;
|
|
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
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
26
|
-
import userEvent from '@testing-library/user-event';
|
|
27
|
-
import { vi } from 'vitest';
|
|
28
|
-
import '@testing-library/jest-dom';
|
|
29
|
-
import SourceCodeEditor from '../index';
|
|
30
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
31
|
-
describe('<SourceCodeEditor />', () => {
|
|
32
|
-
describe('syntax highlight', () => {
|
|
33
|
-
it('should highlight jsx code', async () => {
|
|
34
|
-
const _render = render(_SourceCodeEditor || (_SourceCodeEditor = _jsx(SourceCodeEditor, {
|
|
35
|
-
label: "test",
|
|
36
|
-
language: "jsx",
|
|
37
|
-
defaultValue: "const a = 2;"
|
|
38
|
-
}))),
|
|
39
|
-
container = _render.container;
|
|
40
|
-
const activeLine = container.querySelectorAll('.cm-content span');
|
|
41
|
-
expect(activeLine).toHaveLength(3);
|
|
42
|
-
expect(activeLine[0]).toHaveStyle({
|
|
43
|
-
color: '#770088'
|
|
44
|
-
});
|
|
45
|
-
expect(activeLine[1]).toHaveStyle({
|
|
46
|
-
color: '#0000ff'
|
|
47
|
-
});
|
|
48
|
-
expect(activeLine[2]).toHaveStyle({
|
|
49
|
-
color: '#116644'
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
it('should link editor element to label using aria-labelledby attribute', async () => {
|
|
53
|
-
var _container$querySelec;
|
|
54
|
-
const _render2 = render(_SourceCodeEditor2 || (_SourceCodeEditor2 = _jsx(SourceCodeEditor, {
|
|
55
|
-
label: "test",
|
|
56
|
-
language: "jsx",
|
|
57
|
-
defaultValue: "const a = 2;"
|
|
58
|
-
}))),
|
|
59
|
-
container = _render2.container;
|
|
60
|
-
const editorElement = container.querySelector('[role="textbox"]');
|
|
61
|
-
const labelId = (_container$querySelec = container.querySelector('[class$="-label"]')) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.id;
|
|
62
|
-
expect(editorElement).toHaveAttribute('aria-labelledby', labelId);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe('defaultValue', () => {
|
|
66
|
-
let consoleWarningMock;
|
|
67
|
-
let consoleErrorMock;
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
// Mocking console to prevent test output pollution
|
|
70
|
-
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
71
|
-
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
72
|
-
});
|
|
73
|
-
afterEach(() => {
|
|
74
|
-
consoleWarningMock.mockRestore();
|
|
75
|
-
consoleErrorMock.mockRestore();
|
|
76
|
-
});
|
|
77
|
-
it('should be applied on load', async () => {
|
|
78
|
-
render(_SourceCodeEditor3 || (_SourceCodeEditor3 = _jsx(SourceCodeEditor, {
|
|
79
|
-
label: "foo",
|
|
80
|
-
defaultValue: "hello"
|
|
81
|
-
})));
|
|
82
|
-
const input = screen.getByRole('textbox');
|
|
83
|
-
expect(input).toHaveTextContent('hello');
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
describe('spellcheck', () => {
|
|
87
|
-
it('should set `spellcheck="true"` on the input', async () => {
|
|
88
|
-
render(_SourceCodeEditor4 || (_SourceCodeEditor4 = _jsx(SourceCodeEditor, {
|
|
89
|
-
label: "foo",
|
|
90
|
-
spellcheck: true
|
|
91
|
-
})));
|
|
92
|
-
const input = screen.getByRole('textbox');
|
|
93
|
-
expect(input).toHaveAttribute('spellcheck', 'true');
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
describe('readOnly', () => {
|
|
97
|
-
it('should still update value when value prop changes', async () => {
|
|
98
|
-
const onChange = vi.fn();
|
|
99
|
-
const _render3 = render(_jsx(SourceCodeEditor, {
|
|
100
|
-
label: "foo",
|
|
101
|
-
readOnly: true,
|
|
102
|
-
value: "hello",
|
|
103
|
-
onChange: onChange
|
|
104
|
-
})),
|
|
105
|
-
rerender = _render3.rerender;
|
|
106
|
-
const input = screen.getByRole('textbox');
|
|
107
|
-
expect(input).not.toHaveTextContent('hello world');
|
|
108
|
-
rerender(_jsx(SourceCodeEditor, {
|
|
109
|
-
label: "foo",
|
|
110
|
-
readOnly: true,
|
|
111
|
-
value: "hello world",
|
|
112
|
-
onChange: onChange
|
|
113
|
-
}));
|
|
114
|
-
const inputUpdated = screen.getByRole('textbox');
|
|
115
|
-
expect(inputUpdated).toHaveTextContent('hello world');
|
|
116
|
-
});
|
|
117
|
-
it('should still be focusable', async () => {
|
|
118
|
-
let elementRef = null;
|
|
119
|
-
render(_jsx(SourceCodeEditor, {
|
|
120
|
-
label: "foo",
|
|
121
|
-
readOnly: true,
|
|
122
|
-
ref: component => {
|
|
123
|
-
elementRef = component;
|
|
124
|
-
}
|
|
125
|
-
}));
|
|
126
|
-
const input = screen.getByRole('textbox');
|
|
127
|
-
elementRef.focus();
|
|
128
|
-
await waitFor(() => {
|
|
129
|
-
expect(input).toHaveFocus();
|
|
130
|
-
expect(document.activeElement).toBe(input);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe('editable turned off', () => {
|
|
135
|
-
it('should set `contenteditable` to false', async () => {
|
|
136
|
-
render(_SourceCodeEditor5 || (_SourceCodeEditor5 = _jsx(SourceCodeEditor, {
|
|
137
|
-
label: "foo",
|
|
138
|
-
editable: false
|
|
139
|
-
})));
|
|
140
|
-
const input = screen.getByRole('textbox');
|
|
141
|
-
expect(input).toHaveAttribute('contenteditable', 'false');
|
|
142
|
-
});
|
|
143
|
-
it('should not be focusable', async () => {
|
|
144
|
-
let elementRef = null;
|
|
145
|
-
render(_jsx(SourceCodeEditor, {
|
|
146
|
-
label: "foo",
|
|
147
|
-
editable: false,
|
|
148
|
-
elementRef: component => {
|
|
149
|
-
elementRef = component;
|
|
150
|
-
}
|
|
151
|
-
}));
|
|
152
|
-
const input = screen.getByRole('textbox');
|
|
153
|
-
elementRef.focus();
|
|
154
|
-
await waitFor(() => {
|
|
155
|
-
expect(elementRef).not.toHaveFocus();
|
|
156
|
-
expect(document.activeElement).not.toBe(input);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
describe('lineNumbers', () => {
|
|
161
|
-
it('should display line numbers', async () => {
|
|
162
|
-
const _render4 = render(_SourceCodeEditor6 || (_SourceCodeEditor6 = _jsx(SourceCodeEditor, {
|
|
163
|
-
label: "foo",
|
|
164
|
-
defaultValue: `
|
|
165
|
-
line1
|
|
166
|
-
line2
|
|
167
|
-
line3
|
|
168
|
-
`,
|
|
169
|
-
lineNumbers: true
|
|
170
|
-
}))),
|
|
171
|
-
container = _render4.container;
|
|
172
|
-
const lineNumbers = container.querySelector('[class$="-lineNumbers"]');
|
|
173
|
-
expect(lineNumbers).toBeInTheDocument();
|
|
174
|
-
expect(lineNumbers).toBeVisible();
|
|
175
|
-
expect(lineNumbers).toHaveTextContent('123');
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
describe('foldGutter', () => {
|
|
179
|
-
it('should display fold icons', async () => {
|
|
180
|
-
render(_SourceCodeEditor7 || (_SourceCodeEditor7 = _jsx(SourceCodeEditor, {
|
|
181
|
-
label: "foo",
|
|
182
|
-
defaultValue: `const func = () => {
|
|
183
|
-
console.log('foo')
|
|
184
|
-
}`,
|
|
185
|
-
foldGutter: true
|
|
186
|
-
})));
|
|
187
|
-
const gutterIcon = screen.getByTitle('Fold line');
|
|
188
|
-
expect(gutterIcon).toBeInTheDocument();
|
|
189
|
-
expect(gutterIcon).toBeVisible();
|
|
190
|
-
});
|
|
191
|
-
it('should fold lines on click', async () => {
|
|
192
|
-
const _render5 = render(_SourceCodeEditor8 || (_SourceCodeEditor8 = _jsx(SourceCodeEditor, {
|
|
193
|
-
label: "foo",
|
|
194
|
-
defaultValue: `const func = () => {
|
|
195
|
-
console.log('foo')
|
|
196
|
-
}`,
|
|
197
|
-
foldGutter: true
|
|
198
|
-
}))),
|
|
199
|
-
container = _render5.container;
|
|
200
|
-
const editor = container.querySelector('[class$="-codeEditor"]');
|
|
201
|
-
const gutterIcon = screen.getByTitle('Fold line');
|
|
202
|
-
expect(gutterIcon).toBeInTheDocument();
|
|
203
|
-
await userEvent.click(gutterIcon);
|
|
204
|
-
const unfoldIcons = screen.getAllByTitle('Unfold line');
|
|
205
|
-
expect(editor).not.toHaveTextContent("console.log('foo')");
|
|
206
|
-
expect(unfoldIcons[1]).toBeVisible();
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
describe('highlightActiveLine', () => {
|
|
210
|
-
it('should not highlight line by default', async () => {
|
|
211
|
-
const _render6 = render(_SourceCodeEditor9 || (_SourceCodeEditor9 = _jsx(SourceCodeEditor, {
|
|
212
|
-
label: "foo",
|
|
213
|
-
defaultValue: `const myNumber = 8`
|
|
214
|
-
}))),
|
|
215
|
-
container = _render6.container;
|
|
216
|
-
const allLines = container.querySelectorAll('[class="cm-line"]');
|
|
217
|
-
expect(allLines[0]).not.toHaveClass('cm-activeLine');
|
|
218
|
-
});
|
|
219
|
-
it('should highlight line when true', async () => {
|
|
220
|
-
const _render7 = render(_SourceCodeEditor10 || (_SourceCodeEditor10 = _jsx(SourceCodeEditor, {
|
|
221
|
-
label: "foo",
|
|
222
|
-
defaultValue: `const myNumber = 8`,
|
|
223
|
-
highlightActiveLine: true
|
|
224
|
-
}))),
|
|
225
|
-
container = _render7.container;
|
|
226
|
-
const allLines = container.querySelectorAll('[class$="cm-line"]');
|
|
227
|
-
expect(allLines[0]).toHaveClass('cm-activeLine');
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
describe('highlightActiveLineGutter', () => {
|
|
231
|
-
it('should not highlight gutter element by default', async () => {
|
|
232
|
-
const _render8 = render(_SourceCodeEditor11 || (_SourceCodeEditor11 = _jsx(SourceCodeEditor, {
|
|
233
|
-
label: "foo",
|
|
234
|
-
defaultValue: `const myNumber = 8`,
|
|
235
|
-
lineNumbers: true
|
|
236
|
-
}))),
|
|
237
|
-
container = _render8.container;
|
|
238
|
-
const allGutterElements = container.querySelectorAll('[class$="cm-gutterElement"]');
|
|
239
|
-
expect(allGutterElements[0]).not.toHaveClass('cm-activeLineGutter');
|
|
240
|
-
});
|
|
241
|
-
it('should highlight gutter element when true', async () => {
|
|
242
|
-
const _render9 = render(_SourceCodeEditor12 || (_SourceCodeEditor12 = _jsx(SourceCodeEditor, {
|
|
243
|
-
label: "foo",
|
|
244
|
-
defaultValue: `const myNumber = 8`,
|
|
245
|
-
lineNumbers: true,
|
|
246
|
-
highlightActiveLineGutter: true
|
|
247
|
-
}))),
|
|
248
|
-
container = _render9.container;
|
|
249
|
-
const allGutterElements = container.querySelectorAll('[class^="cm-gutterElement"]');
|
|
250
|
-
expect(allGutterElements[1]).toHaveClass('cm-activeLineGutter');
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
describe('direction', () => {
|
|
254
|
-
it('rtl should apply', async () => {
|
|
255
|
-
render(_SourceCodeEditor13 || (_SourceCodeEditor13 = _jsx(SourceCodeEditor, {
|
|
256
|
-
label: "foo",
|
|
257
|
-
defaultValue: "hello",
|
|
258
|
-
direction: 'rtl'
|
|
259
|
-
})));
|
|
260
|
-
const input = screen.getByRole('textbox');
|
|
261
|
-
expect(input).toHaveAttribute('dir', 'rtl');
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
describe('label', () => {
|
|
265
|
-
it('should be inserted in the ScreenReaderContent', async () => {
|
|
266
|
-
const _render10 = render(_SourceCodeEditor14 || (_SourceCodeEditor14 = _jsx(SourceCodeEditor, {
|
|
267
|
-
label: "this is a label for the SR",
|
|
268
|
-
defaultValue: "hello"
|
|
269
|
-
}))),
|
|
270
|
-
container = _render10.container;
|
|
271
|
-
const label = container.querySelector('[class$="-screenReaderContent"]');
|
|
272
|
-
expect(label).toHaveTextContent('this is a label for the SR');
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
describe('elementRef', () => {
|
|
276
|
-
it('should return with the root element', async () => {
|
|
277
|
-
const elementRef = vi.fn();
|
|
278
|
-
const _render11 = render(_jsx(SourceCodeEditor, {
|
|
279
|
-
label: "foo",
|
|
280
|
-
defaultValue: "hello",
|
|
281
|
-
elementRef: elementRef
|
|
282
|
-
})),
|
|
283
|
-
container = _render11.container;
|
|
284
|
-
const editor = container.querySelector('[class$="-codeEditor"]');
|
|
285
|
-
expect(elementRef).toHaveBeenCalledWith(editor);
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
describe('containerRef', () => {
|
|
289
|
-
it('should return with the root element', async () => {
|
|
290
|
-
const containerRef = vi.fn();
|
|
291
|
-
const _render12 = render(_jsx(SourceCodeEditor, {
|
|
292
|
-
label: "foo",
|
|
293
|
-
defaultValue: "hello",
|
|
294
|
-
containerRef: containerRef
|
|
295
|
-
})),
|
|
296
|
-
container = _render12.container;
|
|
297
|
-
const editorContainer = container.querySelector('[class$="-codeEditorContainer"]');
|
|
298
|
-
expect(containerRef).toHaveBeenCalledWith(editorContainer);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
});
|
|
@@ -1,304 +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 _index = _interopRequireDefault(require("../index"));
|
|
9
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
|
-
var _SourceCodeEditor, _SourceCodeEditor2, _SourceCodeEditor3, _SourceCodeEditor4, _SourceCodeEditor5, _SourceCodeEditor6, _SourceCodeEditor7, _SourceCodeEditor8, _SourceCodeEditor9, _SourceCodeEditor10, _SourceCodeEditor11, _SourceCodeEditor12, _SourceCodeEditor13, _SourceCodeEditor14;
|
|
11
|
-
/*
|
|
12
|
-
* The MIT License (MIT)
|
|
13
|
-
*
|
|
14
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
15
|
-
*
|
|
16
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
-
* in the Software without restriction, including without limitation the rights
|
|
19
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
-
* furnished to do so, subject to the following conditions:
|
|
22
|
-
*
|
|
23
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
-
* copies or substantial portions of the Software.
|
|
25
|
-
*
|
|
26
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
-
* SOFTWARE.
|
|
33
|
-
*/
|
|
34
|
-
describe('<SourceCodeEditor />', () => {
|
|
35
|
-
describe('syntax highlight', () => {
|
|
36
|
-
it('should highlight jsx code', async () => {
|
|
37
|
-
const _render = (0, _react.render)(_SourceCodeEditor || (_SourceCodeEditor = (0, _jsxRuntime.jsx)(_index.default, {
|
|
38
|
-
label: "test",
|
|
39
|
-
language: "jsx",
|
|
40
|
-
defaultValue: "const a = 2;"
|
|
41
|
-
}))),
|
|
42
|
-
container = _render.container;
|
|
43
|
-
const activeLine = container.querySelectorAll('.cm-content span');
|
|
44
|
-
expect(activeLine).toHaveLength(3);
|
|
45
|
-
expect(activeLine[0]).toHaveStyle({
|
|
46
|
-
color: '#770088'
|
|
47
|
-
});
|
|
48
|
-
expect(activeLine[1]).toHaveStyle({
|
|
49
|
-
color: '#0000ff'
|
|
50
|
-
});
|
|
51
|
-
expect(activeLine[2]).toHaveStyle({
|
|
52
|
-
color: '#116644'
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it('should link editor element to label using aria-labelledby attribute', async () => {
|
|
56
|
-
var _container$querySelec;
|
|
57
|
-
const _render2 = (0, _react.render)(_SourceCodeEditor2 || (_SourceCodeEditor2 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
58
|
-
label: "test",
|
|
59
|
-
language: "jsx",
|
|
60
|
-
defaultValue: "const a = 2;"
|
|
61
|
-
}))),
|
|
62
|
-
container = _render2.container;
|
|
63
|
-
const editorElement = container.querySelector('[role="textbox"]');
|
|
64
|
-
const labelId = (_container$querySelec = container.querySelector('[class$="-label"]')) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.id;
|
|
65
|
-
expect(editorElement).toHaveAttribute('aria-labelledby', labelId);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe('defaultValue', () => {
|
|
69
|
-
let consoleWarningMock;
|
|
70
|
-
let consoleErrorMock;
|
|
71
|
-
beforeEach(() => {
|
|
72
|
-
// Mocking console to prevent test output pollution
|
|
73
|
-
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
74
|
-
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
75
|
-
});
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
consoleWarningMock.mockRestore();
|
|
78
|
-
consoleErrorMock.mockRestore();
|
|
79
|
-
});
|
|
80
|
-
it('should be applied on load', async () => {
|
|
81
|
-
(0, _react.render)(_SourceCodeEditor3 || (_SourceCodeEditor3 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
82
|
-
label: "foo",
|
|
83
|
-
defaultValue: "hello"
|
|
84
|
-
})));
|
|
85
|
-
const input = _react.screen.getByRole('textbox');
|
|
86
|
-
expect(input).toHaveTextContent('hello');
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('spellcheck', () => {
|
|
90
|
-
it('should set `spellcheck="true"` on the input', async () => {
|
|
91
|
-
(0, _react.render)(_SourceCodeEditor4 || (_SourceCodeEditor4 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
92
|
-
label: "foo",
|
|
93
|
-
spellcheck: true
|
|
94
|
-
})));
|
|
95
|
-
const input = _react.screen.getByRole('textbox');
|
|
96
|
-
expect(input).toHaveAttribute('spellcheck', 'true');
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
describe('readOnly', () => {
|
|
100
|
-
it('should still update value when value prop changes', async () => {
|
|
101
|
-
const onChange = _vitest.vi.fn();
|
|
102
|
-
const _render3 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
103
|
-
label: "foo",
|
|
104
|
-
readOnly: true,
|
|
105
|
-
value: "hello",
|
|
106
|
-
onChange: onChange
|
|
107
|
-
})),
|
|
108
|
-
rerender = _render3.rerender;
|
|
109
|
-
const input = _react.screen.getByRole('textbox');
|
|
110
|
-
expect(input).not.toHaveTextContent('hello world');
|
|
111
|
-
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
112
|
-
label: "foo",
|
|
113
|
-
readOnly: true,
|
|
114
|
-
value: "hello world",
|
|
115
|
-
onChange: onChange
|
|
116
|
-
}));
|
|
117
|
-
const inputUpdated = _react.screen.getByRole('textbox');
|
|
118
|
-
expect(inputUpdated).toHaveTextContent('hello world');
|
|
119
|
-
});
|
|
120
|
-
it('should still be focusable', async () => {
|
|
121
|
-
let elementRef = null;
|
|
122
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
123
|
-
label: "foo",
|
|
124
|
-
readOnly: true,
|
|
125
|
-
ref: component => {
|
|
126
|
-
elementRef = component;
|
|
127
|
-
}
|
|
128
|
-
}));
|
|
129
|
-
const input = _react.screen.getByRole('textbox');
|
|
130
|
-
elementRef.focus();
|
|
131
|
-
await (0, _react.waitFor)(() => {
|
|
132
|
-
expect(input).toHaveFocus();
|
|
133
|
-
expect(document.activeElement).toBe(input);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
describe('editable turned off', () => {
|
|
138
|
-
it('should set `contenteditable` to false', async () => {
|
|
139
|
-
(0, _react.render)(_SourceCodeEditor5 || (_SourceCodeEditor5 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
140
|
-
label: "foo",
|
|
141
|
-
editable: false
|
|
142
|
-
})));
|
|
143
|
-
const input = _react.screen.getByRole('textbox');
|
|
144
|
-
expect(input).toHaveAttribute('contenteditable', 'false');
|
|
145
|
-
});
|
|
146
|
-
it('should not be focusable', async () => {
|
|
147
|
-
let elementRef = null;
|
|
148
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
149
|
-
label: "foo",
|
|
150
|
-
editable: false,
|
|
151
|
-
elementRef: component => {
|
|
152
|
-
elementRef = component;
|
|
153
|
-
}
|
|
154
|
-
}));
|
|
155
|
-
const input = _react.screen.getByRole('textbox');
|
|
156
|
-
elementRef.focus();
|
|
157
|
-
await (0, _react.waitFor)(() => {
|
|
158
|
-
expect(elementRef).not.toHaveFocus();
|
|
159
|
-
expect(document.activeElement).not.toBe(input);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
describe('lineNumbers', () => {
|
|
164
|
-
it('should display line numbers', async () => {
|
|
165
|
-
const _render4 = (0, _react.render)(_SourceCodeEditor6 || (_SourceCodeEditor6 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
166
|
-
label: "foo",
|
|
167
|
-
defaultValue: `
|
|
168
|
-
line1
|
|
169
|
-
line2
|
|
170
|
-
line3
|
|
171
|
-
`,
|
|
172
|
-
lineNumbers: true
|
|
173
|
-
}))),
|
|
174
|
-
container = _render4.container;
|
|
175
|
-
const lineNumbers = container.querySelector('[class$="-lineNumbers"]');
|
|
176
|
-
expect(lineNumbers).toBeInTheDocument();
|
|
177
|
-
expect(lineNumbers).toBeVisible();
|
|
178
|
-
expect(lineNumbers).toHaveTextContent('123');
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
describe('foldGutter', () => {
|
|
182
|
-
it('should display fold icons', async () => {
|
|
183
|
-
(0, _react.render)(_SourceCodeEditor7 || (_SourceCodeEditor7 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
184
|
-
label: "foo",
|
|
185
|
-
defaultValue: `const func = () => {
|
|
186
|
-
console.log('foo')
|
|
187
|
-
}`,
|
|
188
|
-
foldGutter: true
|
|
189
|
-
})));
|
|
190
|
-
const gutterIcon = _react.screen.getByTitle('Fold line');
|
|
191
|
-
expect(gutterIcon).toBeInTheDocument();
|
|
192
|
-
expect(gutterIcon).toBeVisible();
|
|
193
|
-
});
|
|
194
|
-
it('should fold lines on click', async () => {
|
|
195
|
-
const _render5 = (0, _react.render)(_SourceCodeEditor8 || (_SourceCodeEditor8 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
196
|
-
label: "foo",
|
|
197
|
-
defaultValue: `const func = () => {
|
|
198
|
-
console.log('foo')
|
|
199
|
-
}`,
|
|
200
|
-
foldGutter: true
|
|
201
|
-
}))),
|
|
202
|
-
container = _render5.container;
|
|
203
|
-
const editor = container.querySelector('[class$="-codeEditor"]');
|
|
204
|
-
const gutterIcon = _react.screen.getByTitle('Fold line');
|
|
205
|
-
expect(gutterIcon).toBeInTheDocument();
|
|
206
|
-
await _userEvent.default.click(gutterIcon);
|
|
207
|
-
const unfoldIcons = _react.screen.getAllByTitle('Unfold line');
|
|
208
|
-
expect(editor).not.toHaveTextContent("console.log('foo')");
|
|
209
|
-
expect(unfoldIcons[1]).toBeVisible();
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
describe('highlightActiveLine', () => {
|
|
213
|
-
it('should not highlight line by default', async () => {
|
|
214
|
-
const _render6 = (0, _react.render)(_SourceCodeEditor9 || (_SourceCodeEditor9 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
215
|
-
label: "foo",
|
|
216
|
-
defaultValue: `const myNumber = 8`
|
|
217
|
-
}))),
|
|
218
|
-
container = _render6.container;
|
|
219
|
-
const allLines = container.querySelectorAll('[class="cm-line"]');
|
|
220
|
-
expect(allLines[0]).not.toHaveClass('cm-activeLine');
|
|
221
|
-
});
|
|
222
|
-
it('should highlight line when true', async () => {
|
|
223
|
-
const _render7 = (0, _react.render)(_SourceCodeEditor10 || (_SourceCodeEditor10 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
224
|
-
label: "foo",
|
|
225
|
-
defaultValue: `const myNumber = 8`,
|
|
226
|
-
highlightActiveLine: true
|
|
227
|
-
}))),
|
|
228
|
-
container = _render7.container;
|
|
229
|
-
const allLines = container.querySelectorAll('[class$="cm-line"]');
|
|
230
|
-
expect(allLines[0]).toHaveClass('cm-activeLine');
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
describe('highlightActiveLineGutter', () => {
|
|
234
|
-
it('should not highlight gutter element by default', async () => {
|
|
235
|
-
const _render8 = (0, _react.render)(_SourceCodeEditor11 || (_SourceCodeEditor11 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
236
|
-
label: "foo",
|
|
237
|
-
defaultValue: `const myNumber = 8`,
|
|
238
|
-
lineNumbers: true
|
|
239
|
-
}))),
|
|
240
|
-
container = _render8.container;
|
|
241
|
-
const allGutterElements = container.querySelectorAll('[class$="cm-gutterElement"]');
|
|
242
|
-
expect(allGutterElements[0]).not.toHaveClass('cm-activeLineGutter');
|
|
243
|
-
});
|
|
244
|
-
it('should highlight gutter element when true', async () => {
|
|
245
|
-
const _render9 = (0, _react.render)(_SourceCodeEditor12 || (_SourceCodeEditor12 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
246
|
-
label: "foo",
|
|
247
|
-
defaultValue: `const myNumber = 8`,
|
|
248
|
-
lineNumbers: true,
|
|
249
|
-
highlightActiveLineGutter: true
|
|
250
|
-
}))),
|
|
251
|
-
container = _render9.container;
|
|
252
|
-
const allGutterElements = container.querySelectorAll('[class^="cm-gutterElement"]');
|
|
253
|
-
expect(allGutterElements[1]).toHaveClass('cm-activeLineGutter');
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
describe('direction', () => {
|
|
257
|
-
it('rtl should apply', async () => {
|
|
258
|
-
(0, _react.render)(_SourceCodeEditor13 || (_SourceCodeEditor13 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
259
|
-
label: "foo",
|
|
260
|
-
defaultValue: "hello",
|
|
261
|
-
direction: 'rtl'
|
|
262
|
-
})));
|
|
263
|
-
const input = _react.screen.getByRole('textbox');
|
|
264
|
-
expect(input).toHaveAttribute('dir', 'rtl');
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
describe('label', () => {
|
|
268
|
-
it('should be inserted in the ScreenReaderContent', async () => {
|
|
269
|
-
const _render10 = (0, _react.render)(_SourceCodeEditor14 || (_SourceCodeEditor14 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
270
|
-
label: "this is a label for the SR",
|
|
271
|
-
defaultValue: "hello"
|
|
272
|
-
}))),
|
|
273
|
-
container = _render10.container;
|
|
274
|
-
const label = container.querySelector('[class$="-screenReaderContent"]');
|
|
275
|
-
expect(label).toHaveTextContent('this is a label for the SR');
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
describe('elementRef', () => {
|
|
279
|
-
it('should return with the root element', async () => {
|
|
280
|
-
const elementRef = _vitest.vi.fn();
|
|
281
|
-
const _render11 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
282
|
-
label: "foo",
|
|
283
|
-
defaultValue: "hello",
|
|
284
|
-
elementRef: elementRef
|
|
285
|
-
})),
|
|
286
|
-
container = _render11.container;
|
|
287
|
-
const editor = container.querySelector('[class$="-codeEditor"]');
|
|
288
|
-
expect(elementRef).toHaveBeenCalledWith(editor);
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
describe('containerRef', () => {
|
|
292
|
-
it('should return with the root element', async () => {
|
|
293
|
-
const containerRef = _vitest.vi.fn();
|
|
294
|
-
const _render12 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
295
|
-
label: "foo",
|
|
296
|
-
defaultValue: "hello",
|
|
297
|
-
containerRef: containerRef
|
|
298
|
-
})),
|
|
299
|
-
container = _render12.container;
|
|
300
|
-
const editorContainer = container.querySelector('[class$="-codeEditorContainer"]');
|
|
301
|
-
expect(containerRef).toHaveBeenCalledWith(editorContainer);
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
});
|