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:
parent
71e7a3d360
commit
593271b339
@ -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 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 { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
|
||||||
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
|
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", () => {
|
describe("analytics for installing update", () => {
|
||||||
let builder: ApplicationBuilder;
|
let builder: ApplicationBuilder;
|
||||||
@ -36,9 +36,7 @@ describe("analytics for installing update", () => {
|
|||||||
analyticsListenerMock = jest.fn();
|
analyticsListenerMock = jest.fn();
|
||||||
|
|
||||||
builder.beforeApplicationStart(mainDi => {
|
builder.beforeApplicationStart(mainDi => {
|
||||||
mainDi.override(buildVersionInjectable, () => ({
|
mainDi.override(getBuildVersionInjectable, () => () => "42.0.0");
|
||||||
get: () => "42.0.0",
|
|
||||||
}));
|
|
||||||
|
|
||||||
checkForPlatformUpdatesMock = asyncFn();
|
checkForPlatformUpdatesMock = asyncFn();
|
||||||
|
|
||||||
|
|||||||
@ -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 selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import { updateChannels } from "../../common/application-update/update-channels";
|
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", () => {
|
describe("downgrading version update", () => {
|
||||||
let applicationBuilder: ApplicationBuilder;
|
let applicationBuilder: ApplicationBuilder;
|
||||||
@ -102,9 +102,7 @@ describe("downgrading version update", () => {
|
|||||||
},
|
},
|
||||||
].forEach(({ appVersion, updateChannel, downgradeIsAllowed }) => {
|
].forEach(({ appVersion, updateChannel, downgradeIsAllowed }) => {
|
||||||
it(`given application version "${appVersion}" and update channel "${updateChannel.id}", when checking for updates, can${downgradeIsAllowed ? "": "not"} downgrade`, async () => {
|
it(`given application version "${appVersion}" and update channel "${updateChannel.id}", when checking for updates, can${downgradeIsAllowed ? "": "not"} downgrade`, async () => {
|
||||||
mainDi.override(buildVersionInjectable, () => ({
|
mainDi.override(getBuildVersionInjectable, () => () => appVersion);
|
||||||
get: () => appVersion,
|
|
||||||
}));
|
|
||||||
|
|
||||||
await applicationBuilder.render();
|
await applicationBuilder.render();
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-upda
|
|||||||
import showInfoNotificationInjectable from "../../renderer/components/notifications/show-info-notification.injectable";
|
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 processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/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", () => {
|
describe("selection of update stability", () => {
|
||||||
let builder: ApplicationBuilder;
|
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 () => {
|
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();
|
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);
|
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
|
||||||
|
|
||||||
processCheckingForUpdates("irrelevant");
|
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 () => {
|
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();
|
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);
|
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
|
||||||
|
|
||||||
processCheckingForUpdates("irrelevant");
|
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 () => {
|
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) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(buildVersionInjectable, () => ({
|
mainDi.override(getBuildVersionInjectable, () => () => "1.0.0");
|
||||||
get: () => "1.0.0",
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await builder.render();
|
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 () => {
|
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) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(buildVersionInjectable, () => ({
|
mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-alpha");
|
||||||
get: () => "1.0.0-alpha",
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await builder.render();
|
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 () => {
|
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) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(buildVersionInjectable, () => ({
|
mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-beta");
|
||||||
get: () => "1.0.0-beta",
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await builder.render();
|
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 () => {
|
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();
|
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);
|
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
|
||||||
|
|
||||||
processCheckingForUpdates("irrelevant");
|
processCheckingForUpdates("irrelevant");
|
||||||
|
|||||||
@ -4,11 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
import { createInitializableState } from "../../../common/initializable-state/create";
|
import { createInitializableState } from "../../../common/initializable-state/create";
|
||||||
import { buildVersionInjectionToken } from "../../../common/vars/build-semantic-version.injectable";
|
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({
|
const buildVersionInjectable = createInitializableState({
|
||||||
id: "build-version",
|
id: "build-version",
|
||||||
init: (di) => di.inject(electronAppInjectable).getVersion(),
|
init: (di) => {
|
||||||
|
const getBuildVersion = di.inject(getBuildVersionInjectable);
|
||||||
|
|
||||||
|
return getBuildVersion();
|
||||||
|
},
|
||||||
injectionToken: buildVersionInjectionToken,
|
injectionToken: buildVersionInjectionToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
17
src/main/vars/build-version/get-build-version.injectable.ts
Normal file
17
src/main/vars/build-version/get-build-version.injectable.ts
Normal 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;
|
||||||
Loading…
Reference in New Issue
Block a user