mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
import {
|
|
createContainer,
|
|
DiContainer,
|
|
getInjectable,
|
|
} from "@ogre-tools/injectable";
|
|
import { registerFeature } from "@k8slens/feature-core";
|
|
import { applicationFeatureForElectronMain } from "./applicationFeatureForElectronMain";
|
|
import {
|
|
beforeApplicationIsLoadingInjectionToken,
|
|
startApplicationInjectionToken,
|
|
} from "@k8slens/application";
|
|
import asyncFn, { AsyncFnMock } from "@async-fn/jest";
|
|
import whenAppIsReadyInjectable from "./start-application/when-app-is-ready.injectable";
|
|
import { beforeAnythingInjectionToken } from "./start-application/timeslots/before-anything-injection-token";
|
|
import { beforeElectronIsReadyInjectionToken } from "./start-application/timeslots/before-electron-is-ready-injection-token";
|
|
|
|
describe("starting-of-electron-main-application", () => {
|
|
let di: DiContainer;
|
|
let beforeAnythingMock: jest.Mock;
|
|
let beforeElectronIsReadyMock: jest.Mock;
|
|
let beforeApplicationIsLoadingMock: AsyncFnMock<() => Promise<void>>;
|
|
let whenAppIsReadyMock: AsyncFnMock<() => Promise<void>>;
|
|
|
|
beforeEach(() => {
|
|
di = createContainer("irrelevant");
|
|
|
|
beforeAnythingMock = jest.fn();
|
|
beforeElectronIsReadyMock = jest.fn();
|
|
|
|
beforeApplicationIsLoadingMock = asyncFn();
|
|
whenAppIsReadyMock = asyncFn();
|
|
|
|
registerFeature(di, applicationFeatureForElectronMain);
|
|
|
|
const beforeAnythingIsLoadingInjectable = getInjectable({
|
|
id: "before-anything",
|
|
instantiate: () => ({ run: beforeAnythingMock }),
|
|
injectionToken: beforeAnythingInjectionToken,
|
|
});
|
|
|
|
const beforeElectronIsReadyIsLoadingInjectable = getInjectable({
|
|
id: "before-electron-is-ready",
|
|
instantiate: () => ({ run: beforeElectronIsReadyMock }),
|
|
injectionToken: beforeElectronIsReadyInjectionToken,
|
|
});
|
|
|
|
const beforeApplicationIsLoadingInjectable = getInjectable({
|
|
id: "before-application-is-loading",
|
|
instantiate: () => ({ run: beforeApplicationIsLoadingMock }),
|
|
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
|
});
|
|
|
|
di.register(
|
|
beforeAnythingIsLoadingInjectable,
|
|
beforeElectronIsReadyIsLoadingInjectable,
|
|
beforeApplicationIsLoadingInjectable
|
|
);
|
|
|
|
di.override(whenAppIsReadyInjectable, () => whenAppIsReadyMock);
|
|
});
|
|
|
|
describe("when application is started", () => {
|
|
beforeEach(() => {
|
|
const startApplication = di.inject(startApplicationInjectionToken);
|
|
|
|
startApplication();
|
|
});
|
|
|
|
it("calls for synchronous runnables for before anything", () => {
|
|
expect(beforeAnythingMock).toHaveBeenCalled();
|
|
});
|
|
|
|
it("calls for synchronous runnables for before electron is ready", () => {
|
|
expect(beforeElectronIsReadyMock).toHaveBeenCalled();
|
|
});
|
|
it("calls to wait when electron is ready", () => {
|
|
expect(whenAppIsReadyMock).toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not call runnables for before application is loading yet", () => {
|
|
expect(beforeApplicationIsLoadingMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
describe("when electron is ready", () => {
|
|
beforeEach(async () => {
|
|
await whenAppIsReadyMock.resolve();
|
|
});
|
|
|
|
it("calls runnables for before application is loading", () => {
|
|
expect(beforeApplicationIsLoadingMock).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|
|
});
|