diff --git a/src/test/suite/fold.test.ts b/src/test/suite/fold.test.ts new file mode 100644 index 0000000000..c4618c0048 --- /dev/null +++ b/src/test/suite/fold.test.ts @@ -0,0 +1,68 @@ +import * as assert from "assert"; +import * as vscode from "vscode"; +import * as sinon from "sinon"; +import { getCursorlessApi } from "../../util/getExtensionApi"; +import { openNewEditor } from "../openNewEditor"; + +suite("fold", async function () { + this.timeout("100s"); + this.retries(3); + + teardown(() => { + sinon.restore(); + }); + + test("fold made", foldMade); + test("unfold made", unfoldMade); +}); + +async function foldMade() { + const graph = (await getCursorlessApi()).graph!; + const editor = await openNewEditor("function myFunk() {\n\n}", "typescript"); + + await vscode.commands.executeCommand( + "cursorless.command", + "fold made", + "fold", + [ + { + type: "primitive", + mark: { + type: "cursor", + }, + }, + ] + ); + + assert.equal(editor.visibleRanges.length, 2); + assert.equal(editor.visibleRanges[0].start.line, 0); + assert.equal(editor.visibleRanges[0].end.line, 0); + assert.equal(editor.visibleRanges[1].start.line, 2); + assert.equal(editor.visibleRanges[1].start.line, 2); +} + +async function unfoldMade() { + const graph = (await getCursorlessApi()).graph!; + const editor = await openNewEditor("function myFunk() {\n\n}", "typescript"); + await vscode.commands.executeCommand("editor.fold", { + selectionLines: [0], + }); + + assert.equal(editor.visibleRanges.length, 2); + + await vscode.commands.executeCommand( + "cursorless.command", + "unfold made", + "unfold", + [ + { + type: "primitive", + mark: { + type: "cursor", + }, + }, + ] + ); + + assert.equal(editor.visibleRanges.length, 1); +} diff --git a/src/test/suite/scroll.test.ts b/src/test/suite/scroll.test.ts new file mode 100644 index 0000000000..3ae37ea9bc --- /dev/null +++ b/src/test/suite/scroll.test.ts @@ -0,0 +1,69 @@ +import * as assert from "assert"; +import * as vscode from "vscode"; +import * as sinon from "sinon"; +import { getCursorlessApi } from "../../util/getExtensionApi"; +import { openNewEditor } from "../openNewEditor"; + +suite("scroll", async function () { + this.timeout("100s"); + this.retries(3); + + teardown(() => { + sinon.restore(); + }); + + test("top whale", topWhale); + test("bottom whale", bottomWhale); +}); + +async function topWhale() { + const graph = (await getCursorlessApi()).graph!; + const editor = await openNewEditor("hello\nworld"); + editor.selections = [new vscode.Selection(1, 0, 1, 0)]; + + await vscode.commands.executeCommand( + "cursorless.command", + "crown whale", + "scrollToTop", + [ + { + type: "primitive", + mark: { + type: "cursor", + }, + }, + ] + ); + + assert.equal(editor.visibleRanges.length, 1); + assert.equal(editor.visibleRanges[0].start.line, 1); +} + +async function bottomWhale() { + const graph = (await getCursorlessApi()).graph!; + const editor = await openNewEditor("hello\nworld"); + await vscode.commands.executeCommand("revealLine", { + lineNumber: 1, + at: "top", + }); + editor.selections = [new vscode.Selection(1, 0, 1, 0)]; + + assert.equal(editor.visibleRanges[0].start.line, 1); + + await vscode.commands.executeCommand( + "cursorless.command", + "bottom whale", + "scrollToBottom", + [ + { + type: "primitive", + mark: { + type: "cursor", + }, + }, + ] + ); + + assert.equal(editor.visibleRanges.length, 1); + assert.equal(editor.visibleRanges[0].start.line, 0); +}