Replace static application window with ability to create many (#5979)

* Replace static application window with ability to create as many as you wish

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Adapt tests for replacing static application window with ability to create as many as you wish and separate starting of main and window in behaviours

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Make first render of application smaller in test that proves to be hard for CI

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove redundant code

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Simplify code

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen authored and GitHub committed 2022-08-16 15:55:42 +03:00
1 parent 299922c8a7
commit 63d5a34379
98 files changed
+3283 -2743

No files matched your search

+19 -14
View File
@@ -14,15 +14,10 @@ import { getApplicationBuilder } from "../../renderer/components/test-utils/get-
import type { DiContainer } from "@ogre-tools/injectable";
describe("app-paths", () => {
let applicationBuilder: ApplicationBuilder;
let rendererDi: DiContainer;
let mainDi: DiContainer;
let builder: ApplicationBuilder;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
rendererDi = applicationBuilder.dis.rendererDi;
mainDi = applicationBuilder.dis.mainDi;
builder = getApplicationBuilder();
const defaultAppPathsStub: AppPaths = {
appData: "some-app-data",
@@ -43,7 +38,7 @@ describe("app-paths", () => {
userData: "some-irrelevant-user-data",
};
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(
getElectronAppPathInjectable,
() =>
@@ -64,12 +59,18 @@ describe("app-paths", () => {
});
describe("normally", () => {
let windowDi: DiContainer;
let mainDi: DiContainer;
beforeEach(async () => {
await applicationBuilder.render();
await builder.render();
windowDi = builder.applicationWindow.only.di;
mainDi = builder.mainDi;
});
it("given in renderer, when injecting app paths, returns application specific app paths", () => {
const actual = rendererDi.inject(appPathsInjectionToken);
const actual = windowDi.inject(appPathsInjectionToken);
expect(actual).toEqual({
appData: "some-app-data",
@@ -116,19 +117,23 @@ describe("app-paths", () => {
});
describe("when running integration tests", () => {
let windowDi: DiContainer;
beforeEach(async () => {
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(
directoryForIntegrationTestingInjectable,
() => "some-integration-testing-app-data",
);
});
await applicationBuilder.render();
await builder.render();
windowDi = builder.applicationWindow.only.di;
});
it("given in renderer, when injecting path for app data, has integration specific app data path", () => {
const { appData, userData } = rendererDi.inject(appPathsInjectionToken);
const { appData, userData } = windowDi.inject(appPathsInjectionToken);
expect({ appData, userData }).toEqual({
appData: "some-integration-testing-app-data",
@@ -137,7 +142,7 @@ describe("app-paths", () => {
});
it("given in main, when injecting path for app data, has integration specific app data path", () => {
const { appData, userData } = rendererDi.inject(appPathsInjectionToken);
const { appData, userData } = windowDi.inject(appPathsInjectionToken);
expect({ appData, userData }).toEqual({
appData: "some-integration-testing-app-data",
@@ -0,0 +1,17 @@
/**
* 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 clusterStoreInjectable from "./cluster-store.injectable";
import type { Cluster } from "../cluster/cluster";
import type { ClusterStore } from "./cluster-store";
export default getGlobalOverride(
clusterStoreInjectable,
() =>
({
provideInitialFromMain: () => {},
getById: (id) => (void id, {}) as Cluster,
} as ClusterStore),
);
+46 -82
View File
@@ -4,13 +4,11 @@
*/
import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { LensWindow } from "../../../main/start-main-application/lens-window/application-window/lens-window-injection-token";
import { lensWindowInjectionToken } from "../../../main/start-main-application/lens-window/application-window/lens-window-injection-token";
import type { MessageToChannel } from "./message-to-channel-injection-token";
import { messageToChannelInjectionToken } from "./message-to-channel-injection-token";
import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import createLensWindowInjectable from "../../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
import closeAllWindowsInjectable from "../../../main/start-main-application/lens-window/hide-all-windows/close-all-windows.injectable";
import type { LensWindow } from "../../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
import type { MessageChannel } from "./message-channel-injection-token";
import type { RequestFromChannel } from "./request-from-channel-injection-token";
@@ -30,12 +28,10 @@ describe("channel", () => {
let messageListenerInWindowMock: jest.Mock;
let mainDi: DiContainer;
let messageToChannel: MessageToChannel;
let builder: ApplicationBuilder;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
mainDi = applicationBuilder.dis.mainDi;
const rendererDi = applicationBuilder.dis.rendererDi;
builder = getApplicationBuilder();
messageListenerInWindowMock = jest.fn();
@@ -44,37 +40,34 @@ describe("channel", () => {
instantiate: (di) => ({
channel: di.inject(testMessageChannelInjectable),
handler: messageListenerInWindowMock,
}),
injectionToken: messageChannelListenerInjectionToken,
});
rendererDi.register(testChannelListenerInTestWindowInjectable);
builder.beforeApplicationStart((mainDi) => {
mainDi.register(testMessageChannelInjectable);
});
// Notice how test channel has presence in both DIs, being from common
mainDi.register(testMessageChannelInjectable);
rendererDi.register(testMessageChannelInjectable);
builder.beforeWindowStart((windowDi) => {
windowDi.register(testChannelListenerInTestWindowInjectable);
windowDi.register(testMessageChannelInjectable);
});
mainDi = builder.mainDi;
await builder.startHidden();
testMessageChannel = mainDi.inject(testMessageChannelInjectable);
messageToChannel = mainDi.inject(
messageToChannelInjectionToken,
);
await applicationBuilder.render();
const closeAllWindows = mainDi.inject(closeAllWindowsInjectable);
closeAllWindows();
messageToChannel = mainDi.inject(messageToChannelInjectionToken);
});
describe("given window is started", () => {
let someWindowFake: LensWindow;
beforeEach(async () => {
someWindowFake = createTestWindow(mainDi, "some-window");
someWindowFake = builder.applicationWindow.create("some-window");
await someWindowFake.start();
});
@@ -95,8 +88,8 @@ describe("channel", () => {
});
it("given multiple started windows, when sending message, triggers listeners in all windows", async () => {
const someWindowFake = createTestWindow(mainDi, "some-window");
const someOtherWindowFake = createTestWindow(mainDi, "some-other-window");
const someWindowFake = builder.applicationWindow.create("some-window");
const someOtherWindowFake = builder.applicationWindow.create("some-other-window");
await someWindowFake.start();
await someOtherWindowFake.start();
@@ -113,16 +106,11 @@ describe("channel", () => {
describe("messaging from renderer to main, given listener for channel in a main and application has started", () => {
let testMessageChannel: TestMessageChannel;
let messageListenerInMainMock: jest.Mock;
let rendererDi: DiContainer;
let mainDi: DiContainer;
let messageToChannel: MessageToChannel;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
mainDi = applicationBuilder.dis.mainDi;
rendererDi = applicationBuilder.dis.rendererDi;
messageListenerInMainMock = jest.fn();
const testChannelListenerInMainInjectable = getInjectable({
@@ -137,19 +125,21 @@ describe("channel", () => {
injectionToken: messageChannelListenerInjectionToken,
});
mainDi.register(testChannelListenerInMainInjectable);
applicationBuilder.beforeApplicationStart((mainDi) => {
mainDi.register(testChannelListenerInMainInjectable);
mainDi.register(testMessageChannelInjectable);
});
// Notice how test channel has presence in both DIs, being from common
mainDi.register(testMessageChannelInjectable);
rendererDi.register(testMessageChannelInjectable);
testMessageChannel = rendererDi.inject(testMessageChannelInjectable);
messageToChannel = rendererDi.inject(
messageToChannelInjectionToken,
);
applicationBuilder.beforeWindowStart((windowDi) => {
windowDi.register(testMessageChannelInjectable);
});
await applicationBuilder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
testMessageChannel = windowDi.inject(testMessageChannelInjectable);
messageToChannel = windowDi.inject(messageToChannelInjectionToken);
});
it("when sending message, triggers listener in main", () => {
@@ -162,16 +152,11 @@ describe("channel", () => {
describe("requesting from main in renderer, given listener for channel in a main and application has started", () => {
let testRequestChannel: TestRequestChannel;
let requestListenerInMainMock: AsyncFnMock<(arg: string) => string>;
let rendererDi: DiContainer;
let mainDi: DiContainer;
let requestFromChannel: RequestFromChannel;
beforeEach(async () => {
const applicationBuilder = getApplicationBuilder();
mainDi = applicationBuilder.dis.mainDi;
rendererDi = applicationBuilder.dis.rendererDi;
requestListenerInMainMock = asyncFn();
const testChannelListenerInMainInjectable = getInjectable({
@@ -186,19 +171,24 @@ describe("channel", () => {
injectionToken: requestChannelListenerInjectionToken,
});
mainDi.register(testChannelListenerInMainInjectable);
applicationBuilder.beforeApplicationStart((mainDi) => {
mainDi.register(testChannelListenerInMainInjectable);
mainDi.register(testRequestChannelInjectable);
});
// Notice how test channel has presence in both DIs, being from common
mainDi.register(testRequestChannelInjectable);
rendererDi.register(testRequestChannelInjectable);
testRequestChannel = rendererDi.inject(testRequestChannelInjectable);
requestFromChannel = rendererDi.inject(
requestFromChannelInjectionToken,
);
applicationBuilder.beforeWindowStart((windowDi) => {
windowDi.register(testRequestChannelInjectable);
});
await applicationBuilder.render();
const windowDi = applicationBuilder.applicationWindow.only.di;
testRequestChannel = windowDi.inject(testRequestChannelInjectable);
requestFromChannel = windowDi.inject(
requestFromChannelInjectionToken,
);
});
describe("when requesting from channel", () => {
@@ -245,29 +235,3 @@ const testRequestChannelInjectable = getInjectable({
}),
});
const createTestWindow = (di: DiContainer, id: string) => {
const testWindowInjectable = getInjectable({
id,
instantiate: (di) => {
const createLensWindow = di.inject(createLensWindowInjectable);
return createLensWindow({
id,
title: "Some test window",
defaultHeight: 42,
defaultWidth: 42,
getContentSource: () => ({ url: "some-content-url" }),
resizable: true,
windowFrameUtilitiesAreShown: false,
centered: false,
});
},
injectionToken: lensWindowInjectionToken,
});
di.register(testWindowInjectable);
return di.inject(testWindowInjectable);
};
+31 -42
View File
@@ -2,13 +2,14 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import { observe, runInAction } from "mobx";
import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import createSyncBoxInjectable from "./create-sync-box.injectable";
import { flushPromises } from "../../test-utils/flush-promises";
import type { SyncBox } from "./sync-box-injection-token";
import { syncBoxInjectionToken } from "./sync-box-injection-token";
describe("sync-box", () => {
let applicationBuilder: ApplicationBuilder;
@@ -16,19 +17,23 @@ describe("sync-box", () => {
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
applicationBuilder.dis.mainDi.register(someInjectable);
applicationBuilder.dis.rendererDi.register(someInjectable);
applicationBuilder.beforeApplicationStart(mainDi => {
mainDi.register(someInjectable);
});
applicationBuilder.beforeWindowStart((windowDi) => {
windowDi.register(someInjectable);
});
});
// TODO: Separate starting for main application and starting of window in application builder
xdescribe("given application is started, when value is set in main", () => {
describe("given application is started, when value is set in main", () => {
let valueInMain: string;
let syncBoxInMain: SyncBox<string>;
beforeEach(async () => {
syncBoxInMain = applicationBuilder.dis.mainDi.inject(someInjectable);
await applicationBuilder.startHidden();
// await applicationBuilder.start();
syncBoxInMain = applicationBuilder.mainDi.inject(someInjectable);
observe(syncBoxInMain.value, ({ newValue }) => {
valueInMain = newValue as string;
@@ -46,48 +51,28 @@ describe("sync-box", () => {
describe("when window starts", () => {
let valueInRenderer: string;
let syncBoxInRenderer: SyncBox<string>;
let rendererDi: DiContainer;
beforeEach(() => {
// applicationBuilder.renderWindow()
beforeEach(async () => {
const applicationWindow =
applicationBuilder.applicationWindow.create("some-window-id");
syncBoxInRenderer = applicationBuilder.dis.rendererDi.inject(someInjectable);
await applicationWindow.start();
rendererDi = applicationWindow.di;
syncBoxInRenderer = rendererDi.inject(someInjectable);
observe(syncBoxInRenderer.value, ({ newValue }) => {
valueInRenderer = newValue as string;
}, true);
});
it("does not have the initial value yet", () => {
expect(valueInRenderer).toBe(undefined);
it("has the value from main", () => {
expect(valueInRenderer).toBe("some-value-from-main");
});
describe("when getting initial value resolves", () => {
beforeEach(async () => {
await flushPromises();
});
it("has value in renderer", () => {
expect(valueInRenderer).toBe("some-value-from-main");
});
describe("when value is set from renderer", () => {
beforeEach(() => {
runInAction(() => {
syncBoxInRenderer.set("some-value-from-renderer");
});
});
it("has value in main", () => {
expect(valueInMain).toBe("some-value-from-renderer");
});
it("has value in renderer", () => {
expect(valueInRenderer).toBe("some-value-from-renderer");
});
});
});
describe("when value is set from renderer before getting initial value from main resolves", () => {
describe("when value is set from renderer", () => {
beforeEach(() => {
runInAction(() => {
syncBoxInRenderer.set("some-value-from-renderer");
@@ -112,11 +97,13 @@ describe("sync-box", () => {
let syncBoxInRenderer: SyncBox<string>;
beforeEach(async () => {
syncBoxInMain = applicationBuilder.dis.mainDi.inject(someInjectable);
syncBoxInRenderer = applicationBuilder.dis.rendererDi.inject(someInjectable);
await applicationBuilder.render();
const applicationWindow = applicationBuilder.applicationWindow.only;
syncBoxInMain = applicationBuilder.mainDi.inject(someInjectable);
syncBoxInRenderer = applicationWindow.di.inject(someInjectable);
observe(syncBoxInRenderer.value, ({ newValue }) => {
valueInRenderer = newValue as string;
}, true);
@@ -176,4 +163,6 @@ const someInjectable = getInjectable({
return createSyncBox("some-sync-box", "some-initial-value");
},
injectionToken: syncBoxInjectionToken,
});