@instructure/ui-source-code-editor 10.16.3-snapshot--1 → 10.16.4-snapshot-0
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 +9 -1
- package/es/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.js +241 -4
- package/lib/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.js +240 -2
- package/package.json +16 -18
- package/src/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.tsx +302 -2
- package/tsconfig.build.json +0 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/SourceCodeEditor/__new-tests__/SourceCodeEditor.test.d.ts.map +1 -1
- package/es/SourceCodeEditor/SourceCodeEditorLocator.js +0 -58
- package/lib/SourceCodeEditor/SourceCodeEditorLocator.js +0 -63
- package/src/SourceCodeEditor/SourceCodeEditorLocator.ts +0 -59
- package/types/SourceCodeEditor/SourceCodeEditorLocator.d.ts +0 -355
- package/types/SourceCodeEditor/SourceCodeEditorLocator.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,15 @@
|
|
|
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.16.
|
|
6
|
+
## [10.16.4-snapshot-0](https://github.com/instructure/instructure-ui/compare/v10.16.3...v10.16.4-snapshot-0) (2025-05-05)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-source-code-editor
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [10.16.3](https://github.com/instructure/instructure-ui/compare/v10.16.1...v10.16.3) (2025-04-30)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-source-code-editor
|
|
9
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _SourceCodeEditor, _SourceCodeEditor2;
|
|
1
|
+
var _SourceCodeEditor, _SourceCodeEditor2, _SourceCodeEditor3, _SourceCodeEditor4, _SourceCodeEditor5, _SourceCodeEditor6, _SourceCodeEditor7, _SourceCodeEditor8, _SourceCodeEditor9, _SourceCodeEditor10, _SourceCodeEditor11, _SourceCodeEditor12, _SourceCodeEditor13, _SourceCodeEditor14;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -22,10 +22,11 @@ var _SourceCodeEditor, _SourceCodeEditor2;
|
|
|
22
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
import
|
|
27
|
-
import
|
|
25
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
26
|
+
import userEvent from '@testing-library/user-event';
|
|
27
|
+
import { vi } from 'vitest';
|
|
28
28
|
import '@testing-library/jest-dom';
|
|
29
|
+
import SourceCodeEditor from '../index';
|
|
29
30
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
30
31
|
describe('<SourceCodeEditor />', () => {
|
|
31
32
|
describe('syntax highlight', () => {
|
|
@@ -61,4 +62,240 @@ describe('<SourceCodeEditor />', () => {
|
|
|
61
62
|
expect(editorElement).toHaveAttribute('aria-labelledby', labelId);
|
|
62
63
|
});
|
|
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
|
+
});
|
|
64
301
|
});
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
var _react = require("@testing-library/react");
|
|
5
|
-
var
|
|
5
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
6
|
+
var _vitest = require("vitest");
|
|
6
7
|
require("@testing-library/jest-dom");
|
|
8
|
+
var _index = _interopRequireDefault(require("../index"));
|
|
7
9
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
8
|
-
var _SourceCodeEditor, _SourceCodeEditor2;
|
|
10
|
+
var _SourceCodeEditor, _SourceCodeEditor2, _SourceCodeEditor3, _SourceCodeEditor4, _SourceCodeEditor5, _SourceCodeEditor6, _SourceCodeEditor7, _SourceCodeEditor8, _SourceCodeEditor9, _SourceCodeEditor10, _SourceCodeEditor11, _SourceCodeEditor12, _SourceCodeEditor13, _SourceCodeEditor14;
|
|
9
11
|
/*
|
|
10
12
|
* The MIT License (MIT)
|
|
11
13
|
*
|
|
@@ -63,4 +65,240 @@ describe('<SourceCodeEditor />', () => {
|
|
|
63
65
|
expect(editorElement).toHaveAttribute('aria-labelledby', labelId);
|
|
64
66
|
});
|
|
65
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
|
+
});
|
|
66
304
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-source-code-editor",
|
|
3
|
-
"version": "10.16.
|
|
3
|
+
"version": "10.16.4-snapshot-0",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,11 +23,10 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-babel-preset": "10.16.
|
|
27
|
-
"@instructure/ui-test-queries": "10.16.3-snapshot--1",
|
|
28
|
-
"@instructure/ui-test-utils": "10.16.3-snapshot--1",
|
|
26
|
+
"@instructure/ui-babel-preset": "10.16.4-snapshot-0",
|
|
29
27
|
"@testing-library/jest-dom": "^6.6.3",
|
|
30
28
|
"@testing-library/react": "^16.0.1",
|
|
29
|
+
"@testing-library/user-event": "^14.5.2",
|
|
31
30
|
"vitest": "^2.1.8"
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
@@ -45,20 +44,19 @@
|
|
|
45
44
|
"@codemirror/search": "^6.5.6",
|
|
46
45
|
"@codemirror/state": "^6.4.1",
|
|
47
46
|
"@codemirror/view": "^6.34.1",
|
|
48
|
-
"@instructure/emotion": "10.16.
|
|
49
|
-
"@instructure/shared-types": "10.16.
|
|
50
|
-
"@instructure/ui-a11y-content": "10.16.
|
|
51
|
-
"@instructure/ui-buttons": "10.16.
|
|
52
|
-
"@instructure/ui-dom-utils": "10.16.
|
|
53
|
-
"@instructure/ui-i18n": "10.16.
|
|
54
|
-
"@instructure/ui-icons": "10.16.
|
|
55
|
-
"@instructure/ui-prop-types": "10.16.
|
|
56
|
-
"@instructure/ui-react-utils": "10.16.
|
|
57
|
-
"@instructure/ui-
|
|
58
|
-
"@instructure/ui-
|
|
59
|
-
"@instructure/ui-
|
|
60
|
-
"@instructure/ui-
|
|
61
|
-
"@instructure/ui-utils": "10.16.3-snapshot--1",
|
|
47
|
+
"@instructure/emotion": "10.16.4-snapshot-0",
|
|
48
|
+
"@instructure/shared-types": "10.16.4-snapshot-0",
|
|
49
|
+
"@instructure/ui-a11y-content": "10.16.4-snapshot-0",
|
|
50
|
+
"@instructure/ui-buttons": "10.16.4-snapshot-0",
|
|
51
|
+
"@instructure/ui-dom-utils": "10.16.4-snapshot-0",
|
|
52
|
+
"@instructure/ui-i18n": "10.16.4-snapshot-0",
|
|
53
|
+
"@instructure/ui-icons": "10.16.4-snapshot-0",
|
|
54
|
+
"@instructure/ui-prop-types": "10.16.4-snapshot-0",
|
|
55
|
+
"@instructure/ui-react-utils": "10.16.4-snapshot-0",
|
|
56
|
+
"@instructure/ui-testable": "10.16.4-snapshot-0",
|
|
57
|
+
"@instructure/ui-text-input": "10.16.4-snapshot-0",
|
|
58
|
+
"@instructure/ui-themes": "10.16.4-snapshot-0",
|
|
59
|
+
"@instructure/ui-utils": "10.16.4-snapshot-0",
|
|
62
60
|
"@lezer/highlight": "1.2.1",
|
|
63
61
|
"prop-types": "^15.8.1"
|
|
64
62
|
},
|