Skip to content

Commit

Permalink
Status bar tests
Browse files Browse the repository at this point in the history
commit-id:d18dba8f
  • Loading branch information
Draggu committed Dec 12, 2024
1 parent 925bfed commit 2abcb8e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test-support/scarb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import commandExists from "command-exists";

let isScarbAvailableState: null | boolean = null;

export const isScarbAvailable = async () =>
(isScarbAvailableState ??= await commandExists("scarb")
.then(() => true)
.catch(() => false));
6 changes: 6 additions & 0 deletions ui-test/fixtures/empty/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "empty"
version = "0.1.0"
3 changes: 3 additions & 0 deletions ui-test/fixtures/empty/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "empty"
version = "0.1.0"
Empty file.
68 changes: 68 additions & 0 deletions ui-test/statusBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { EditorView, StatusBar, VSBrowser, WebElement, Workbench } from "vscode-extension-tester";
import { expect } from "chai";
import { isScarbAvailable } from "../test-support/scarb";
import * as path from "path";

describe("Status bar", function () {
this.timeout(50000);

before(async function () {
await VSBrowser.instance.openResources(path.join("ui-test", "fixtures", "empty"));
});

afterEach(async function () {
await new EditorView().closeAllEditors();
});

it("Displays Cairo toolchain version", async function () {
const statusBar = await VSBrowser.instance.driver.wait(
getStatusBarItem,
5000,
"failed to obtain Cairo status bar",
// Check every 0.5 second.
500,
);

expect(statusBar).not.undefined;

// `new StatusBar().getItem("Cairo")` is broken and searches not only in title.
const title = await statusBar!.getAttribute(StatusBar["locators"].StatusBar.itemTitle);

if (await isScarbAvailable()) {
expect(title).to.match(
/Cairo, Cairo Language\nscarb .+ \(.+\)\ncairo: .+ \(.+\)\nsierra: .+/,
);
} else {
expect(title).to.be.eq("Cairo, Cairo Language");
}
});

it("checks if status bar is disabled", async function () {
const settings = await new Workbench().openSettings();

const setting = await settings.findSetting("Show In Status Bar", "Cairo1");
setting.setValue(false);

const statusBarIsUndefined = await VSBrowser.instance.driver.wait(async () => {
const statusBar = await getStatusBarItem();

return statusBar === undefined;
}, 2000);

expect(statusBarIsUndefined).to.be.true;
});
});

async function getStatusBarItem(): Promise<WebElement | undefined> {
const items = await new StatusBar().getItems();

for (const item of items) {
const text = await item.getText();

if (text.startsWith("Cairo")) {
return item;
}
}

return undefined;
}

0 comments on commit 2abcb8e

Please sign in to comment.