1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/features/application-menu/application-menu.test.ts
Iku-turso b93bea359b Simplify overriding of platform in a unit test
Also make typing of platforms more strict, and remove some magic strings.
Also add a TODO for further OCP-ification.

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
2022-10-26 11:34:55 +03:00

60 lines
2.0 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import populateApplicationMenuInjectable from "./main/populate-application-menu.injectable";
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
import { getCompositePaths } from "../../common/utils/composite/get-composite-paths/get-composite-paths";
import platformInjectable, { allPlatforms } from "../../common/vars/platform.injectable";
describe.each(allPlatforms)("application-menu, given platform is '%s'", (platform) => {
let builder: ApplicationBuilder;
let populateApplicationMenuMock: jest.Mock;
beforeEach(async () => {
useFakeTime();
populateApplicationMenuMock = jest.fn();
builder = getApplicationBuilder();
builder.beforeApplicationStart((mainDi) => {
mainDi.override(platformInjectable, () => platform);
mainDi.override(
populateApplicationMenuInjectable,
() => populateApplicationMenuMock,
);
});
await builder.startHidden();
});
it("when insufficient time passes, does not populate menu items yet", () => {
advanceFakeTime(99);
expect(populateApplicationMenuMock).not.toHaveBeenCalled();
});
describe("given enough time passes", () => {
let applicationMenuPaths: string[][];
beforeEach(() => {
advanceFakeTime(100);
applicationMenuPaths = getCompositePaths(
populateApplicationMenuMock.mock.calls[0][0],
);
});
it("populates application menu with at least something", () => {
expect(applicationMenuPaths.length).toBeGreaterThan(0);
});
it("populates application menu", () => {
expect(applicationMenuPaths.map(x => x.join(" -> "))).toMatchSnapshot();
});
});
});