Skip to content

Commit

Permalink
Fix the scroll-(up|down)-command tests (#1807)
Browse files Browse the repository at this point in the history
* Fix the scroll-(up|down)-command tests

* Call sinon.restore() diffensively
  • Loading branch information
whitphx authored Jan 11, 2024
1 parent 4761a18 commit a746c1c
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/test/suite/commands/move.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import assert from "assert";
import sinon from "sinon";
import { Range, TextEditor } from "vscode";
import { EmacsEmulator } from "../../../emulator";
import { assertCursorsEqual, assertSelectionsEqual, setEmptyCursors, setupWorkspace, cleanUpWorkspace } from "../utils";
Expand Down Expand Up @@ -232,16 +233,19 @@ suite("scroll-up/down-command", () => {
visibleRange = _visibleRange;
pageLines = visibleRange.end.line - visibleRange.start.line;
});
teardown(cleanUpWorkspace);
teardown(async () => {
sinon.restore();
await cleanUpWorkspace();
});

suite("scroll-up-command", () => {
test("it scrolls one page and moves the cursor to the bottom of the visible range", async () => {
const middleVisibleLine = Math.floor((visibleRange.start.line + visibleRange.end.line) / 2);
setEmptyCursors(activeTextEditor, [middleVisibleLine, 0]);

test("it delegates to the cursorPageDown command", async () => {
sinon.spy(vscode.commands, "executeCommand");
await emulator.runCommand("scrollUpCommand");

assertCursorsEqual(activeTextEditor, [(activeTextEditor.visibleRanges[0]?.end.line as number) - 1, 0]);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
assert(vscode.commands.executeCommand.calledWithExactly("cursorPageDown"), "cursorPageDown is not called");
sinon.restore();
});

test("it scrolls one page if the cursor remains in the visible range without cursor move with strictEmacsMove = true", async () => {
Expand Down Expand Up @@ -300,13 +304,13 @@ suite("scroll-up/down-command", () => {
});

suite("scroll-down-command", () => {
test("it scrolls one page and moves the cursor to the top of the visible range", async () => {
const middleVisibleLine = Math.floor((visibleRange.start.line + visibleRange.end.line) / 2);
setEmptyCursors(activeTextEditor, [middleVisibleLine, 0]);

test("it delegates to the cursorPageUp command", async () => {
sinon.spy(vscode.commands, "executeCommand");
await emulator.runCommand("scrollDownCommand");

assertCursorsEqual(activeTextEditor, [activeTextEditor.visibleRanges[0]?.start.line as number, 0]);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
assert(vscode.commands.executeCommand.calledWithExactly("cursorPageUp"), "cursorPageUp is not called");
sinon.restore();
});

test("it scrolls one page without cursor move if the cursor remains in the visible range with strictEmacsMove = true", async () => {
Expand Down

0 comments on commit a746c1c

Please sign in to comment.