Skip to content

Commit 1a7618f

Browse files
authored
Tests for navigation of cells using up/down arrow (#9905)
#9884
1 parent 521f82c commit 1a7618f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/datascience-ui/react-common/monacoEditor.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as fastDeepEqual from 'fast-deep-equal';
66
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
77
import * as React from 'react';
8+
import { isTestExecution } from '../../client/common/constants';
89
import { IDisposable } from '../../client/common/types';
910
import { logMessage } from './logger';
1011

@@ -393,6 +394,10 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
393394
}
394395

395396
private scrollToCurrentPosition(_editor: monacoEditor.editor.IStandaloneCodeEditor) {
397+
// Unfortunately during functional tests we hack the line count and the like.
398+
if (isTestExecution()) {
399+
return;
400+
}
396401
// Scroll to the visible line that has our current line. Note: Visible lines are not sorted by monaco
397402
// so we have to retrieve the current line's index (not its visible position)
398403
const visibleLineDivs = this.getVisibleLines();

src/test/datascience/nativeEditor.functional.test.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,50 @@ for _ in range(50):
10761076
}
10771077
});
10781078

1079+
test('Navigating cells using up/down keys while focus is set to editor', async () => {
1080+
wrapper.update();
1081+
1082+
const firstCell = 0;
1083+
const secondCell = 1;
1084+
1085+
// Set focus to the first cell.
1086+
let update = waitForUpdate(wrapper, NativeEditor, 1);
1087+
clickCell(firstCell);
1088+
await update;
1089+
update = waitForMessage(ioc, InteractiveWindowMessages.FocusedCellEditor);
1090+
simulateKeyPressOnCell(firstCell, { code: 'Enter' });
1091+
await update;
1092+
assert.ok(isCellFocused(wrapper, 'NativeCell', firstCell));
1093+
1094+
// Now press the down arrow, and focus should go to the next cell.
1095+
update = waitForMessage(ioc, InteractiveWindowMessages.FocusedCellEditor);
1096+
let monacoEditor = getNativeFocusedEditor(wrapper)!.instance() as MonacoEditor;
1097+
monacoEditor.getCurrentVisibleLine = () => 0;
1098+
monacoEditor.getVisibleLineCount = () => 1;
1099+
simulateKeyPressOnCell(firstCell, { code: 'ArrowDown' });
1100+
await update;
1101+
1102+
// The next cell must be focused, but not selected.
1103+
assert.isFalse(isCellFocused(wrapper, 'NativeCell', firstCell), 'First new cell must not be focused');
1104+
assert.isTrue(isCellFocused(wrapper, 'NativeCell', secondCell), 'Second new cell must be focused');
1105+
assert.isFalse(isCellSelected(wrapper, 'NativeCell', firstCell), 'First new cell must not be selected');
1106+
assert.isFalse(isCellSelected(wrapper, 'NativeCell', secondCell), 'Second new cell must not be selected');
1107+
1108+
// Now press the up arrow, and focus should go back to the first cell.
1109+
update = waitForMessage(ioc, InteractiveWindowMessages.FocusedCellEditor);
1110+
monacoEditor = getNativeFocusedEditor(wrapper)!.instance() as MonacoEditor;
1111+
monacoEditor.getCurrentVisibleLine = () => 0;
1112+
monacoEditor.getVisibleLineCount = () => 1;
1113+
simulateKeyPressOnCell(firstCell, { code: 'ArrowUp' });
1114+
await update;
1115+
1116+
// The first cell must be focused, but not selected.
1117+
assert.isTrue(isCellFocused(wrapper, 'NativeCell', firstCell), 'First new cell must not be focused');
1118+
assert.isFalse(isCellFocused(wrapper, 'NativeCell', secondCell), 'Second new cell must be focused');
1119+
assert.isFalse(isCellSelected(wrapper, 'NativeCell', firstCell), 'First new cell must not be selected');
1120+
assert.isFalse(isCellSelected(wrapper, 'NativeCell', secondCell), 'Second new cell must not be selected');
1121+
});
1122+
10791123
test("Pressing 'd' on a selected cell twice deletes the cell", async () => {
10801124
// Initially 3 cells.
10811125
wrapper.update();

0 commit comments

Comments
 (0)