|
1 | 1 | import * as vscode from "vscode"; |
2 | 2 | import * as assert from "assert"; |
3 | | -import { exampleWorkspacePath } from "./test-utils"; |
| 3 | +import { exampleWorkspacePath, exampleWorkspaceOutPath, copyFile, wait } from "./test-utils"; |
4 | 4 | import { isQuartoDoc } from "../core/doc"; |
5 | 5 |
|
| 6 | +const APPROX_TIME_TO_OPEN_VISUAL_EDITOR = 1600; |
| 7 | + |
6 | 8 | suite("Quarto basics", () => { |
| 9 | + // Before we run any tests, we should copy any files that get edited in the tests to file under `exampleWorkspaceOutPath` |
| 10 | + suiteSetup(async () => { |
| 11 | + const didCopyFile = await copyFile(exampleWorkspacePath('hello.qmd'), exampleWorkspaceOutPath('hello.qmd')); |
| 12 | + assert.ok(didCopyFile); |
| 13 | + }); |
| 14 | + |
7 | 15 | test("Can open a Quarto document", async () => { |
8 | | - const doc = await vscode.workspace.openTextDocument(exampleWorkspacePath("hello.qmd")); |
| 16 | + const doc = await vscode.workspace.openTextDocument(exampleWorkspaceOutPath("hello.qmd")); |
9 | 17 | const editor = await vscode.window.showTextDocument(doc); |
| 18 | + |
10 | 19 | assert.strictEqual(editor?.document.languageId, "quarto"); |
11 | 20 | assert.strictEqual(isQuartoDoc(editor?.document), true); |
12 | 21 | }); |
| 22 | + // Note: the following tests may be flaky. They rely on waiting estimated amounts of time for commands to complete. |
| 23 | + test("Can edit in visual mode", async () => { |
| 24 | + const doc = await vscode.workspace.openTextDocument(exampleWorkspaceOutPath("hello.qmd")); |
| 25 | + const editor = await vscode.window.showTextDocument(doc); |
| 26 | + |
| 27 | + // manually confirm visual mode so dialogue pop-up doesn't show because dialogues cause test errors |
| 28 | + // and switch to visual editor |
| 29 | + await vscode.commands.executeCommand("quarto.test_setkVisualModeConfirmedTrue"); |
| 30 | + await wait(300); // It seems necessary to wait around 300ms for this command to be done. |
| 31 | + await vscode.commands.executeCommand("quarto.editInVisualMode"); |
| 32 | + await wait(APPROX_TIME_TO_OPEN_VISUAL_EDITOR); |
| 33 | + |
| 34 | + assert.ok(await vscode.commands.executeCommand("quarto.test_isInVisualEditor")); |
| 35 | + }); |
| 36 | + // Note: this test runs after the previous test, so `hello.qmd` has already been touched by the previous |
| 37 | + // test. That's okay for this test, but could cause issues if you expect a qmd to look how it |
| 38 | + // does in `/examples`. |
| 39 | + test("Roundtrip doesn't change hello.qmd", async () => { |
| 40 | + const doc = await vscode.workspace.openTextDocument(exampleWorkspaceOutPath("hello.qmd")); |
| 41 | + const editor = await vscode.window.showTextDocument(doc); |
| 42 | + |
| 43 | + const docTextBefore = doc.getText(); |
| 44 | + |
| 45 | + // switch to visual editor and back |
| 46 | + await vscode.commands.executeCommand("quarto.test_setkVisualModeConfirmedTrue"); |
| 47 | + await wait(300); |
| 48 | + await vscode.commands.executeCommand("quarto.editInVisualMode"); |
| 49 | + await wait(APPROX_TIME_TO_OPEN_VISUAL_EDITOR); |
| 50 | + await vscode.commands.executeCommand("quarto.editInSourceMode"); |
| 51 | + await wait(300); |
| 52 | + |
| 53 | + const docTextAfter = doc.getText(); |
| 54 | + assert.ok(docTextBefore === docTextAfter); |
| 55 | + }); |
13 | 56 | }); |
0 commit comments