mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Open application only if new update is available when using tray to check for updates (#5948)
* Prevent opening of application if no new updates were downloaded when checking for updates using tray when application window is closed Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix getting initial value of sync box Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak naming of variable Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
a68ce2b2be
commit
af4b74d9bd
8 files changed
+110
-52
No files matched your search
@@ -73,15 +73,14 @@ describe("encourage user to update when sufficient time passed since update was
|
||||
});
|
||||
|
||||
describe("given the update check", () => {
|
||||
let processCheckingForUpdates: (source: string) => Promise<void>;
|
||||
let processCheckingForUpdatesPromise: Promise<void>;
|
||||
let processCheckingForUpdates: (source: string) => Promise<{ updateIsReadyToBeInstalled: boolean }>;
|
||||
|
||||
beforeEach(async () => {
|
||||
processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(
|
||||
processCheckingForUpdatesInjectable,
|
||||
);
|
||||
|
||||
processCheckingForUpdatesPromise = processCheckingForUpdates("irrelevant");
|
||||
processCheckingForUpdates("irrelevant");
|
||||
});
|
||||
|
||||
describe("when update downloaded", () => {
|
||||
@@ -94,7 +93,6 @@ describe("encourage user to update when sufficient time passed since update was
|
||||
});
|
||||
|
||||
await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true });
|
||||
await processCheckingForUpdatesPromise;
|
||||
|
||||
button = rendered.getByTestId("update-button");
|
||||
});
|
||||
@@ -107,6 +105,11 @@ describe("encourage user to update when sufficient time passed since update was
|
||||
expect(button).toHaveAttribute("data-warning-level", "light");
|
||||
});
|
||||
|
||||
// TODO: Implement after starting main and renderer is separated in ApplicationBuilder
|
||||
xit("given closing the application window, when starting the application window again, still shows the button", () => {
|
||||
expect(button).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe("given some time passes, when checking for updates again", () => {
|
||||
beforeEach(() => {
|
||||
advanceFakeTime(daysToMilliseconds(2));
|
||||
|
||||
@@ -13,13 +13,14 @@ import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
||||
import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
||||
import showApplicationWindowInjectable from "../../main/start-main-application/lens-window/show-application-window.injectable";
|
||||
import closeAllWindowsInjectable from "../../main/start-main-application/lens-window/hide-all-windows/close-all-windows.injectable";
|
||||
import applicationWindowInjectable from "../../main/start-main-application/lens-window/application-window/application-window.injectable";
|
||||
import type { LensWindow } from "../../main/start-main-application/lens-window/application-window/lens-window-injection-token";
|
||||
|
||||
describe("installing update using tray", () => {
|
||||
let applicationBuilder: ApplicationBuilder;
|
||||
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
|
||||
let downloadPlatformUpdateMock: AsyncFnMock<DownloadPlatformUpdate>;
|
||||
let showApplicationWindowMock: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
applicationBuilder = getApplicationBuilder();
|
||||
@@ -27,9 +28,6 @@ describe("installing update using tray", () => {
|
||||
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||
checkForPlatformUpdatesMock = asyncFn();
|
||||
downloadPlatformUpdateMock = asyncFn();
|
||||
showApplicationWindowMock = jest.fn();
|
||||
|
||||
mainDi.override(showApplicationWindowInjectable, () => showApplicationWindowMock);
|
||||
|
||||
mainDi.override(
|
||||
checkForPlatformUpdatesInjectable,
|
||||
@@ -61,15 +59,77 @@ describe("installing update using tray", () => {
|
||||
expect(applicationBuilder.tray.get("install-update")).toBeNull();
|
||||
});
|
||||
|
||||
describe("when user checks for updates using tray", () => {
|
||||
let processCheckingForUpdatesPromise: Promise<void>;
|
||||
describe("given all application windows are closed, when checking for updates", () => {
|
||||
let applicationWindow: LensWindow;
|
||||
let closeAllWindows: () => void;
|
||||
|
||||
beforeEach(async () => {
|
||||
processCheckingForUpdatesPromise = applicationBuilder.tray.click("check-for-updates");
|
||||
beforeEach(() => {
|
||||
const mainDi = applicationBuilder.dis.mainDi;
|
||||
|
||||
closeAllWindows = mainDi.inject(closeAllWindowsInjectable);
|
||||
|
||||
applicationWindow = mainDi.inject(applicationWindowInjectable);
|
||||
|
||||
closeAllWindows();
|
||||
|
||||
applicationBuilder.tray.click("check-for-updates");
|
||||
});
|
||||
|
||||
it("does not show application window yet", () => {
|
||||
expect(showApplicationWindowMock).not.toHaveBeenCalled();
|
||||
describe("when check for update resolves with new update", () => {
|
||||
beforeEach(async () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: true,
|
||||
version: "some-version",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not show application window yet", () => {
|
||||
expect(applicationWindow.isVisible).toBe(false);
|
||||
});
|
||||
|
||||
describe("when download of update resolves with success", () => {
|
||||
beforeEach(async () => {
|
||||
|
||||
await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true });
|
||||
});
|
||||
|
||||
it("shows the application window", () => {
|
||||
expect(applicationWindow.isVisible).toBe(true);
|
||||
});
|
||||
|
||||
it("given closing application window again and checking for updates again using tray, when check resolves with same version that was earlier downloaded, shows the application window", async () => {
|
||||
closeAllWindows();
|
||||
|
||||
applicationBuilder.tray.click("check-for-updates");
|
||||
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: true,
|
||||
version: "some-version",
|
||||
});
|
||||
|
||||
expect(applicationWindow.isVisible).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("when download of update resolves with failure, does not show the application window", async () => {
|
||||
await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: false });
|
||||
|
||||
expect(applicationWindow.isVisible).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("when process resolves without new update, does not show the application window", async () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: false,
|
||||
});
|
||||
|
||||
expect(applicationWindow.isVisible).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when user checks for updates using tray", () => {
|
||||
beforeEach(() => {
|
||||
applicationBuilder.tray.click("check-for-updates");
|
||||
});
|
||||
|
||||
it("user cannot check for updates again", () => {
|
||||
@@ -97,12 +157,6 @@ describe("installing update using tray", () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: false,
|
||||
});
|
||||
|
||||
await processCheckingForUpdatesPromise;
|
||||
});
|
||||
|
||||
it("shows application window", () => {
|
||||
expect(showApplicationWindowMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("user cannot install update", () => {
|
||||
@@ -132,12 +186,6 @@ describe("installing update using tray", () => {
|
||||
updateWasDiscovered: true,
|
||||
version: "some-version",
|
||||
});
|
||||
|
||||
await processCheckingForUpdatesPromise;
|
||||
});
|
||||
|
||||
it("shows application window", () => {
|
||||
expect(showApplicationWindowMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("user cannot check for updates again yet", () => {
|
||||
|
||||
@@ -63,7 +63,7 @@ describe("installing update", () => {
|
||||
|
||||
describe("when started", () => {
|
||||
let rendered: RenderResult;
|
||||
let processCheckingForUpdates: (source: string) => Promise<void>;
|
||||
let processCheckingForUpdates: (source: string) => Promise<{ updateIsReadyToBeInstalled: boolean }>;
|
||||
|
||||
beforeEach(async () => {
|
||||
rendered = await applicationBuilder.render();
|
||||
@@ -84,10 +84,8 @@ describe("installing update", () => {
|
||||
});
|
||||
|
||||
describe("when user checks for updates", () => {
|
||||
let processCheckingForUpdatesPromise: Promise<void>;
|
||||
|
||||
beforeEach(async () => {
|
||||
processCheckingForUpdatesPromise = processCheckingForUpdates("irrelevant");
|
||||
beforeEach(() => {
|
||||
processCheckingForUpdates("irrelevant");
|
||||
});
|
||||
|
||||
it("checks for updates", () => {
|
||||
@@ -112,8 +110,6 @@ describe("installing update", () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: false,
|
||||
});
|
||||
|
||||
await processCheckingForUpdatesPromise;
|
||||
});
|
||||
|
||||
it("shows tray icon for normal", () => {
|
||||
@@ -137,8 +133,6 @@ describe("installing update", () => {
|
||||
updateWasDiscovered: true,
|
||||
version: "some-version",
|
||||
});
|
||||
|
||||
await processCheckingForUpdatesPromise;
|
||||
});
|
||||
|
||||
it("starts downloading the update", () => {
|
||||
@@ -243,7 +237,6 @@ describe("installing update", () => {
|
||||
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,8 +7,6 @@ import { getApplicationBuilder } from "../../renderer/components/test-utils/get-
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
|
||||
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-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";
|
||||
@@ -17,7 +15,7 @@ const ENOUGH_TIME = 1000 * 60 * 60 * 2;
|
||||
|
||||
describe("periodical checking of updates", () => {
|
||||
let applicationBuilder: ApplicationBuilder;
|
||||
let processCheckingForUpdatesMock: AsyncFnMock<() => Promise<void>>;
|
||||
let processCheckingForUpdatesMock: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
useFakeTime("2015-10-21T07:28:00Z");
|
||||
@@ -28,7 +26,7 @@ describe("periodical checking of updates", () => {
|
||||
mainDi.unoverride(periodicalCheckForUpdatesInjectable);
|
||||
mainDi.permitSideEffects(periodicalCheckForUpdatesInjectable);
|
||||
|
||||
processCheckingForUpdatesMock = asyncFn();
|
||||
processCheckingForUpdatesMock = jest.fn();
|
||||
|
||||
mainDi.override(
|
||||
processCheckingForUpdatesInjectable,
|
||||
|
||||
@@ -67,7 +67,7 @@ describe("selection of update stability", () => {
|
||||
|
||||
describe("when started", () => {
|
||||
let rendered: RenderResult;
|
||||
let processCheckingForUpdates: (source: string) => Promise<void>;
|
||||
let processCheckingForUpdates: (source: string) => Promise<{ updateIsReadyToBeInstalled: boolean }>;
|
||||
|
||||
beforeEach(async () => {
|
||||
rendered = await applicationBuilder.render();
|
||||
|
||||
Reference in new issue
Block a user