From 43cedae7b05eaa7f932f2718939f7b856a1b86c5 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 25 Apr 2023 10:23:11 -0400 Subject: [PATCH] fix: Only show Update Channel preferences when applicable Signed-off-by: Sebastian Malton --- ...ding-preference-when-disabled.test.ts.snap | 1416 +++++++++++++++++ .../analytics-for-installing-update.test.ts | 2 +- ...tion-update-using-application-menu.test.ts | 2 +- .../check-for-updates-menu-item.injectable.ts | 2 +- ...alling-update-using-topbar-button.test.tsx | 2 +- .../installing-update-using-tray.test.ts | 2 +- .../check-for-updates-tray-item.injectable.ts | 2 +- .../start-checking-for-updates.injectable.ts | 2 +- .../periodical-checking-of-updates.test.ts | 2 +- ...ate-channel-preference-block.injectable.ts | 2 + .../selection-of-update-stability.test.ts | 2 +- .../updating-is-enabled/common/token.ts | 13 + .../main/channel-listener.injectable.ts | 18 + .../main}/publish-is-configured.injectable.ts | 0 .../main}/updating-is-enabled.injectable.ts | 4 +- .../updating-is-enabled.injectable.ts | 22 + .../downgrading-version-update.test.ts | 2 +- .../hiding-preference-when-disabled.test.ts | 70 + .../installing-update.test.ts | 2 +- 19 files changed, 1555 insertions(+), 12 deletions(-) create mode 100644 packages/core/src/features/application-update/__snapshots__/hiding-preference-when-disabled.test.ts.snap create mode 100644 packages/core/src/features/application-update/child-features/updating-is-enabled/common/token.ts create mode 100644 packages/core/src/features/application-update/child-features/updating-is-enabled/main/channel-listener.injectable.ts rename packages/core/src/features/application-update/{main/updating-is-enabled => child-features/updating-is-enabled/main}/publish-is-configured.injectable.ts (100%) rename packages/core/src/features/application-update/{main/updating-is-enabled => child-features/updating-is-enabled/main}/updating-is-enabled.injectable.ts (72%) create mode 100644 packages/core/src/features/application-update/child-features/updating-is-enabled/renderer/updating-is-enabled.injectable.ts create mode 100644 packages/core/src/features/application-update/hiding-preference-when-disabled.test.ts diff --git a/packages/core/src/features/application-update/__snapshots__/hiding-preference-when-disabled.test.ts.snap b/packages/core/src/features/application-update/__snapshots__/hiding-preference-when-disabled.test.ts.snap new file mode 100644 index 0000000000..7388d59015 --- /dev/null +++ b/packages/core/src/features/application-update/__snapshots__/hiding-preference-when-disabled.test.ts.snap @@ -0,0 +1,1416 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`hiding Update Channel preference with updating is not enabled renders 1`] = ` + +
+
+
+
+
+ + + home + + +
+
+
+ + + arrow_back + + +
+
+
+ + + arrow_forward + + +
+
+
+
+
+
+
+ +
+
+
+

+ Application +

+
+
+
+ Theme + +
+
+ + +
+
+
+ Select... +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+
+ Extension Install Registry + +
+
+ + +
+
+
+ Default Url +
+
+ +
+
+
+ + +
+
+
+

+ This setting is to change the registry URL for installing extensions by name. + If you are unable to access the default registry (https://registry.npmjs.org) you can change it in your + + .npmrc + + file or in the input below. +

+
+ +
+
+
+
+
+
+
+
+ Start-up + +
+ +
+
+
+
+
+
+ Locale Timezone + +
+
+ + +
+
+
+ Etc/GMT +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + + close + + +
+ +
+
+
+
+
+
+
+
+
+
+
+
+ Ca +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + arrow_left + + +
+
+ 1 +
+
+ + + arrow_right + + +
+
+
+
+
+
+
+
+
+ +`; + +exports[`showing Update Channel preference with updating is enabled renders 1`] = ` + +
+
+
+
+
+ + + home + + +
+
+
+ + + arrow_back + + +
+
+
+ + + arrow_forward + + +
+
+
+
+
+
+
+ +
+
+
+

+ Application +

+
+
+
+ Theme + +
+
+ + +
+
+
+ Select... +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+
+ Extension Install Registry + +
+
+ + +
+
+
+ Default Url +
+
+ +
+
+
+ + +
+
+
+

+ This setting is to change the registry URL for installing extensions by name. + If you are unable to access the default registry (https://registry.npmjs.org) you can change it in your + + .npmrc + + file or in the input below. +

+
+ +
+
+
+
+
+
+
+
+ Start-up + +
+ +
+
+
+
+
+
+ Update Channel + +
+
+ + +
+
+
+ Stable +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+
+ Locale Timezone + +
+
+ + +
+
+
+ Etc/GMT +
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + + close + + +
+ +
+
+
+
+
+
+
+
+
+
+
+
+ Ca +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + arrow_left + + +
+
+ 1 +
+
+ + + arrow_right + + +
+
+
+
+
+
+
+
+
+ +`; diff --git a/packages/core/src/features/application-update/analytics-for-installing-update.test.ts b/packages/core/src/features/application-update/analytics-for-installing-update.test.ts index 780a81a81d..710c4b8e49 100644 --- a/packages/core/src/features/application-update/analytics-for-installing-update.test.ts +++ b/packages/core/src/features/application-update/analytics-for-installing-update.test.ts @@ -5,7 +5,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable"; -import publishIsConfiguredInjectable from "./main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; +import publishIsConfiguredInjectable from "./child-features/updating-is-enabled/main/publish-is-configured.injectable"; import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; import type { CheckForPlatformUpdates } from "./main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; diff --git a/packages/core/src/features/application-update/child-features/application-update-using-application-menu/application-update-using-application-menu.test.ts b/packages/core/src/features/application-update/child-features/application-update-using-application-menu/application-update-using-application-menu.test.ts index f8edecd81b..d25355c821 100644 --- a/packages/core/src/features/application-update/child-features/application-update-using-application-menu/application-update-using-application-menu.test.ts +++ b/packages/core/src/features/application-update/child-features/application-update-using-application-menu/application-update-using-application-menu.test.ts @@ -15,7 +15,7 @@ import type { ShowMessagePopup } from "../../../../main/electron-app/features/sh import electronUpdaterIsActiveInjectable from "../../../../main/electron-app/features/electron-updater-is-active.injectable"; import publishIsConfiguredInjectable - from "../../main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; + from "../../child-features/updating-is-enabled/main/publish-is-configured.injectable"; describe("installing update using application menu", () => { let applicationBuilder: ApplicationBuilder; diff --git a/packages/core/src/features/application-update/child-features/application-update-using-application-menu/main/check-for-updates-menu-item.injectable.ts b/packages/core/src/features/application-update/child-features/application-update-using-application-menu/main/check-for-updates-menu-item.injectable.ts index 0bbf22abce..72cbff284a 100644 --- a/packages/core/src/features/application-update/child-features/application-update-using-application-menu/main/check-for-updates-menu-item.injectable.ts +++ b/packages/core/src/features/application-update/child-features/application-update-using-application-menu/main/check-for-updates-menu-item.injectable.ts @@ -7,7 +7,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import applicationMenuItemInjectionToken from "../../../../application-menu/main/menu-items/application-menu-item-injection-token"; import processCheckingForUpdatesInjectable from "../../../main/process-checking-for-updates.injectable"; import showApplicationWindowInjectable from "../../../../../main/start-main-application/lens-window/show-application-window.injectable"; -import updatingIsEnabledInjectable from "../../../main/updating-is-enabled/updating-is-enabled.injectable"; +import updatingIsEnabledInjectable from "../../updating-is-enabled/main/updating-is-enabled.injectable"; import isMacInjectable from "../../../../../common/vars/is-mac.injectable"; import showMessagePopupInjectable from "../../../../../main/electron-app/features/show-message-popup.injectable"; diff --git a/packages/core/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx b/packages/core/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx index 26e456c0c3..be9bc9291a 100644 --- a/packages/core/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx +++ b/packages/core/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx @@ -10,7 +10,7 @@ import type { CheckForPlatformUpdates } from "../../main/check-for-updates/check import checkForPlatformUpdatesInjectable from "../../main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; import type { DownloadPlatformUpdate } from "../../main/download-update/download-platform-update/download-platform-update.injectable"; import downloadPlatformUpdateInjectable from "../../main/download-update/download-platform-update/download-platform-update.injectable"; -import publishIsConfiguredInjectable from "../../main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; +import publishIsConfiguredInjectable from "../../child-features/updating-is-enabled/main/publish-is-configured.injectable"; import electronUpdaterIsActiveInjectable from "../../../../main/electron-app/features/electron-updater-is-active.injectable"; import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; diff --git a/packages/core/src/features/application-update/child-features/application-update-using-tray/installing-update-using-tray.test.ts b/packages/core/src/features/application-update/child-features/application-update-using-tray/installing-update-using-tray.test.ts index 29f6cdbe48..fca1de9757 100644 --- a/packages/core/src/features/application-update/child-features/application-update-using-tray/installing-update-using-tray.test.ts +++ b/packages/core/src/features/application-update/child-features/application-update-using-tray/installing-update-using-tray.test.ts @@ -6,7 +6,7 @@ import { getApplicationBuilder } from "../../../../renderer/components/test-util import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import type { RenderResult } from "@testing-library/react"; import electronUpdaterIsActiveInjectable from "../../../../main/electron-app/features/electron-updater-is-active.injectable"; -import publishIsConfiguredInjectable from "../../main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; +import publishIsConfiguredInjectable from "../../child-features/updating-is-enabled/main/publish-is-configured.injectable"; import type { CheckForPlatformUpdates } from "../../main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "../../main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; import type { AsyncFnMock } from "@async-fn/jest"; diff --git a/packages/core/src/features/application-update/child-features/application-update-using-tray/main/tray-items/check-for-updates-tray-item.injectable.ts b/packages/core/src/features/application-update/child-features/application-update-using-tray/main/tray-items/check-for-updates-tray-item.injectable.ts index 3b20d9bfa1..3f79fa628d 100644 --- a/packages/core/src/features/application-update/child-features/application-update-using-tray/main/tray-items/check-for-updates-tray-item.injectable.ts +++ b/packages/core/src/features/application-update/child-features/application-update-using-tray/main/tray-items/check-for-updates-tray-item.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import updatingIsEnabledInjectable from "../../../../main/updating-is-enabled/updating-is-enabled.injectable"; +import updatingIsEnabledInjectable from "../../../updating-is-enabled/main/updating-is-enabled.injectable"; import { trayMenuItemInjectionToken } from "../../../../../../main/tray/tray-menu-item/tray-menu-item-injection-token"; import showApplicationWindowInjectable from "../../../../../../main/start-main-application/lens-window/show-application-window.injectable"; import discoveredUpdateVersionInjectable from "../../../../common/discovered-update-version.injectable"; diff --git a/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/main/start-checking-for-updates.injectable.ts b/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/main/start-checking-for-updates.injectable.ts index 5e8ab6622c..b1539343f6 100644 --- a/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/main/start-checking-for-updates.injectable.ts +++ b/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/main/start-checking-for-updates.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import periodicalCheckForUpdatesInjectable from "./periodical-check-for-updates.injectable"; -import updatingIsEnabledInjectable from "../../../main/updating-is-enabled/updating-is-enabled.injectable"; +import updatingIsEnabledInjectable from "../../updating-is-enabled/main/updating-is-enabled.injectable"; import { afterApplicationIsLoadedInjectionToken } from "@k8slens/application"; const startCheckingForUpdatesInjectable = getInjectable({ diff --git a/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts b/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts index 1c01fdac31..ac29f38a2a 100644 --- a/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts +++ b/packages/core/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts @@ -6,7 +6,7 @@ import type { ApplicationBuilder } from "../../../../renderer/components/test-ut import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import type { RenderResult } from "@testing-library/react"; import electronUpdaterIsActiveInjectable from "../../../../main/electron-app/features/electron-updater-is-active.injectable"; -import publishIsConfiguredInjectable from "../../main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; +import publishIsConfiguredInjectable from "../../child-features/updating-is-enabled/main/publish-is-configured.injectable"; import processCheckingForUpdatesInjectable from "../../main/process-checking-for-updates.injectable"; import periodicalCheckForUpdatesInjectable from "./main/periodical-check-for-updates.injectable"; import { testUsingFakeTime, advanceFakeTime } from "../../../../test-utils/use-fake-time"; diff --git a/packages/core/src/features/application-update/child-features/preferences/renderer/update-channel/update-channel-preference-block.injectable.ts b/packages/core/src/features/application-update/child-features/preferences/renderer/update-channel/update-channel-preference-block.injectable.ts index a429b1b0c0..5e601ae017 100644 --- a/packages/core/src/features/application-update/child-features/preferences/renderer/update-channel/update-channel-preference-block.injectable.ts +++ b/packages/core/src/features/application-update/child-features/preferences/renderer/update-channel/update-channel-preference-block.injectable.ts @@ -4,6 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { preferenceItemInjectionToken } from "../../../../../preferences/renderer/preference-items/preference-item-injection-token"; +import { updatingIsEnabledInitializable } from "../../../updating-is-enabled/common/token"; import { UpdateChannel } from "./update-channel"; const updateChannelPreferenceBlockInjectable = getInjectable({ @@ -15,6 +16,7 @@ const updateChannelPreferenceBlockInjectable = getInjectable({ parentId: "application-page", orderNumber: 50, Component: UpdateChannel, + isShown: di.inject(updatingIsEnabledInitializable.stateToken), }), injectionToken: preferenceItemInjectionToken, diff --git a/packages/core/src/features/application-update/child-features/selection-of-update-stability/selection-of-update-stability.test.ts b/packages/core/src/features/application-update/child-features/selection-of-update-stability/selection-of-update-stability.test.ts index 51401420e9..05785faf38 100644 --- a/packages/core/src/features/application-update/child-features/selection-of-update-stability/selection-of-update-stability.test.ts +++ b/packages/core/src/features/application-update/child-features/selection-of-update-stability/selection-of-update-stability.test.ts @@ -7,7 +7,7 @@ import { getApplicationBuilder } from "../../../../renderer/components/test-util import quitAndInstallUpdateInjectable from "../../main/quit-and-install-update.injectable"; import type { RenderResult } from "@testing-library/react"; import electronUpdaterIsActiveInjectable from "../../../../main/electron-app/features/electron-updater-is-active.injectable"; -import publishIsConfiguredInjectable from "../../main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; +import publishIsConfiguredInjectable from "../../child-features/updating-is-enabled/main/publish-is-configured.injectable"; import type { CheckForPlatformUpdates } from "../../main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "../../main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; import type { AsyncFnMock } from "@async-fn/jest"; diff --git a/packages/core/src/features/application-update/child-features/updating-is-enabled/common/token.ts b/packages/core/src/features/application-update/child-features/updating-is-enabled/common/token.ts new file mode 100644 index 0000000000..d624b0a1cf --- /dev/null +++ b/packages/core/src/features/application-update/child-features/updating-is-enabled/common/token.ts @@ -0,0 +1,13 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import type { RequestChannel } from "@k8slens/messaging"; +import { getInitializable } from "../../../../../common/initializable-state/create"; + +export const updatingIsEnabledChannel: RequestChannel = { + id: "updating-is-enabled", +}; + +export const updatingIsEnabledInitializable = getInitializable("updating-is-enabled"); diff --git a/packages/core/src/features/application-update/child-features/updating-is-enabled/main/channel-listener.injectable.ts b/packages/core/src/features/application-update/child-features/updating-is-enabled/main/channel-listener.injectable.ts new file mode 100644 index 0000000000..ba52b0188d --- /dev/null +++ b/packages/core/src/features/application-update/child-features/updating-is-enabled/main/channel-listener.injectable.ts @@ -0,0 +1,18 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; +import { updatingIsEnabledChannel, updatingIsEnabledInitializable } from "../common/token"; + +const updatingIsEnabledChannelListenerInjectable = getRequestChannelListenerInjectable({ + channel: updatingIsEnabledChannel, + id: "foobar", + getHandler: (di) => { + const updatingIsEnabled = di.inject(updatingIsEnabledInitializable.stateToken); + + return () => updatingIsEnabled; + }, +}); + +export default updatingIsEnabledChannelListenerInjectable; diff --git a/packages/core/src/features/application-update/main/updating-is-enabled/publish-is-configured.injectable.ts b/packages/core/src/features/application-update/child-features/updating-is-enabled/main/publish-is-configured.injectable.ts similarity index 100% rename from packages/core/src/features/application-update/main/updating-is-enabled/publish-is-configured.injectable.ts rename to packages/core/src/features/application-update/child-features/updating-is-enabled/main/publish-is-configured.injectable.ts diff --git a/packages/core/src/features/application-update/main/updating-is-enabled/updating-is-enabled.injectable.ts b/packages/core/src/features/application-update/child-features/updating-is-enabled/main/updating-is-enabled.injectable.ts similarity index 72% rename from packages/core/src/features/application-update/main/updating-is-enabled/updating-is-enabled.injectable.ts rename to packages/core/src/features/application-update/child-features/updating-is-enabled/main/updating-is-enabled.injectable.ts index cc9f50f627..4091fd0e38 100644 --- a/packages/core/src/features/application-update/main/updating-is-enabled/updating-is-enabled.injectable.ts +++ b/packages/core/src/features/application-update/child-features/updating-is-enabled/main/updating-is-enabled.injectable.ts @@ -3,7 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import electronUpdaterIsActiveInjectable from "../../../../main/electron-app/features/electron-updater-is-active.injectable"; +import electronUpdaterIsActiveInjectable from "../../../../../main/electron-app/features/electron-updater-is-active.injectable"; +import { updatingIsEnabledInitializable } from "../common/token"; import publishIsConfiguredInjectable from "./publish-is-configured.injectable"; const updatingIsEnabledInjectable = getInjectable({ @@ -15,6 +16,7 @@ const updatingIsEnabledInjectable = getInjectable({ return electronUpdaterIsActive && publishIsConfigured; }, + injectionToken: updatingIsEnabledInitializable.stateToken, }); export default updatingIsEnabledInjectable; diff --git a/packages/core/src/features/application-update/child-features/updating-is-enabled/renderer/updating-is-enabled.injectable.ts b/packages/core/src/features/application-update/child-features/updating-is-enabled/renderer/updating-is-enabled.injectable.ts new file mode 100644 index 0000000000..347ba31a68 --- /dev/null +++ b/packages/core/src/features/application-update/child-features/updating-is-enabled/renderer/updating-is-enabled.injectable.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { onLoadOfApplicationInjectionToken } from "@k8slens/application"; +import { requestFromChannelInjectionToken } from "@k8slens/messaging"; +import { getInjectablesForInitializable } from "../../../../../common/initializable-state/create"; +import { updatingIsEnabledChannel, updatingIsEnabledInitializable } from "../common/token"; + +export const { + stateInjectable, + initializationInjectable, +} = getInjectablesForInitializable({ + token: updatingIsEnabledInitializable, + init: async (di) => { + const requestFromChannel = di.inject(requestFromChannelInjectionToken); + + return requestFromChannel(updatingIsEnabledChannel); + }, + phase: onLoadOfApplicationInjectionToken, +}); diff --git a/packages/core/src/features/application-update/downgrading-version-update.test.ts b/packages/core/src/features/application-update/downgrading-version-update.test.ts index 151ac09936..0781484645 100644 --- a/packages/core/src/features/application-update/downgrading-version-update.test.ts +++ b/packages/core/src/features/application-update/downgrading-version-update.test.ts @@ -5,7 +5,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable"; -import publishIsConfiguredInjectable from "./main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; +import publishIsConfiguredInjectable from "./child-features/updating-is-enabled/main/publish-is-configured.injectable"; import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; import type { CheckForPlatformUpdates } from "./main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; diff --git a/packages/core/src/features/application-update/hiding-preference-when-disabled.test.ts b/packages/core/src/features/application-update/hiding-preference-when-disabled.test.ts new file mode 100644 index 0000000000..74cbb0f9d3 --- /dev/null +++ b/packages/core/src/features/application-update/hiding-preference-when-disabled.test.ts @@ -0,0 +1,70 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import type { GetSingleElement } from "@k8slens/react-testing-library-discovery"; +import { getSingleElement } from "@k8slens/react-testing-library-discovery"; +import type { RenderResult } from "@testing-library/react"; +import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; +import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; +import navigateToPreferencesInjectable from "../preferences/common/navigate-to-preferences.injectable"; +import updatingIsEnabledInjectable from "./child-features/updating-is-enabled/main/updating-is-enabled.injectable"; + +describe("hiding Update Channel preference with updating is not enabled", () => { + let builder: ApplicationBuilder; + let result: RenderResult; + let getElement: GetSingleElement; + + beforeEach(async () => { + builder = getApplicationBuilder(); + + builder.mainDi.override(updatingIsEnabledInjectable, () => false); + + result = await builder.render(); + + getElement = getSingleElement(() => result); + builder.navigateWith(navigateToPreferencesInjectable); + }); + + it("renders", () => { + expect(result.baseElement).toMatchSnapshot(); + }); + + it("shows the application settings", () => { + expect(getElement("preference-page", "application-page").discovered).toBeInTheDocument(); + }); + + it("does not show the update channel preference", () => { + expect(() => getElement("preference-item", "update-channel")).toThrowError(`Couldn't find HTML-element with attribute "data-preference-item-test" with value "update-channel".`); + }); +}); + +describe("showing Update Channel preference with updating is enabled", () => { + let builder: ApplicationBuilder; + let result: RenderResult; + let getElement: GetSingleElement; + + beforeEach(async () => { + builder = getApplicationBuilder(); + + builder.mainDi.override(updatingIsEnabledInjectable, () => true); + + result = await builder.render(); + + getElement = getSingleElement(() => result); + builder.navigateWith(navigateToPreferencesInjectable); + }); + + it("renders", () => { + expect(result.baseElement).toMatchSnapshot(); + }); + + it("shows the application settings", () => { + expect(getElement("preference-page", "application-page").discovered).toBeInTheDocument(); + }); + + it("does show the update channel preference", () => { + expect(getElement("preference-item", "update-channel").discovered).toBeInTheDocument(); + }); +}); diff --git a/packages/core/src/features/application-update/installing-update.test.ts b/packages/core/src/features/application-update/installing-update.test.ts index 0981c8c8f1..7f1d20ed10 100644 --- a/packages/core/src/features/application-update/installing-update.test.ts +++ b/packages/core/src/features/application-update/installing-update.test.ts @@ -7,7 +7,7 @@ import { getApplicationBuilder } from "../../renderer/components/test-utils/get- import quitAndInstallUpdateInjectable from "./main/quit-and-install-update.injectable"; import type { RenderResult } from "@testing-library/react"; import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable"; -import publishIsConfiguredInjectable from "./main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; +import publishIsConfiguredInjectable from "./child-features/updating-is-enabled/main/publish-is-configured.injectable"; import type { CheckForPlatformUpdates } from "./main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "./main/check-for-updates/check-for-platform-updates/check-for-platform-updates.injectable"; import type { AsyncFnMock } from "@async-fn/jest";