diff --git a/src/behaviours/application-update/__snapshots__/installing-update-using-topbar-button.test.tsx.snap b/src/behaviours/application-update/__snapshots__/installing-update-using-topbar-button.test.tsx.snap index 9d4c66acae..2fbbc159a8 100644 --- a/src/behaviours/application-update/__snapshots__/installing-update-using-topbar-button.test.tsx.snap +++ b/src/behaviours/application-update/__snapshots__/installing-update-using-topbar-button.test.tsx.snap @@ -1,5 +1,225 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`encourage user to update when sufficient time passed since update was downloaded when started given the update check when update downloaded given some time passes, when checking for updates again when checking for updates resolves with same version that was previously downloaded renders 1`] = ` + +
+
+
+
+ + + home + + + + + arrow_back + + + + + arrow_forward + + + +
+
+
+
+
+
+
+ +
+
+

+ Welcome to OpenLens 5! +

+

+ To get you started we have auto-detected your clusters in your + + kubeconfig file and added them to the catalog, your centralized + + view for managing all your cloud-native resources. +
+
+ If you have any questions or feedback, please join our + + Lens Community slack channel + + . +

+ +
+
+
+
+
+
+
+
+ + + arrow_left + + +
+
+ 0 +
+
+ + + arrow_right + + +
+
+
+
+
+
+
+
+
+ +`; + exports[`encourage user to update when sufficient time passed since update was downloaded when started renders 1`] = `
diff --git a/src/behaviours/application-update/analytics-for-installing-update.test.ts b/src/behaviours/application-update/analytics-for-installing-update.test.ts index 018d2361da..e9dccb326e 100644 --- a/src/behaviours/application-update/analytics-for-installing-update.test.ts +++ b/src/behaviours/application-update/analytics-for-installing-update.test.ts @@ -194,6 +194,46 @@ describe("analytics for installing update", () => { await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true }); }); + describe("given checking for updates again", () => { + beforeEach(() => { + const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable); + + processCheckingForUpdates("irrelevant"); + + analyticsListenerMock.mockClear(); + }); + + it("when check resolves with same version that was previously downloaded, does not send event to analytics about update discovered", async () => { + await checkForPlatformUpdatesMock.resolve({ + updateWasDiscovered: true, + version: "43.0.0", + }); + + expect(analyticsListenerMock).not.toHaveBeenCalled(); + }); + + it("when check resolves with different version that was previously downloaded, sends event to analytics about update discovered", async () => { + await checkForPlatformUpdatesMock.resolve({ + updateWasDiscovered: true, + version: "44.0.0", + }); + + expect(analyticsListenerMock.mock.calls).toEqual([ + [ + { + name: "app", + action: "update-was-discovered", + + params: { + version: "44.0.0", + currentDateTime: "2015-10-21T07:28:00Z", + }, + }, + ], + ]); + }); + }); + it("does not send event to analytics about update downloaded being successful", () => { expect(analyticsListenerMock).not.toHaveBeenCalled(); }); diff --git a/src/behaviours/application-update/installing-update-using-topbar-button.test.tsx b/src/behaviours/application-update/installing-update-using-topbar-button.test.tsx index c639798fac..bd57a6c9da 100644 --- a/src/behaviours/application-update/installing-update-using-topbar-button.test.tsx +++ b/src/behaviours/application-update/installing-update-using-topbar-button.test.tsx @@ -18,6 +18,7 @@ import processCheckingForUpdatesInjectable from "../../main/application-update/c import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable"; import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; + function daysToMilliseconds(days: number) { return Math.round(days * 24 * 60 * 60 * 1000); } @@ -73,10 +74,13 @@ describe("encourage user to update when sufficient time passed since update was }); describe("given the update check", () => { + let processCheckingForUpdates: (source: string) => Promise; let processCheckingForUpdatesPromise: Promise; beforeEach(async () => { - const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); + processCheckingForUpdates = applicationBuilder.dis.mainDi.inject( + processCheckingForUpdatesInjectable, + ); processCheckingForUpdatesPromise = processCheckingForUpdates("irrelevant"); }); @@ -104,6 +108,33 @@ describe("encourage user to update when sufficient time passed since update was expect(button).toHaveAttribute("data-warning-level", "light"); }); + describe("given some time passes, when checking for updates again", () => { + beforeEach(() => { + advanceFakeTime(daysToMilliseconds(2)); + + processCheckingForUpdates("irrelevant"); + }); + + describe("when checking for updates resolves with same version that was previously downloaded", () => { + beforeEach(async () => { + await checkForPlatformUpdatesMock.resolve({ + updateWasDiscovered: true, + version: "some-version", + }); + }); + + it("when enough time from download passes for medium update encouragement, has medium emotional indication in the button", () => { + advanceFakeTime(daysToMilliseconds(20)); + + expect(button).toHaveAttribute("data-warning-level", "medium"); + }); + + it("renders", () => { + expect(rendered.baseElement).toMatchSnapshot(); + }); + }); + }); + describe("when button is clicked", () => { beforeEach(() => { act(() => button.click()); diff --git a/src/behaviours/application-update/installing-update.test.ts b/src/behaviours/application-update/installing-update.test.ts index 2e10403ed8..305e95d525 100644 --- a/src/behaviours/application-update/installing-update.test.ts +++ b/src/behaviours/application-update/installing-update.test.ts @@ -193,6 +193,59 @@ describe("installing update", () => { it("renders", () => { expect(rendered.baseElement).toMatchSnapshot(); }); + + describe("given checking for updates again", () => { + beforeEach(() => { + downloadPlatformUpdateMock.mockClear(); + + processCheckingForUpdates("irrelevant"); + }); + + it("shows tray icon for checking for updates", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + ); + }); + + describe("when check resolves with same update that is already downloaded", () => { + beforeEach(async () => { + await checkForPlatformUpdatesMock.resolve({ + updateWasDiscovered: true, + version: "some-version", + }); + }); + + it("does not re-download the update", () => { + expect(downloadPlatformUpdateMock).not.toHaveBeenCalled(); + }); + + it("shows tray icon for update being available", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconUpdateAvailableTemplate.png", + ); + }); + }); + + describe("when check resolves with different update that was previously downloaded", () => { + beforeEach(async () => { + await checkForPlatformUpdatesMock.resolve({ + updateWasDiscovered: true, + version: "some-other-version", + }); + }); + + it("downloads the update", () => { + expect(downloadPlatformUpdateMock).toHaveBeenCalled(); + }); + + it("shows tray icon for downloading update", () => { + expect(applicationBuilder.tray.getIconPath()).toBe( + "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + ); + }); + + }); + }); }); }); }); diff --git a/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts b/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts index 73cab8d300..e737c67faf 100644 --- a/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts +++ b/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts @@ -49,6 +49,16 @@ const processCheckingForUpdatesInjectable = getInjectable({ const { version, actualUpdateChannel } = result; + const previouslyDiscovered = discoveredVersionState.value.get(); + + if (version === previouslyDiscovered?.version) { + runInAction(() => { + checkingForUpdatesState.set(false); + }); + + return; + } + emitEvent({ name: "app", action: "update-was-discovered",