From 8d3bc40aa99208803e73abe427c54a8cc1b4ad2f Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Fri, 6 May 2022 13:49:57 +0300 Subject: [PATCH] Add behaviour for navigating to preferences using tray Signed-off-by: Janne Savolainen --- .../navigation-using-tray.test.ts.snap | 542 ++++++++++++++++++ .../preferences/navigation-using-tray.test.ts | 44 ++ src/main/getDiForUnitTesting.ts | 7 +- .../test-utils/get-application-builder.tsx | 33 +- 4 files changed, 623 insertions(+), 3 deletions(-) create mode 100644 src/behaviours/preferences/__snapshots__/navigation-using-tray.test.ts.snap create mode 100644 src/behaviours/preferences/navigation-using-tray.test.ts diff --git a/src/behaviours/preferences/__snapshots__/navigation-using-tray.test.ts.snap b/src/behaviours/preferences/__snapshots__/navigation-using-tray.test.ts.snap new file mode 100644 index 0000000000..006460b386 --- /dev/null +++ b/src/behaviours/preferences/__snapshots__/navigation-using-tray.test.ts.snap @@ -0,0 +1,542 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`show-about-using-tray renders 1`] = ` + +
+ +`; + +exports[`show-about-using-tray when navigating using tray renders 1`] = ` + +
+
+ +
+
+
+

+ Application +

+
+
+ Theme + +
+
+ + +
+
+
+ Select... +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+ Extension Install Registry + +
+
+ + +
+
+
+ Select... +
+
+ +
+
+
+ + +
+
+
+

+ This setting is to change the registry URL for installing extensions by name. + + If you are unable to access the default registry ( + https://registry.npmjs.org + ) + + you can change it in your + + .npmrc + +  file or in the input below. +

+
+ +
+
+
+
+
+
+ Start-up + +
+ +
+
+
+
+ Update Channel + +
+
+ + +
+
+
+ Select... +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+ Locale Timezone + +
+
+ + +
+
+
+ Select... +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+ + + close + + +
+ +
+
+
+
+
+
+ +`; diff --git a/src/behaviours/preferences/navigation-using-tray.test.ts b/src/behaviours/preferences/navigation-using-tray.test.ts new file mode 100644 index 0000000000..065cc54f4b --- /dev/null +++ b/src/behaviours/preferences/navigation-using-tray.test.ts @@ -0,0 +1,44 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import type { RenderResult } from "@testing-library/react"; +import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; +import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; + +describe("show-about-using-tray", () => { + let applicationBuilder: ApplicationBuilder; + let rendered: RenderResult; + + beforeEach(async () => { + applicationBuilder = getApplicationBuilder(); + + rendered = await applicationBuilder.render(); + }); + + it("renders", () => { + expect(rendered.baseElement).toMatchSnapshot(); + }); + + it("does not show application preferences page yet", () => { + const actual = rendered.queryByTestId("application-preferences-page"); + + expect(actual).toBeNull(); + }); + + describe("when navigating using tray", () => { + beforeEach(async () => { + await applicationBuilder.tray.click("open-preferences"); + }); + + it("renders", () => { + expect(rendered.baseElement).toMatchSnapshot(); + }); + + it("shows application preferences page", () => { + const actual = rendered.getByTestId("application-preferences-page"); + + expect(actual).not.toBeNull(); + }); + }); +}); diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index efd065905c..26a1ea5963 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -77,6 +77,7 @@ import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectab import getElectronThemeInjectable from "./electron-app/features/get-electron-theme.injectable"; import syncThemeFromOperatingSystemInjectable from "./electron-app/features/sync-theme-from-operating-system.injectable"; import platformInjectable from "../common/vars/platform.injectable"; +import productNameInjectable from "./app-paths/app-name/product-name.injectable"; export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) { const { @@ -101,9 +102,9 @@ export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) { if (doGeneralOverrides) { di.override(hotbarStoreInjectable, () => ({ load: () => {} })); - di.override(userStoreInjectable, () => ({ startMainReactions: () => {} }) as UserStore); + di.override(userStoreInjectable, () => ({ startMainReactions: () => {}, extensionRegistryUrl: { customUrl: "some-custom-url" } }) as UserStore); di.override(extensionsStoreInjectable, () => ({ isEnabled: (opts) => (void opts, false) }) as ExtensionsStore); - di.override(clusterStoreInjectable, () => ({ getById: (id) => (void id, {}) as Cluster }) as ClusterStore); + di.override(clusterStoreInjectable, () => ({ provideInitialFromMain: () => {}, getById: (id) => (void id, {}) as Cluster }) as ClusterStore); di.override(fileSystemProvisionerStoreInjectable, () => ({}) as FileSystemProvisionerStore); overrideOperatingSystem(di); @@ -114,6 +115,8 @@ export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) { di.override(environmentVariablesInjectable, () => ({})); di.override(commandLineArgumentsInjectable, () => []); + di.override(productNameInjectable, () => "some-product-name"); + di.override(clusterFramesInjectable, () => observable.map()); di.override(stopServicesAndExitAppInjectable, () => () => {}); diff --git a/src/renderer/components/test-utils/get-application-builder.tsx b/src/renderer/components/test-utils/get-application-builder.tsx index 178874ed76..5e6ca0396e 100644 --- a/src/renderer/components/test-utils/get-application-builder.tsx +++ b/src/renderer/components/test-utils/get-application-builder.tsx @@ -25,7 +25,7 @@ import type { ClusterStore } from "../../../common/cluster-store/cluster-store"; import mainExtensionsInjectable from "../../../extensions/main-extensions.injectable"; import currentRouteComponentInjectable from "../../routes/current-route-component.injectable"; import { pipeline } from "@ogre-tools/fp"; -import { flatMap, compact, join, get, filter } from "lodash/fp"; +import { flatMap, compact, join, get, filter, find, map } from "lodash/fp"; import preferenceNavigationItemsInjectable from "../+preferences/preferences-navigation/preference-navigation-items.injectable"; import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable"; import type { MenuItemOpts } from "../../../main/menu/application-menu-items.injectable"; @@ -44,6 +44,7 @@ import { flushPromises } from "../../../common/test-utils/flush-promises"; import type { NamespaceStore } from "../+namespaces/store"; import namespaceStoreInjectable from "../+namespaces/store.injectable"; import historyInjectable from "../../navigation/history.injectable"; +import trayMenuItemsInjectable from "../../../main/tray/tray-menu-item/tray-menu-items.injectable"; type Callback = (dis: DiContainers) => void | Promise; @@ -56,6 +57,10 @@ export interface ApplicationBuilder { beforeRender: (callback: Callback) => ApplicationBuilder; render: () => Promise; + tray: { + click: (id: string) => Promise; + }; + applicationMenu: { click: (path: string) => Promise; }; @@ -180,6 +185,32 @@ export const getApplicationBuilder = () => { }, }, + tray: { + click: async (id: string) => { + const trayMenuItems = mainDi.inject( + trayMenuItemsInjectable, + ); + + const menuItem = pipeline( + trayMenuItems.get(), + find((menuItem) => menuItem.id === id), + ); + + if (!menuItem) { + const availableIds = pipeline( + trayMenuItems.get(), + filter(item => !!item.click), + map(item => item.id), + join(", "), + ); + + throw new Error(`Tried to click tray menu item with ID ${id} which does not exist. Available IDs are: "${availableIds}"`); + } + + await menuItem.click?.(); + }, + }, + preferences: { close: () => { const link = rendered.getByTestId("close-preferences");