|
| 1 | +import assert = require("node:assert"); |
| 2 | +import path = require("node:path"); |
| 3 | +import * as fs from "fs/promises"; |
| 4 | +import { |
| 5 | + VSBrowser, |
| 6 | + WebDriver, |
| 7 | + ActivityBar, |
| 8 | + InputBox, |
| 9 | + Workbench, |
| 10 | + TreeItem, |
| 11 | + ContextMenu, |
| 12 | + CustomTreeSection, |
| 13 | +} from "vscode-extension-tester"; |
| 14 | +import {getViewSection, openCommandPrompt, waitForTreeItems} from "./utils"; |
| 15 | + |
| 16 | +describe("Configure Databricks Extension", function () { |
| 17 | + // these will be populated by the before() function |
| 18 | + let browser: VSBrowser; |
| 19 | + let driver: WebDriver; |
| 20 | + let projectDir: string; |
| 21 | + |
| 22 | + // this will be populated by the tests |
| 23 | + let clusterId: string; |
| 24 | + |
| 25 | + this.timeout(20_000); |
| 26 | + |
| 27 | + before(async () => { |
| 28 | + browser = VSBrowser.instance; |
| 29 | + driver = browser.driver; |
| 30 | + |
| 31 | + assert(process.env["PROJECT_DIR"]); |
| 32 | + projectDir = process.env["PROJECT_DIR"]; |
| 33 | + }); |
| 34 | + |
| 35 | + it("should open VSCode", async () => { |
| 36 | + const title = await driver.getTitle(); |
| 37 | + assert(title.indexOf("Get Started") >= 0); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should open project folder", async () => { |
| 41 | + await fs.writeFile(path.join(projectDir, "test.txt"), "test"); |
| 42 | + (await new ActivityBar().getViewControl("Explorer"))?.openView(); |
| 43 | + |
| 44 | + const workbench = new Workbench(); |
| 45 | + const prompt = await openCommandPrompt(workbench); |
| 46 | + await prompt.setText(">File: Open Folder"); |
| 47 | + await prompt.confirm(); |
| 48 | + |
| 49 | + const input = await InputBox.create(); |
| 50 | + await input.setText(projectDir); |
| 51 | + await input.confirm(); |
| 52 | + |
| 53 | + // wait for reload to complete |
| 54 | + await new Promise((resolve) => setTimeout(resolve, 3000)); |
| 55 | + }); |
| 56 | + |
| 57 | + it("should open databricks panel and login", async () => { |
| 58 | + const section = await getViewSection("Configuration"); |
| 59 | + assert(section); |
| 60 | + const welcome = await section.findWelcomeContent(); |
| 61 | + assert(welcome); |
| 62 | + const buttons = await welcome.getButtons(); |
| 63 | + assert(buttons); |
| 64 | + assert(buttons.length > 0); |
| 65 | + await buttons[0].click(); |
| 66 | + |
| 67 | + const input = await InputBox.create(); |
| 68 | + await input.selectQuickPick(1); |
| 69 | + |
| 70 | + assert(await waitForTreeItems(section)); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should dismiss notifications", async () => { |
| 74 | + const notifications = await new Workbench().getNotifications(); |
| 75 | + for (const n of notifications) { |
| 76 | + await n.dismiss(); |
| 77 | + } |
| 78 | + }); |
| 79 | + |
| 80 | + it("shoult list clusters", async () => { |
| 81 | + const section = await getViewSection("Clusters"); |
| 82 | + assert(section); |
| 83 | + const tree = section as CustomTreeSection; |
| 84 | + |
| 85 | + assert(await waitForTreeItems(tree)); |
| 86 | + |
| 87 | + const items = await tree.getVisibleItems(); |
| 88 | + const labels = await Promise.all(items.map((item) => item.getLabel())); |
| 89 | + assert(labels.length > 0); |
| 90 | + }); |
| 91 | + |
| 92 | + it.skip("should filter clusters", async () => { |
| 93 | + // test is skipped because context menus currently don't work in vscode-extension-tester |
| 94 | + // https://github.com/redhat-developer/vscode-extension-tester/issues/444 |
| 95 | + |
| 96 | + const section = await getViewSection("Clusters"); |
| 97 | + assert(section); |
| 98 | + const action = await section!.getAction("Filter clusters ..."); |
| 99 | + assert(action); |
| 100 | + |
| 101 | + await action.click(); |
| 102 | + const menu = new ContextMenu(new Workbench()); |
| 103 | + let item = await menu.getItem("Created by me"); |
| 104 | + await item?.click(); |
| 105 | + |
| 106 | + const items = await section.getVisibleItems(); |
| 107 | + assert(items.length > 0); |
| 108 | + }); |
| 109 | + |
| 110 | + it("should attach cluster", async () => { |
| 111 | + const section = await getViewSection("Clusters"); |
| 112 | + assert(section); |
| 113 | + |
| 114 | + const items = await section.getVisibleItems(); |
| 115 | + assert(items.length > 0); |
| 116 | + |
| 117 | + // find top level cluster tree item |
| 118 | + let item: TreeItem | undefined; |
| 119 | + for (const i of items) { |
| 120 | + if (await (i as TreeItem).hasChildren()) { |
| 121 | + item = i as TreeItem; |
| 122 | + break; |
| 123 | + } |
| 124 | + } |
| 125 | + assert(item); |
| 126 | + |
| 127 | + const buttons = await (item as TreeItem).getActionButtons(); |
| 128 | + await buttons[0].click(); |
| 129 | + |
| 130 | + // check if cluster is attached |
| 131 | + const config = await getViewSection("Configuration"); |
| 132 | + assert(config); |
| 133 | + const configTree = config as CustomTreeSection; |
| 134 | + |
| 135 | + assert(await waitForTreeItems(configTree)); |
| 136 | + |
| 137 | + const configItems = await configTree.getVisibleItems(); |
| 138 | + |
| 139 | + let clusterConfigItem: TreeItem | undefined; |
| 140 | + const itemLabel = await item.getLabel(); |
| 141 | + for (const i of configItems) { |
| 142 | + const label = await i.getLabel(); |
| 143 | + if (label === `Cluster: ${itemLabel}`) { |
| 144 | + clusterConfigItem = i; |
| 145 | + break; |
| 146 | + } |
| 147 | + } |
| 148 | + assert(clusterConfigItem); |
| 149 | + |
| 150 | + // get cluster ID |
| 151 | + const clusterPropsItems = await clusterConfigItem.getChildren(); |
| 152 | + const clusterProps: Record<string, string> = {}; |
| 153 | + for (const i of clusterPropsItems) { |
| 154 | + clusterProps[await i.getLabel()] = (await i.getDescription()) || ""; |
| 155 | + } |
| 156 | + |
| 157 | + // store cluster ID in test suite scope |
| 158 | + clusterId = clusterProps["Cluster ID:"]; |
| 159 | + assert(clusterId); |
| 160 | + }); |
| 161 | + |
| 162 | + it("should write the project config file", async () => { |
| 163 | + let projectConfig = JSON.parse( |
| 164 | + await fs.readFile( |
| 165 | + path.join(projectDir, ".databricks", "project.json"), |
| 166 | + "utf-8" |
| 167 | + ) |
| 168 | + ); |
| 169 | + |
| 170 | + assert.deepEqual(projectConfig, { |
| 171 | + clusterId, |
| 172 | + profile: "DEFAULT", |
| 173 | + }); |
| 174 | + }); |
| 175 | +}); |
0 commit comments