diff --git a/integration/__tests__/app.tests.ts b/integration/__tests__/app.tests.ts index 604ac43323..74081a2061 100644 --- a/integration/__tests__/app.tests.ts +++ b/integration/__tests__/app.tests.ts @@ -47,17 +47,23 @@ describe("Lens integration tests", () => { await clickWhatsNew(app) }) - // Todo figure out how to access main menu to get these to work - it.skip('shows "add cluster"', async () => { - await app.client.keys(['Shift', 'Meta', 'A']) + it('shows "add cluster"', async () => { + await app.electron.ipcRenderer.send('test-menu-item-click', "File", "Add Cluster") await app.client.waitUntilTextExists("h2", "Add Cluster") - await app.client.keys(['Shift', 'Meta']) }) - it.skip('shows "preferences"', async () => { - await app.client.keys(['Meta', ',']) - await app.client.waitUntilTextExists("h2", "Preferences") - await app.client.keys('Meta') + describe("preferences page", () => { + it('shows "preferences"', async () => { + let appName: string = process.platform === "darwin" ? "Lens" : "File" + await app.electron.ipcRenderer.send('test-menu-item-click', appName, "Preferences") + await app.client.waitUntilTextExists("h2", "Preferences") + }) + + it('ensures helm repos', async () => { + await app.client.waitUntilTextExists("div.repos #message-stable", "stable") // wait for the helm-cli to fetch the stable repo + await app.client.click("#HelmRepoSelect") // click the repo select to activate the drop-down + await app.client.waitUntilTextExists("div.Select__option", "") // wait for at least one option to appear (any text) + }) }) it.skip('quits Lens"', async () => { diff --git a/src/main/menu.ts b/src/main/menu.ts index cb8f260dcf..bc4be680cf 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -1,7 +1,7 @@ -import { app, BrowserWindow, dialog, Menu, MenuItem, MenuItemConstructorOptions, webContents, shell } from "electron" +import { app, BrowserWindow, dialog, ipcMain, IpcMainEvent, Menu, MenuItem, MenuItemConstructorOptions, webContents, shell } from "electron" import { autorun } from "mobx"; import { WindowManager } from "./window-manager"; -import { appName, isMac, isWindows } from "../common/vars"; +import { appName, isMac, isWindows, isTestEnv } from "../common/vars"; import { addClusterURL } from "../renderer/components/+add-cluster/add-cluster.route"; import { preferencesURL } from "../renderer/components/+preferences/preferences.route"; import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route"; @@ -235,4 +235,38 @@ export function buildMenu(windowManager: WindowManager) { const menu = Menu.buildFromTemplate(Object.values(appMenu)); Menu.setApplicationMenu(menu); + + if (isTestEnv) { + // this is a workaround for the test environment (spectron) not being able to directly access + // the application menus (https://github.com/electron-userland/spectron/issues/21) + ipcMain.on('test-menu-item-click', (event: IpcMainEvent, ...names: string[]) => { + let menu: Menu = Menu.getApplicationMenu() + const parentLabels: string[] = []; + let menuItem: MenuItem + + for (const name of names) { + parentLabels.push(name); + menuItem = menu?.items?.find(item => item.label === name); + if (!menuItem) { + break; + } + menu = menuItem.submenu; + } + + const menuPath: string = parentLabels.join(" -> ") + if (!menuItem) { + logger.info(`[MENU:test-menu-item-click] Cannot find menu item ${menuPath}`); + return; + } + + const { enabled, visible, click } = menuItem; + if (enabled === false || visible === false || typeof click !== 'function') { + logger.info(`[MENU:test-menu-item-click] Menu item ${menuPath} not clickable`); + return; + } + + logger.info(`[MENU:test-menu-item-click] Menu item ${menuPath} click!`); + menuItem.click(); + }); + } } diff --git a/src/renderer/components/+preferences/preferences.tsx b/src/renderer/components/+preferences/preferences.tsx index 22cbd4a7b1..2fc58646df 100644 --- a/src/renderer/components/+preferences/preferences.tsx +++ b/src/renderer/components/+preferences/preferences.tsx @@ -128,7 +128,7 @@ export class Preferences extends React.Component {

Helm

-