mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
implemented app menu testing support
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
f69f8c793f
commit
86b19ac24b
@ -48,16 +48,15 @@ describe("Lens integration tests", () => {
|
||||
})
|
||||
|
||||
// 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', ','])
|
||||
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")
|
||||
await app.client.keys('Meta')
|
||||
})
|
||||
|
||||
it.skip('quits Lens"', async () => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
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";
|
||||
@ -235,4 +235,35 @@ export function buildMenu(windowManager: WindowManager) {
|
||||
|
||||
const menu = Menu.buildFromTemplate(Object.values(appMenu));
|
||||
Menu.setApplicationMenu(menu);
|
||||
|
||||
if (!!process.env.JEST_WORKER_ID) {
|
||||
ipcMain.on('test-menu-item-click', (event: IpcMainEvent, ...names: string[]) => {
|
||||
let menu: Menu = Menu.getApplicationMenu()
|
||||
const parentLabels: string[] = [];
|
||||
let menuItem: MenuItem
|
||||
|
||||
for (let name of names) {
|
||||
parentLabels.push(name);
|
||||
menuItem = menu?.items?.find(item => item.label === name);
|
||||
if (!menuItem) {
|
||||
break;
|
||||
}
|
||||
menu = menuItem.submenu;
|
||||
}
|
||||
|
||||
if (!menuItem) {
|
||||
logger.info(`[MENU:test-menu-item-click] Cannot find menu item ${parentLabels.join(" -> ")}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let { enabled, visible, click } = menuItem;
|
||||
if (enabled === false || visible === false || typeof click !== 'function') {
|
||||
logger.info(`[MENU:test-menu-item-click] Menu item ${parentLabels.join(" -> ")} not clickable`);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(`[MENU:test-menu-item-click] Menu item ${parentLabels.join(" -> ")} click!`);
|
||||
menuItem.click();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user