diff --git a/test-support/scarb.ts b/test-support/scarb.ts new file mode 100644 index 0000000..bb8c807 --- /dev/null +++ b/test-support/scarb.ts @@ -0,0 +1,3 @@ +import { sync as commandExists } from "command-exists"; + +export const isScarbAvailable = commandExists("scarb"); diff --git a/ui-test/fixtures/empty/Scarb.lock b/ui-test/fixtures/empty/Scarb.lock new file mode 100644 index 0000000..080628e --- /dev/null +++ b/ui-test/fixtures/empty/Scarb.lock @@ -0,0 +1,6 @@ +# Code generated by scarb DO NOT EDIT. +version = 1 + +[[package]] +name = "empty" +version = "0.1.0" diff --git a/ui-test/fixtures/empty/Scarb.toml b/ui-test/fixtures/empty/Scarb.toml new file mode 100644 index 0000000..3e29fcd --- /dev/null +++ b/ui-test/fixtures/empty/Scarb.toml @@ -0,0 +1,3 @@ +[package] +name = "empty" +version = "0.1.0" diff --git a/ui-test/fixtures/empty/src/lib.cairo b/ui-test/fixtures/empty/src/lib.cairo new file mode 100644 index 0000000..e69de29 diff --git a/ui-test/statusBar.ts b/ui-test/statusBar.ts new file mode 100644 index 0000000..ec8c87f --- /dev/null +++ b/ui-test/statusBar.ts @@ -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 (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 { + const items = await new StatusBar().getItems(); + + for (const item of items) { + const text = await item.getText(); + + if (text.startsWith("Cairo")) { + return item; + } + } + + return undefined; +}