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

Introduce and use ApplicationBuilder.quit in afterEach() hooks

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-10-14 13:25:33 -04:00
parent 8136e23ac6
commit f11145045b
76 changed files with 497 additions and 153 deletions

View File

@ -56,6 +56,10 @@ describe("app-paths", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("normally", () => {
let windowDi: DiContainer;
let mainDi: DiContainer;

View File

@ -0,0 +1,11 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../test-utils/get-global-override";
import createReadFileStreamInjectable from "./create-read-file-stream.injectable";
export default getGlobalOverride(createReadFileStreamInjectable, () => () => {
throw new Error("tried to create read stream for a file without override");
});

View File

@ -60,6 +60,10 @@ describe("channel", () => {
messageToChannel = mainDi.inject(sendMessageToChannelInjectionToken);
});
afterEach(() => {
builder.quit();
});
describe("given window is started", () => {
let someWindowFake: LensWindow;
@ -103,10 +107,10 @@ describe("channel", () => {
describe("messaging from renderer to main, given listener for channel in a main and application has started", () => {
let messageListenerInMainMock: jest.Mock;
let messageToChannel: SendMessageToChannel;
let builder: ApplicationBuilder;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
messageListenerInMainMock = jest.fn();
const testChannelListenerInMainInjectable = getInjectable({
@ -120,19 +124,23 @@ describe("channel", () => {
injectionToken: messageChannelListenerInjectionToken,
});
applicationBuilder.beforeApplicationStart((mainDi) => {
builder.beforeApplicationStart((mainDi) => {
runInAction(() => {
mainDi.register(testChannelListenerInMainInjectable);
});
});
await applicationBuilder.render();
await builder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
const windowDi = builder.applicationWindow.only.di;
messageToChannel = windowDi.inject(sendMessageToChannelInjectionToken);
});
afterEach(() => {
builder.quit();
});
it("when sending message, triggers listener in main", () => {
messageToChannel(testMessageChannel, "some-message");
@ -143,10 +151,10 @@ describe("channel", () => {
describe("requesting from main in renderer, given listener for channel in a main and application has started", () => {
let requestListenerInMainMock: AsyncFnMock<RequestChannelHandler<TestRequestChannel>>;
let requestFromChannel: RequestFromChannel;
let builder: ApplicationBuilder;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
requestListenerInMainMock = asyncFn();
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
@ -154,19 +162,23 @@ describe("channel", () => {
handler: () => requestListenerInMainMock,
});
applicationBuilder.beforeApplicationStart((mainDi) => {
builder.beforeApplicationStart((mainDi) => {
runInAction(() => {
mainDi.register(testChannelListenerInMainInjectable);
});
});
await applicationBuilder.render();
await builder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
const windowDi = builder.applicationWindow.only.di;
requestFromChannel = windowDi.inject(requestFromChannelInjectable);
});
afterEach(() => {
builder.quit();
});
describe("when requesting from channel", () => {
let actualPromise: Promise<string>;
@ -194,28 +206,38 @@ describe("channel", () => {
});
});
it("when registering multiple handlers for the same channel, throws", async () => {
const applicationBuilder = getApplicationBuilder();
describe("when registering multiple handlers for the same channel", () => {
let builder: ApplicationBuilder;
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
channel: testRequestChannel,
handler: () => () => "some-value",
});
const testChannelListenerInMain2Injectable = getRequestChannelListenerInjectable({
channel: testRequestChannel,
handler: () => () => "some-other-value",
});
beforeEach(() => {
builder = getApplicationBuilder();
testChannelListenerInMain2Injectable.id += "2";
const testChannelListenerInMainInjectable = getRequestChannelListenerInjectable({
channel: testRequestChannel,
handler: () => () => "some-value",
});
const testChannelListenerInMain2Injectable = getRequestChannelListenerInjectable({
channel: testRequestChannel,
handler: () => () => "some-other-value",
});
applicationBuilder.beforeApplicationStart((mainDi) => {
runInAction(() => {
mainDi.register(testChannelListenerInMainInjectable);
mainDi.register(testChannelListenerInMain2Injectable);
testChannelListenerInMain2Injectable.id += "2";
builder.beforeApplicationStart((mainDi) => {
runInAction(() => {
mainDi.register(testChannelListenerInMainInjectable);
mainDi.register(testChannelListenerInMain2Injectable);
});
});
});
await expect(applicationBuilder.render()).rejects.toThrow('Tried to register a multiple channel handlers for "some-request-channel-id", only one handler is supported for a request channel.');
afterEach(() => {
builder.quit();
});
it("throws on startup", async () => {
await expect(builder.render()).rejects.toThrow('Tried to register a multiple channel handlers for "some-request-channel-id", only one handler is supported for a request channel.');
});
});
});

View File

@ -12,32 +12,36 @@ import type { SyncBox } from "./sync-box-injection-token";
import { syncBoxInjectionToken } from "./sync-box-injection-token";
describe("sync-box", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(mainDi => {
builder.beforeApplicationStart(mainDi => {
runInAction(() => {
mainDi.register(someInjectable);
});
});
applicationBuilder.beforeWindowStart((windowDi) => {
builder.beforeWindowStart((windowDi) => {
runInAction(() => {
windowDi.register(someInjectable);
});
});
});
afterEach(() => {
builder.quit();
});
describe("given application is started, when value is set in main", () => {
let valueInMain: string;
let syncBoxInMain: SyncBox<string>;
beforeEach(async () => {
await applicationBuilder.startHidden();
await builder.startHidden();
syncBoxInMain = applicationBuilder.mainDi.inject(someInjectable);
syncBoxInMain = builder.mainDi.inject(someInjectable);
observe(syncBoxInMain.value, ({ newValue }) => {
valueInMain = newValue as string;
@ -59,7 +63,7 @@ describe("sync-box", () => {
beforeEach(async () => {
const applicationWindow =
applicationBuilder.applicationWindow.create("some-window-id");
builder.applicationWindow.create("some-window-id");
await applicationWindow.start();
@ -101,11 +105,11 @@ describe("sync-box", () => {
let syncBoxInRenderer: SyncBox<string>;
beforeEach(async () => {
await applicationBuilder.render();
await builder.render();
const applicationWindow = applicationBuilder.applicationWindow.only;
const applicationWindow = builder.applicationWindow.only;
syncBoxInMain = applicationBuilder.mainDi.inject(someInjectable);
syncBoxInMain = builder.mainDi.inject(someInjectable);
syncBoxInRenderer = applicationWindow.di.inject(someInjectable);
observe(syncBoxInRenderer.value, ({ newValue }) => {

View File

@ -8,13 +8,17 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
describe("add-cluster - navigation using application menu", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let rendered: RenderResult;
beforeEach(async () => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
@ -28,8 +32,8 @@ describe("add-cluster - navigation using application menu", () => {
});
describe("when navigating to add cluster using application menu", () => {
beforeEach(async () => {
await applicationBuilder.applicationMenu.click(
beforeEach(() => {
builder.applicationMenu.click(
"root",
"file",
"add-cluster",

View File

@ -62,6 +62,10 @@ describe("analytics for installing update", () => {
mainDi = builder.mainDi;
});
afterEach(() => {
builder.quit();
});
describe("given application is started and checking updates periodically", () => {
beforeEach(async () => {
mainDi.unoverride(periodicalCheckForUpdatesInjectable);

View File

@ -23,7 +23,7 @@ function daysToMilliseconds(days: number) {
}
describe("encourage user to update when sufficient time passed since update was downloaded", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
let downloadPlatformUpdateMock: AsyncFnMock<DownloadPlatformUpdate>;
let quitAndInstallUpdateMock: jest.MockedFunction<() => void>;
@ -31,9 +31,9 @@ describe("encourage user to update when sufficient time passed since update was
beforeEach(() => {
testUsingFakeTime("2015-10-21T07:28:00Z");
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart((mainDi) => {
builder.beforeApplicationStart((mainDi) => {
checkForPlatformUpdatesMock = asyncFn();
downloadPlatformUpdateMock = asyncFn();
@ -55,11 +55,15 @@ describe("encourage user to update when sufficient time passed since update was
});
});
afterEach(() => {
builder.quit();
});
describe("when started", () => {
let rendered: RenderResult;
beforeEach(async () => {
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
it("renders", () => {
@ -76,7 +80,7 @@ describe("encourage user to update when sufficient time passed since update was
let processCheckingForUpdates: (source: string) => Promise<{ updateIsReadyToBeInstalled: boolean }>;
beforeEach(async () => {
processCheckingForUpdates = applicationBuilder.mainDi.inject(
processCheckingForUpdates = builder.mainDi.inject(
processCheckingForUpdatesInjectable,
);
@ -106,9 +110,9 @@ describe("encourage user to update when sufficient time passed since update was
});
it("given closing the application window, when starting the application window again, still shows the button", async () => {
applicationBuilder.applicationWindow.closeAll();
builder.applicationWindow.closeAll();
const window = applicationBuilder.applicationWindow.create("some-window-id");
const window = builder.applicationWindow.create("some-window-id");
await window.start();

View File

@ -43,6 +43,10 @@ describe("installing update using tray", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("when started", () => {
let rendered: RenderResult;

View File

@ -24,7 +24,7 @@ const TIME_AFTER_UPDATE_MUST_BE_INSTALLED = 1000;
const TIME_AFTER_INSTALL_STARTS = 5 * 1000;
describe("force user to update when too long since update was downloaded", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
let downloadPlatformUpdateMock: AsyncFnMock<DownloadPlatformUpdate>;
let mainDi: DiContainer;
@ -33,9 +33,9 @@ describe("force user to update when too long since update was downloaded", () =>
beforeEach(() => {
testUsingFakeTime("2015-10-21T07:28:00Z");
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(mainDi => {
builder.beforeApplicationStart(mainDi => {
checkForPlatformUpdatesMock = asyncFn();
mainDi.override(checkForPlatformUpdatesInjectable, () => checkForPlatformUpdatesMock);
@ -49,7 +49,7 @@ describe("force user to update when too long since update was downloaded", () =>
mainDi.override(quitAndInstallUpdateInjectable, () => quitAndInstallUpdateMock);
});
applicationBuilder.beforeWindowStart(windowDi => {
builder.beforeWindowStart(windowDi => {
windowDi.unoverride(forceUpdateModalRootFrameComponentInjectable);
windowDi.permitSideEffects(forceUpdateModalRootFrameComponentInjectable);
@ -57,14 +57,18 @@ describe("force user to update when too long since update was downloaded", () =>
windowDi.override(secondsAfterInstallStartsInjectable, () => TIME_AFTER_INSTALL_STARTS / 1000);
});
mainDi = applicationBuilder.mainDi;
mainDi = builder.mainDi;
});
afterEach(() => {
builder.quit();
});
describe("when application is started", () => {
let rendered: RenderResult;
beforeEach(async () => {
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
describe("given checking for updates and it resolves, when update was downloaded", () => {

View File

@ -35,6 +35,10 @@ describe("periodical checking of updates", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("given updater is enabled and configuration exists, when started", () => {
let rendered: RenderResult;

View File

@ -73,6 +73,10 @@ describe("selection of update stability", () => {
mainDi = builder.mainDi;
});
afterEach(() => {
builder.quit();
});
describe("when started", () => {
let rendered: RenderResult;
let processCheckingForUpdates: (source: string) => Promise<{ updateIsReadyToBeInstalled: boolean }>;

View File

@ -17,14 +17,14 @@ import { updateChannels } from "./common/update-channels";
import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable";
describe("downgrading version update", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
let mainDi: DiContainer;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(mainDi => {
builder.beforeApplicationStart(mainDi => {
checkForPlatformUpdatesMock = asyncFn();
mainDi.override(
@ -36,7 +36,11 @@ describe("downgrading version update", () => {
mainDi.override(publishIsConfiguredInjectable, () => true);
});
mainDi = applicationBuilder.mainDi;
mainDi = builder.mainDi;
});
afterEach(() => {
builder.quit();
});
[
@ -104,7 +108,7 @@ describe("downgrading version update", () => {
it(`given application version "${appVersion}" and update channel "${updateChannel.id}", when checking for updates, can${downgradeIsAllowed ? "": "not"} downgrade`, async () => {
mainDi.override(getBuildVersionInjectable, () => () => appVersion);
await applicationBuilder.render();
await builder.render();
const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable);

View File

@ -61,6 +61,10 @@ describe("installing update", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("when started", () => {
let rendered: RenderResult;
let processCheckingForUpdates: (source: string) => Promise<{ updateIsReadyToBeInstalled: boolean }>;

View File

@ -104,6 +104,10 @@ describe("Deleting a cluster", () => {
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("when the kubeconfig has multiple clusters", () => {
let currentCluster: Cluster;
let nonCurrentCluster: Cluster;

View File

@ -47,6 +47,10 @@ describe("disable-cluster-pages-when-cluster-is-not-relevant", () => {
builder.extensions.get("test-extension-id").applicationWindows.only;
});
afterEach(() => {
builder.quit();
});
describe("given not yet known if extension should be enabled for the cluster, when navigating", () => {
beforeEach(() => {
rendererTestExtension.navigate();

View File

@ -53,6 +53,10 @@ describe("disable sidebar items when cluster is not relevant", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
describe("given not yet known if extension should be enabled for the cluster", () => {
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();

View File

@ -46,6 +46,10 @@ describe("reactively disable cluster pages", () => {
builder.extensions.get("test-extension-id").applicationWindows.only;
});
afterEach(() => {
builder.quit();
});
it("when navigating to the page, does not show the page", () => {
testExtensionInstance.navigate();

View File

@ -75,6 +75,10 @@ describe("disable kube object detail items when cluster is not relevant", () =>
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
describe("given not yet known if extension should be enabled for the cluster", () => {
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();

View File

@ -74,6 +74,11 @@ describe("reactively hide kube object detail item", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});

View File

@ -70,6 +70,10 @@ describe("disable kube object menu items when cluster is not relevant", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
describe("given not yet known if extension should be enabled for the cluster", () => {
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();

View File

@ -66,6 +66,10 @@ describe("reactively hide kube object menu item", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
it("does not show the kube object menu item", () => {
const actual = rendered.queryByTestId("some-kube-object-menu-item");

View File

@ -71,6 +71,10 @@ describe("disable kube object statuses when cluster is not relevant", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
describe("given not yet known if extension should be enabled for the cluster", () => {
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();

View File

@ -67,6 +67,10 @@ describe("reactively hide kube object status", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
it("does not show the kube object status", () => {
const actual = rendered.baseElement.querySelectorAll(
".KubeObjectStatusIcon",

View File

@ -110,6 +110,10 @@ describe("show status for a kube object", () => {
builder.setEnvironmentToClusterFrame();
});
afterEach(() => {
builder.quit();
});
describe("given application starts and in test page", () => {
let windowDi: DiContainer;
let rendered: RenderResult;

View File

@ -70,6 +70,10 @@ describe("cluster/namespaces - edit namespace from new tab", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("when navigating to namespaces", () => {
let rendered: RenderResult;
let windowDi: DiContainer;

View File

@ -41,6 +41,10 @@ describe("cluster/namespaces - edit namespaces from previously opened tab", () =
});
});
afterEach(() => {
builder.quit();
});
describe("given tab was previously opened, when application is started", () => {
let rendered: RenderResult;

View File

@ -28,6 +28,10 @@ describe("cluster - order of sidebar items", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("when rendered", () => {
beforeEach(async () => {
rendered = await builder.render();

View File

@ -40,6 +40,10 @@ describe("cluster - sidebar and tab navigation for core", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("given core registrations", () => {
beforeEach(() => {
builder.beforeWindowStart((windowDi) => {

View File

@ -23,17 +23,17 @@ import type { DiContainer } from "@ogre-tools/injectable";
import { flushPromises } from "../../common/test-utils/flush-promises";
describe("cluster - sidebar and tab navigation for extensions", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let rendered: RenderResult;
beforeEach(() => {
testUsingFakeTime("2015-10-21T07:28:00Z");
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
applicationBuilder.setEnvironmentToClusterFrame();
builder.setEnvironmentToClusterFrame();
applicationBuilder.beforeWindowStart((windowDi) => {
builder.beforeWindowStart((windowDi) => {
windowDi.override(storageSaveDelayInjectable, () => 250);
windowDi.override(
@ -43,6 +43,10 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("given extension with cluster pages and cluster page menus", () => {
let someObservable: IObservableValue<boolean>;
@ -125,14 +129,14 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
},
};
applicationBuilder.extensions.enable(testExtension);
builder.extensions.enable(testExtension);
});
describe("given no state for expanded sidebar items exists, and navigated to child sidebar item, when rendered", () => {
beforeEach(async () => {
rendered = await applicationBuilder.render();
rendered = await builder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
const windowDi = builder.applicationWindow.only.di;
const navigateToRoute = windowDi.inject(navigateToRouteInjectionToken);
@ -173,7 +177,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
describe("given state for expanded sidebar items already exists, when rendered", () => {
beforeEach(async () => {
applicationBuilder.beforeWindowStart(async (windowDi) => {
builder.beforeWindowStart(async (windowDi) => {
const writeJsonFileFake = windowDi.inject(writeJsonFileInjectable);
await writeJsonFileFake(
@ -187,7 +191,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
);
});
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
it("renders", () => {
@ -209,7 +213,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
describe("given state for expanded unknown sidebar items already exists, when rendered", () => {
beforeEach(async () => {
applicationBuilder.beforeWindowStart(async (windowDi) => {
builder.beforeWindowStart(async (windowDi) => {
const writeJsonFileFake = windowDi.inject(writeJsonFileInjectable);
await writeJsonFileFake(
@ -223,7 +227,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
);
});
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
it("renders without errors", () => {
@ -239,7 +243,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
describe("given empty state for expanded sidebar items already exists, when rendered", () => {
beforeEach(async () => {
applicationBuilder.beforeWindowStart(async (windowDi) => {
builder.beforeWindowStart(async (windowDi) => {
const writeJsonFileFake = windowDi.inject(writeJsonFileInjectable);
await writeJsonFileFake(
@ -250,7 +254,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
);
});
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
it("renders without errors", () => {
@ -268,9 +272,9 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
let windowDi: DiContainer;
beforeEach(async () => {
rendered = await applicationBuilder.render();
rendered = await builder.render();
windowDi = applicationBuilder.applicationWindow.only.di;
windowDi = builder.applicationWindow.only.di;
});
it("renders", () => {

View File

@ -33,6 +33,10 @@ describe("cluster - visibility of sidebar items", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("given kube resource for route is not allowed", () => {
beforeEach(async () => {
rendered = await builder.render();

View File

@ -57,6 +57,10 @@ describe("disable workloads overview details when cluster is not relevant", () =
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
describe("given not yet known if extension should be enabled for the cluster", () => {
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();

View File

@ -3,6 +3,7 @@
* 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";
import React from "react";
import getRandomIdInjectable from "../../../../../common/utils/get-random-id.injectable";
@ -12,9 +13,10 @@ import { computed, runInAction } from "mobx";
describe("order of workload overview details", () => {
let rendered: RenderResult;
let builder: ApplicationBuilder;
beforeEach(async () => {
const builder = getApplicationBuilder();
builder = getApplicationBuilder();
builder.beforeWindowStart((windowDi) => {
windowDi.unoverride(getRandomIdInjectable);
@ -78,6 +80,10 @@ describe("order of workload overview details", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
it("shows items in correct order", () => {
const actual = rendered.queryAllByTestId("workload-overview-detail").map(x => x.id);

View File

@ -54,6 +54,10 @@ describe("reactively hide workloads overview details item", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
it("does not show the workload overview detail item", () => {
const actual = rendered.queryByTestId("some-workload-overview-detail-item");

View File

@ -16,6 +16,10 @@ describe("Command Pallet: keyboard shortcut tests", () => {
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("when on macOS", () => {
beforeEach(async () => {
builder.beforeWindowStart((windowDi) => {

View File

@ -25,6 +25,10 @@ describe("extension special characters in page registrations", () => {
windowDi = builder.applicationWindow.only.di;
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});

View File

@ -28,6 +28,10 @@ describe("extensions - navigation using application menu", () => {
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});

View File

@ -58,6 +58,10 @@ describe("add custom helm repository in preferences", () => {
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("when navigating to preferences containing helm repositories", () => {
beforeEach(async () => {
builder.preferences.navigate();

View File

@ -50,6 +50,10 @@ describe("add helm repository from list in preferences", () => {
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("when navigating to preferences containing helm repositories", () => {
beforeEach(() => {
builder.preferences.navigate();

View File

@ -71,6 +71,10 @@ describe("installing helm chart from new tab", () => {
builder.namespaces.add("some-other-namespace");
});
afterEach(() => {
builder.quit();
});
describe("given tab for installing chart was not previously opened and application is started", () => {
let rendered: RenderResult;
let windowDi: DiContainer;

View File

@ -48,6 +48,10 @@ describe("installing helm chart from previously opened tab", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("given tab for installing chart was previously opened, when application is started", () => {
let rendered: RenderResult;

View File

@ -56,6 +56,10 @@ describe("opening dock tab for installing helm chart", () => {
builder.setEnvironmentToClusterFrame();
});
afterEach(() => {
builder.quit();
});
describe("given application is started, when navigating to helm charts", () => {
let rendered: RenderResult;

View File

@ -56,6 +56,10 @@ describe("listing active helm repositories in preferences", () => {
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("when navigating to preferences containing helm repositories", () => {
beforeEach(async () => {
builder.preferences.navigate();

View File

@ -41,6 +41,10 @@ describe("remove helm repository from list of active repositories in preferences
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("when navigating to preferences containing helm repositories", () => {
beforeEach(async () => {
builder.preferences.navigate();

View File

@ -64,6 +64,10 @@ describe("New Upgrade Helm Chart Dock Tab", () => {
dockStore.closeTab("terminal");
});
afterEach(() => {
builder.quit();
});
describe("given a namespace is selected", () => {
beforeEach(() => {
builder.namespaces.select("my-second-namespace");

View File

@ -83,6 +83,10 @@ describe("showing details for helm release", () => {
builder.namespaces.select("some-other-namespace");
});
afterEach(() => {
builder.quit();
});
describe("given application is started", () => {
let rendered: RenderResult;

View File

@ -9,6 +9,7 @@ import isEmpty from "lodash/isEmpty";
import queryParametersInjectable from "../renderer/routes/query-parameters.injectable";
import currentPathInjectable from "../renderer/routes/current-path.injectable";
import type { IComputedValue } from "mobx";
import type { ApplicationBuilder } from "../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../renderer/components/test-utils/get-application-builder";
import type { FakeExtensionOptions } from "../renderer/components/test-utils/get-extension-fake";
import type { LensRendererExtension } from "../extensions/lens-renderer-extension";
@ -18,9 +19,10 @@ describe("navigate to extension page", () => {
let testExtension: LensRendererExtension;
let queryParameters: IComputedValue<object>;
let currentPath: IComputedValue<string>;
let builder: ApplicationBuilder;
beforeEach(async () => {
const builder = getApplicationBuilder();
builder = getApplicationBuilder();
builder.extensions.enable(extensionWithPagesHavingParameters);
@ -35,6 +37,10 @@ describe("navigate to extension page", () => {
currentPath = windowDi.inject(currentPathInjectable);
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});

View File

@ -27,6 +27,10 @@ describe("navigating between routes", () => {
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given route without path parameters", () => {
let windowDi: DiContainer;

View File

@ -95,6 +95,10 @@ describe("download logs options in logs dock tab", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("opening pod logs", () => {
beforeEach(async () => {
rendered = await builder.render();

View File

@ -49,6 +49,10 @@ describe("preferences - closing-preferences", () => {
});
});
afterEach(() => {
builder.quit();
});
describe("given already in a page and then navigated to preferences", () => {
let rendered: RenderResult;
let windowDi: DiContainer;

View File

@ -18,6 +18,10 @@ describe("preferences: extension adding preference tabs", () => {
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when extension with preference tabs is enabled", () => {
let rendered: RenderResult;
let someObservable: IObservableValue<boolean>;

View File

@ -18,6 +18,10 @@ describe("preferences - navigation to application preferences", () => {
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when rendered", () => {
let rendered: RenderResult;
let discover: Discover;
@ -57,8 +61,7 @@ describe("preferences - navigation to application preferences", () => {
});
it("shows preference items of the extension as last", () => {
const { attributeValues } =
discover.queryAllElements("preference-item");
const { attributeValues } = discover.queryAllElements("preference-item");
expect(attributeValues.at(-1)).toBe("preference-item-for-extension-some-test-extension-name-item-some-application-preference-item-id");
});

View File

@ -9,23 +9,26 @@ import type { Discover } from "../../renderer/components/test-utils/discovery-of
import { discoverFor } from "../../renderer/components/test-utils/discovery-of-html-elements";
describe("preferences - navigation to editor preferences", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let discover: Discover;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when rendered", () => {
let rendered: RenderResult;
beforeEach(async () => {
applicationBuilder.beforeWindowStart(() => {
applicationBuilder.preferences.navigate();
builder.beforeWindowStart(() => {
builder.preferences.navigate();
});
rendered = await applicationBuilder.render();
rendered = await builder.render();
discover = discoverFor(() => rendered);
});
@ -43,7 +46,7 @@ describe("preferences - navigation to editor preferences", () => {
describe("when navigating to editor preferences using navigation", () => {
beforeEach(() => {
applicationBuilder.preferences.navigation.click("editor");
builder.preferences.navigation.click("editor");
});
it("renders", () => {

View File

@ -19,6 +19,10 @@ describe("preferences - navigation to extension specific preferences", () => {
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when rendered", () => {
let rendered: RenderResult;
let logErrorMock: jest.Mock;

View File

@ -17,6 +17,10 @@ describe("preferences - navigation to kubernetes preferences", () => {
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when rendered", () => {
let rendered: RenderResult;
let discover: Discover;

View File

@ -9,10 +9,14 @@ import type { Discover } from "../../renderer/components/test-utils/discovery-of
import { discoverFor } from "../../renderer/components/test-utils/discovery-of-html-elements";
describe("preferences - navigation to proxy preferences", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when rendered", () => {
@ -20,11 +24,11 @@ describe("preferences - navigation to proxy preferences", () => {
let discover: Discover;
beforeEach(async () => {
applicationBuilder.beforeWindowStart(() => {
applicationBuilder.preferences.navigate();
builder.beforeWindowStart(() => {
builder.preferences.navigate();
});
rendered = await applicationBuilder.render();
rendered = await builder.render();
discover = discoverFor(() => rendered);
});
@ -43,7 +47,7 @@ describe("preferences - navigation to proxy preferences", () => {
describe("when navigating to proxy preferences using navigation", () => {
beforeEach(() => {
applicationBuilder.preferences.navigation.click("proxy");
builder.preferences.navigation.click("proxy");
});
it("renders", () => {

View File

@ -19,6 +19,10 @@ describe("preferences - navigation to telemetry preferences", () => {
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when rendered", () => {
let rendered: RenderResult;
let discover: Discover;

View File

@ -9,10 +9,14 @@ import type { Discover } from "../../renderer/components/test-utils/discovery-of
import { discoverFor } from "../../renderer/components/test-utils/discovery-of-html-elements";
describe("preferences - navigation to terminal preferences", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given in preferences, when rendered", () => {
@ -20,12 +24,11 @@ describe("preferences - navigation to terminal preferences", () => {
let discover: Discover;
beforeEach(async () => {
applicationBuilder.beforeWindowStart(() => {
applicationBuilder.preferences.navigate();
builder.beforeWindowStart(() => {
builder.preferences.navigate();
});
rendered = await applicationBuilder.render();
rendered = await builder.render();
discover = discoverFor(() => rendered);
});
@ -44,7 +47,7 @@ describe("preferences - navigation to terminal preferences", () => {
describe("when navigating to terminal preferences using navigation", () => {
beforeEach(() => {
applicationBuilder.preferences.navigation.click("terminal");
builder.preferences.navigation.click("terminal");
});
it("renders", () => {

View File

@ -10,17 +10,21 @@ import type { Discover } from "../../renderer/components/test-utils/discovery-of
import { discoverFor } from "../../renderer/components/test-utils/discovery-of-html-elements";
describe("preferences - navigation using application menu", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let rendered: RenderResult;
let discover: Discover;
beforeEach(async () => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
rendered = await applicationBuilder.render();
rendered = await builder.render();
discover = discoverFor(() => rendered);
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});
@ -36,7 +40,7 @@ describe("preferences - navigation using application menu", () => {
describe("when navigating to preferences using application menu", () => {
beforeEach(() => {
applicationBuilder.applicationMenu.click(
builder.applicationMenu.click(
"root",
"mac",
"navigate-to-preferences",

View File

@ -9,17 +9,21 @@ import type { Discover } from "../../renderer/components/test-utils/discovery-of
import { discoverFor } from "../../renderer/components/test-utils/discovery-of-html-elements";
describe("show-about-using-tray", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let rendered: RenderResult;
let discover: Discover;
beforeEach(async () => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
rendered = await applicationBuilder.render();
rendered = await builder.render();
discover = discoverFor(() => rendered);
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
@ -35,7 +39,7 @@ describe("show-about-using-tray", () => {
describe("when navigating using tray", () => {
beforeEach(async () => {
await applicationBuilder.tray.click("open-preferences");
await builder.tray.click("open-preferences");
});
it("renders", () => {

View File

@ -75,6 +75,10 @@ describe("opening application window using tray", () => {
await builder.render();
});
afterEach(() => {
builder.quit();
});
it("only the first application window is open", () => {
expectWindowsToBeOpen(["first-application-window"]);
});

View File

@ -37,6 +37,10 @@ describe("quitting the app using application menu", () => {
await builder.render();
});
afterEach(() => {
builder.quit();
});
it("first application window is open", () => {
const windows = builder.applicationWindow.getAll();

View File

@ -31,6 +31,10 @@ describe("resolve-system-proxy", () => {
await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("given in main, when called with URL", () => {
beforeEach(async () => {
const resolveSystemProxyInMain = builder.mainDi.inject(

View File

@ -43,6 +43,10 @@ describe("reactively disable global pages", () => {
rendererTestExtension = builder.extensions.get("test-extension-id").applicationWindows.only;
});
afterEach(() => {
builder.quit();
});
it("when navigating to the page, does not show the page", () => {
rendererTestExtension.navigate();

View File

@ -11,22 +11,26 @@ import type { FakeExtensionOptions } from "../../renderer/components/test-utils/
import { computed } from "mobx";
describe("status-bar-items-originating-from-extensions", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
applicationBuilder.beforeWindowStart((windowDi) => {
builder.beforeWindowStart((windowDi) => {
windowDi.unoverride(getRandomIdInjectable);
windowDi.permitSideEffects(getRandomIdInjectable);
});
});
afterEach(() => {
builder.quit();
});
describe("when application starts", () => {
let rendered: RenderResult;
beforeEach(async () => {
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
it("when multiple extensions with status bar items are loaded, shows items in correct order", () => {
@ -62,7 +66,7 @@ describe("status-bar-items-originating-from-extensions", () => {
},
};
applicationBuilder.extensions.enable(testExtension1, testExtension2);
builder.extensions.enable(testExtension1, testExtension2);
const rightSide = rendered.getByTestId("status-bar-right");
@ -119,7 +123,7 @@ describe("status-bar-items-originating-from-extensions", () => {
},
};
applicationBuilder.extensions.enable(testExtensionOptions);
builder.extensions.enable(testExtensionOptions);
});
it("renders", () => {
@ -153,7 +157,7 @@ describe("status-bar-items-originating-from-extensions", () => {
});
it("when the extension is removed, shows there are no extension status bar items", () => {
applicationBuilder.extensions.disable(testExtensionOptions);
builder.extensions.disable(testExtensionOptions);
const actual = rendered.queryAllByTestId("some-testId");

View File

@ -545,7 +545,7 @@ exports[`test for opening terminal tab within cluster frame when new terminal ta
<span
aria-hidden="true"
class="xterm-char-measure-element"
style="font-size: 42px;"
style="font-family: RobotoMono; font-size: 12px;"
>
W
</span>

View File

@ -32,6 +32,10 @@ describe("test for opening terminal tab within cluster frame", () => {
result = await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("when new terminal tab is opened", () => {
beforeEach(() => {
result.getByTestId("dock-tab-for-terminal").click();

View File

@ -25,6 +25,10 @@ describe("clicking tray menu item originating from extension", () => {
await builder.render();
});
afterEach(() => {
builder.quit();
});
describe("when extension is enabled", () => {
let someExtension: FakeExtensionOptions;
let clickMock: jest.Mock;

View File

@ -85,6 +85,10 @@ describe("preferences: extension adding tray items", () => {
builder.extensions.enable(testExtension);
});
afterEach(() => {
builder.quit();
});
describe("given controlled label", () => {
it("has the label", () => {
const item = builder.tray.get(

View File

@ -20,6 +20,10 @@ describe("multiple separators originating from extension", () => {
await builder.render();
});
afterEach(() => {
builder.quit();
});
it("given extension with multiple separators, when extension is enabled, does not throw", () => {
const someExtension = {
id: "some-extension-id",

View File

@ -8,13 +8,17 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
describe("welcome - navigation using application menu", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let rendered: RenderResult;
beforeEach(async () => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
rendered = await applicationBuilder.render();
rendered = await builder.render();
});
afterEach(() => {
builder.quit();
});
it("renders", () => {
@ -29,7 +33,7 @@ describe("welcome - navigation using application menu", () => {
describe("when navigated somewhere else", () => {
beforeEach(() => {
applicationBuilder.applicationMenu.click(
builder.applicationMenu.click(
"root",
"mac",
"navigate-to-preferences",
@ -48,7 +52,7 @@ describe("welcome - navigation using application menu", () => {
describe("when navigated to welcome using application menu", () => {
beforeEach(() => {
applicationBuilder.applicationMenu.click(
builder.applicationMenu.click(
"root",
"help",
"navigate-to-welcome",

View File

@ -14,29 +14,33 @@ import type { Route } from "../../common/front-end-routing/front-end-route-injec
describe("setting-welcome-page", () => {
let applicationBuilder: ApplicationBuilder;
let builder: ApplicationBuilder;
let rendered : RenderResult;
let welcomeRoute: Route;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
builder = getApplicationBuilder();
});
afterEach(() => {
builder.quit();
});
describe("given configuration of welcome page route is the default", () => {
beforeEach(async () => {
applicationBuilder.beforeApplicationStart((mainDi) => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(welcomeRouteConfigInjectable, () => "/welcome");
});
applicationBuilder.beforeWindowStart((windowDi) => {
builder.beforeWindowStart((windowDi) => {
windowDi.override(welcomeRouteConfigInjectable, () => "/welcome");
});
// enable the extension even though the welcomeRoute is not overriden
applicationBuilder.extensions.enable(extensionWithWelcomePage);
rendered = await applicationBuilder.render();
builder.extensions.enable(extensionWithWelcomePage);
rendered = await builder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
const windowDi = builder.applicationWindow.only.di;
welcomeRoute = windowDi.inject(welcomeRouteInjectable);
});
@ -54,18 +58,18 @@ describe("setting-welcome-page", () => {
describe("given configuration of welcome page route is set to a custom page", () => {
beforeEach(async () => {
applicationBuilder.beforeApplicationStart((mainDi) => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(welcomeRouteConfigInjectable, () => "/extension/some-extension-name/some-welcome-page");
});
applicationBuilder.beforeWindowStart((windowDi) => {
builder.beforeWindowStart((windowDi) => {
windowDi.override(welcomeRouteConfigInjectable, () => "/extension/some-extension-name/some-welcome-page");
});
applicationBuilder.extensions.enable(extensionWithWelcomePage);
rendered = await applicationBuilder.render();
builder.extensions.enable(extensionWithWelcomePage);
rendered = await builder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
const windowDi = builder.applicationWindow.only.di;
welcomeRoute = windowDi.inject(welcomeRouteInjectable);
});

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeQuitOfBackEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
import lensProxyInjectable from "./lens-proxy.injectable";
const stopLensProxyOnQuitInjectable = getInjectable({
id: "stop-lens-proxy-on-quit",
instantiate: (di) => {
const lensProxy = di.inject(lensProxyInjectable);
return {
id: "stop-lens-proxy",
run: () => {
lensProxy.close();
},
};
},
injectionToken: beforeQuitOfBackEndInjectionToken,
});
export default stopLensProxyOnQuitInjectable;

View File

@ -82,8 +82,6 @@ const setupLensProxyInjectable = getInjectable({
};
},
// causesSideEffects: true,
injectionToken: beforeApplicationIsLoadingInjectionToken,
});

View File

@ -176,6 +176,7 @@ export class Terminal {
};
onClear = () => {
console.log("clearing");
this.xterm.clear();
};

View File

@ -39,6 +39,10 @@ describe("<StatusBar />", () => {
});
});
afterEach(() => {
builder.quit();
});
it("renders w/o errors", async () => {
const { container } = await builder.render();

View File

@ -71,6 +71,8 @@ import createClusterInjectable from "../../../main/create-cluster/create-cluster
import { onLoadOfApplicationInjectionToken } from "../../../main/start-main-application/runnable-tokens/on-load-of-application-injection-token";
import currentLocationInjectable from "../../api/current-location.injectable";
import lensProxyPortInjectable from "../../../main/lens-proxy/lens-proxy-port.injectable";
import { runManyFor } from "../../../common/runnable/run-many-for";
import { beforeQuitOfBackEndInjectionToken } from "../../../main/start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
type Callback = (di: DiContainer) => void | Promise<void>;
@ -122,6 +124,7 @@ export interface ApplicationBuilder {
startHidden: () => Promise<void>;
render: () => Promise<RenderResult>;
quit: () => void;
tray: {
click: (id: string) => Promise<void>;
@ -703,6 +706,13 @@ export const getApplicationBuilder = () => {
await startApplication({ shouldStartHidden: true });
},
quit() {
const runMany = runManyFor(builder.mainDi);
const beforeQuitOfBackEnd = runMany(beforeQuitOfBackEndInjectionToken);
beforeQuitOfBackEnd();
},
async render() {
await startApplication({ shouldStartHidden: false });