Skip to content

Tests for navigation of cells using up/down arrow #9905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/datascience-ui/react-common/monacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as fastDeepEqual from 'fast-deep-equal';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
import * as React from 'react';
import { isTestExecution } from '../../client/common/constants';
import { IDisposable } from '../../client/common/types';
import { logMessage } from './logger';

Expand Down Expand Up @@ -393,6 +394,10 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
}

private scrollToCurrentPosition(_editor: monacoEditor.editor.IStandaloneCodeEditor) {
// Unfortunately during functional tests we hack the line count and the like.
if (isTestExecution()) {
return;
}
// Scroll to the visible line that has our current line. Note: Visible lines are not sorted by monaco
// so we have to retrieve the current line's index (not its visible position)
const visibleLineDivs = this.getVisibleLines();
Expand Down
44 changes: 44 additions & 0 deletions src/test/datascience/nativeEditor.functional.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,50 @@ for _ in range(50):
}
});

test('Navigating cells using up/down keys while focus is set to editor', async () => {
wrapper.update();

const firstCell = 0;
const secondCell = 1;

// Set focus to the first cell.
let update = waitForUpdate(wrapper, NativeEditor, 1);
clickCell(firstCell);
await update;
update = waitForMessage(ioc, InteractiveWindowMessages.FocusedCellEditor);
simulateKeyPressOnCell(firstCell, { code: 'Enter' });
await update;
assert.ok(isCellFocused(wrapper, 'NativeCell', firstCell));

// Now press the down arrow, and focus should go to the next cell.
update = waitForMessage(ioc, InteractiveWindowMessages.FocusedCellEditor);
let monacoEditor = getNativeFocusedEditor(wrapper)!.instance() as MonacoEditor;
monacoEditor.getCurrentVisibleLine = () => 0;
monacoEditor.getVisibleLineCount = () => 1;
simulateKeyPressOnCell(firstCell, { code: 'ArrowDown' });
await update;

// The next cell must be focused, but not selected.
assert.isFalse(isCellFocused(wrapper, 'NativeCell', firstCell), 'First new cell must not be focused');
assert.isTrue(isCellFocused(wrapper, 'NativeCell', secondCell), 'Second new cell must be focused');
assert.isFalse(isCellSelected(wrapper, 'NativeCell', firstCell), 'First new cell must not be selected');
assert.isFalse(isCellSelected(wrapper, 'NativeCell', secondCell), 'Second new cell must not be selected');

// Now press the up arrow, and focus should go back to the first cell.
update = waitForMessage(ioc, InteractiveWindowMessages.FocusedCellEditor);
monacoEditor = getNativeFocusedEditor(wrapper)!.instance() as MonacoEditor;
monacoEditor.getCurrentVisibleLine = () => 0;
monacoEditor.getVisibleLineCount = () => 1;
simulateKeyPressOnCell(firstCell, { code: 'ArrowUp' });
await update;

// The first cell must be focused, but not selected.
assert.isTrue(isCellFocused(wrapper, 'NativeCell', firstCell), 'First new cell must not be focused');
assert.isFalse(isCellFocused(wrapper, 'NativeCell', secondCell), 'Second new cell must be focused');
assert.isFalse(isCellSelected(wrapper, 'NativeCell', firstCell), 'First new cell must not be selected');
assert.isFalse(isCellSelected(wrapper, 'NativeCell', secondCell), 'Second new cell must not be selected');
});

test("Pressing 'd' on a selected cell twice deletes the cell", async () => {
// Initially 3 cells.
wrapper.update();
Expand Down