1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

implemented app menu testing support (#1105)

* implemented app menu testing support

* addded Preferences page helm repo test

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann 2020-11-09 15:10:30 -05:00 committed by GitHub
parent 8d1c29ae4c
commit 033a91f002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 11 deletions

View File

@ -47,17 +47,23 @@ describe("Lens integration tests", () => {
await clickWhatsNew(app) await clickWhatsNew(app)
}) })
// Todo figure out how to access main menu to get these to work it('shows "add cluster"', async () => {
it.skip('shows "add cluster"', async () => { await app.electron.ipcRenderer.send('test-menu-item-click', "File", "Add Cluster")
await app.client.keys(['Shift', 'Meta', 'A'])
await app.client.waitUntilTextExists("h2", "Add Cluster") await app.client.waitUntilTextExists("h2", "Add Cluster")
await app.client.keys(['Shift', 'Meta'])
}) })
it.skip('shows "preferences"', async () => { describe("preferences page", () => {
await app.client.keys(['Meta', ',']) it('shows "preferences"', async () => {
await app.client.waitUntilTextExists("h2", "Preferences") let appName: string = process.platform === "darwin" ? "Lens" : "File"
await app.client.keys('Meta') 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 () => { it.skip('quits Lens"', async () => {

View File

@ -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 { autorun } from "mobx";
import { WindowManager } from "./window-manager"; 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 { addClusterURL } from "../renderer/components/+add-cluster/add-cluster.route";
import { preferencesURL } from "../renderer/components/+preferences/preferences.route"; import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.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)); const menu = Menu.buildFromTemplate(Object.values(appMenu));
Menu.setApplicationMenu(menu); 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();
});
}
} }

View File

@ -128,7 +128,7 @@ export class Preferences extends React.Component {
<KubectlBinaries preferences={preferences}/> <KubectlBinaries preferences={preferences}/>
<h2><Trans>Helm</Trans></h2> <h2><Trans>Helm</Trans></h2>
<Select <Select id="HelmRepoSelect"
placeholder={<Trans>Repositories</Trans>} placeholder={<Trans>Repositories</Trans>}
isLoading={this.helmLoading} isLoading={this.helmLoading}
isDisabled={this.helmLoading} isDisabled={this.helmLoading}