Skip to content

Commit

Permalink
Status bar tests
Browse files Browse the repository at this point in the history
commit-id:45249b72
  • Loading branch information
Draggu committed Dec 10, 2024
1 parent bae6bc2 commit 39f1618
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test-support/scarb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
import commandExists = require("command-exists");

export const is_scarb_available = () =>
commandExists("scarb")
.then(() => true)
.catch(() => false);
6 changes: 6 additions & 0 deletions ui-test-resources/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-resources/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.
71 changes: 71 additions & 0 deletions ui-test/statusBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { EditorView, StatusBar, VSBrowser, WebElement, Workbench } from "vscode-extension-tester";
import { expect } from "chai";
import { is_scarb_available } from "../test-support/scarb";
import * as path from "path";

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

let is_scarb: boolean;

before(async function () {
is_scarb = await is_scarb_available();

await VSBrowser.instance.openResources(path.join("ui-test-resources", "empty"));
});

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

it("checks if status bar is displaying correct message", 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 (is_scarb) {
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);

// Wait so extension have time to refresh.
await new Promise((done) => setTimeout(done, 2000));

const statusBar = await getStatusBarItem();

expect(statusBar).to.be.undefined;
});
});

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 39f1618

Please sign in to comment.