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

Fix tests by adding getBuildVersionInjectable as an easy override point

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-09-15 14:23:12 -04:00
parent 71e7a3d360
commit 593271b339
5 changed files with 43 additions and 48 deletions

View File

@ -19,7 +19,7 @@ import quitAndInstallUpdateInjectable from "../../main/application-update/quit-a
import periodicalCheckForUpdatesInjectable from "../../main/application-update/periodical-check-for-updates/periodical-check-for-updates.injectable";
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable";
import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable";
describe("analytics for installing update", () => {
let builder: ApplicationBuilder;
@ -36,9 +36,7 @@ describe("analytics for installing update", () => {
analyticsListenerMock = jest.fn();
builder.beforeApplicationStart(mainDi => {
mainDi.override(buildVersionInjectable, () => ({
get: () => "42.0.0",
}));
mainDi.override(getBuildVersionInjectable, () => () => "42.0.0");
checkForPlatformUpdatesMock = asyncFn();

View File

@ -14,7 +14,7 @@ import processCheckingForUpdatesInjectable from "../../main/application-update/c
import selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import { updateChannels } from "../../common/application-update/update-channels";
import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable";
import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable";
describe("downgrading version update", () => {
let applicationBuilder: ApplicationBuilder;
@ -102,9 +102,7 @@ describe("downgrading version update", () => {
},
].forEach(({ appVersion, updateChannel, downgradeIsAllowed }) => {
it(`given application version "${appVersion}" and update channel "${updateChannel.id}", when checking for updates, can${downgradeIsAllowed ? "": "not"} downgrade`, async () => {
mainDi.override(buildVersionInjectable, () => ({
get: () => appVersion,
}));
mainDi.override(getBuildVersionInjectable, () => () => appVersion);
await applicationBuilder.render();

View File

@ -22,7 +22,7 @@ import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-upda
import showInfoNotificationInjectable from "../../renderer/components/notifications/show-info-notification.injectable";
import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable";
import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable";
describe("selection of update stability", () => {
let builder: ApplicationBuilder;
@ -231,16 +231,12 @@ describe("selection of update stability", () => {
});
it("given valid update channel selection is stored, when checking for updates, checks for updates from the update channel", async () => {
builder.beforeApplicationStart((mainDi) => {
// TODO: Switch to more natural way of setting initial value
// TODO: UserStore is currently responsible for getting and setting initial value
const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable);
selectedUpdateChannel.setValue(updateChannels.beta.id);
});
await builder.render();
// TODO: Switch to more natural way of setting initial value
// TODO: UserStore is currently responsible for getting and setting initial value
mainDi.inject(selectedUpdateChannelInjectable).setValue(updateChannels.beta.id);
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant");
@ -249,16 +245,12 @@ describe("selection of update stability", () => {
});
it("given invalid update channel selection is stored, when checking for updates, checks for updates from the update channel", async () => {
builder.beforeApplicationStart((mainDi) => {
// TODO: Switch to more natural way of setting initial value
// TODO: UserStore is currently responsible for getting and setting initial value
const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable);
selectedUpdateChannel.setValue("something-invalid" as ReleaseChannel);
});
await builder.render();
// TODO: Switch to more natural way of setting initial value
// TODO: UserStore is currently responsible for getting and setting initial value
mainDi.inject(selectedUpdateChannelInjectable).setValue("something-invalid" as ReleaseChannel);
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant");
@ -268,9 +260,7 @@ describe("selection of update stability", () => {
it('given no update channel selection is stored and currently using stable release, when user checks for updates, checks for updates from "latest" update channel by default', async () => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(buildVersionInjectable, () => ({
get: () => "1.0.0",
}));
mainDi.override(getBuildVersionInjectable, () => () => "1.0.0");
});
await builder.render();
@ -287,9 +277,7 @@ describe("selection of update stability", () => {
it('given no update channel selection is stored and currently using alpha release, when checking for updates, checks for updates from "alpha" channel', async () => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(buildVersionInjectable, () => ({
get: () => "1.0.0-alpha",
}));
mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-alpha");
});
await builder.render();
@ -303,9 +291,7 @@ describe("selection of update stability", () => {
it('given no update channel selection is stored and currently using beta release, when checking for updates, checks for updates from "beta" channel', async () => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(buildVersionInjectable, () => ({
get: () => "1.0.0-beta",
}));
mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-beta");
});
await builder.render();
@ -318,20 +304,12 @@ describe("selection of update stability", () => {
});
it("given update channel selection is stored and currently using prerelease, when checking for updates, checks for updates from stored channel", async () => {
builder.beforeApplicationStart((mainDi) => {
mainDi.override(buildVersionInjectable, () => ({
get: () => "1.0.0-alpha",
}));
// TODO: Switch to more natural way of setting initial value
// TODO: UserStore is currently responsible for getting and setting initial value
const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable);
selectedUpdateChannel.setValue(updateChannels.beta.id);
});
await builder.render();
// TODO: Switch to more natural way of setting initial value
// TODO: UserStore is currently responsible for getting and setting initial value
mainDi.inject(selectedUpdateChannelInjectable).setValue(updateChannels.beta.id);
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant");

View File

@ -4,11 +4,15 @@
*/
import { createInitializableState } from "../../../common/initializable-state/create";
import { buildVersionInjectionToken } from "../../../common/vars/build-semantic-version.injectable";
import electronAppInjectable from "../../electron-app/electron-app.injectable";
import getBuildVersionInjectable from "./get-build-version.injectable";
const buildVersionInjectable = createInitializableState({
id: "build-version",
init: (di) => di.inject(electronAppInjectable).getVersion(),
init: (di) => {
const getBuildVersion = di.inject(getBuildVersionInjectable);
return getBuildVersion();
},
injectionToken: buildVersionInjectionToken,
});

View File

@ -0,0 +1,17 @@
/**
* 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 electronAppInjectable from "../../electron-app/electron-app.injectable";
const getBuildVersionInjectable = getInjectable({
id: "get-build-version",
instantiate: (di) => {
const electronApp = di.inject(electronAppInjectable);
return () => electronApp.getVersion();
},
});
export default getBuildVersionInjectable;