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 c33a3f92af..5fef35df65 100644 --- a/src/behaviours/application-update/analytics-for-installing-update.test.ts +++ b/src/behaviours/application-update/analytics-for-installing-update.test.ts @@ -18,6 +18,7 @@ import downloadPlatformUpdateInjectable from "../../main/application-update/down import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable"; import appVersionInjectable from "../../common/get-configuration-file-model/app-version/app-version.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"; describe("analytics for installing update", () => { let applicationBuilder: ApplicationBuilder; @@ -27,9 +28,7 @@ describe("analytics for installing update", () => { let mainDi: DiContainer; beforeEach(async () => { - jest.useFakeTimers(); - - global.Date.now = () => new Date("2015-10-21T07:28:00Z").getTime(); + useFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); @@ -84,7 +83,7 @@ describe("analytics for installing update", () => { it("when enough time passes to check for updates again, sends event to analytics for being checked periodically", () => { analyticsListenerMock.mockClear(); - jest.advanceTimersByTime(1000 * 60 * 60 * 2); + advanceFakeTime(1000 * 60 * 60 * 2); expect(analyticsListenerMock).toHaveBeenCalledWith({ name: "app", 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 f2b9a58dd1..c639798fac 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 @@ -16,6 +16,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/ge import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable"; 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); @@ -28,7 +29,7 @@ describe("encourage user to update when sufficient time passed since update was let quitAndInstallUpdateMock: jest.MockedFunction<() => void>; beforeEach(() => { - jest.useFakeTimers(); + useFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); @@ -128,13 +129,13 @@ describe("encourage user to update when sufficient time passed since update was }); it("given just enough time passes for medium update encouragement, has medium emotional indication in the button", () => { - jest.advanceTimersByTime(daysToMilliseconds(22)); + advanceFakeTime(daysToMilliseconds(22)); expect(button).toHaveAttribute("data-warning-level", "medium"); }); it("given just enough time passes for severe update encouragement, has severe emotional indication in the button", () => { - jest.advanceTimersByTime(daysToMilliseconds(26)); + advanceFakeTime(daysToMilliseconds(26)); expect(button).toHaveAttribute("data-warning-level", "high"); }); diff --git a/src/behaviours/application-update/installing-update.test.ts b/src/behaviours/application-update/installing-update.test.ts index c81f2954ed..e784aac78c 100644 --- a/src/behaviours/application-update/installing-update.test.ts +++ b/src/behaviours/application-update/installing-update.test.ts @@ -16,6 +16,7 @@ import type { DownloadPlatformUpdate } from "../../main/application-update/downl import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable"; import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable"; import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable"; +import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; describe("installing update", () => { let applicationBuilder: ApplicationBuilder; @@ -25,7 +26,7 @@ describe("installing update", () => { let setUpdateOnQuitMock: jest.Mock; beforeEach(() => { - jest.useFakeTimers(); + useFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); @@ -115,7 +116,7 @@ describe("installing update", () => { }); it.skip("when 5 seconds elapses, clears the notification to the user", () => { - jest.advanceTimersByTime(6000); + advanceFakeTime(6000); expect(rendered.getByTestId("app-update-idle")).toBeInTheDocument(); }); diff --git a/src/behaviours/application-update/periodical-checking-of-updates.test.ts b/src/behaviours/application-update/periodical-checking-of-updates.test.ts index e81c002e34..37c9d4e92b 100644 --- a/src/behaviours/application-update/periodical-checking-of-updates.test.ts +++ b/src/behaviours/application-update/periodical-checking-of-updates.test.ts @@ -11,6 +11,7 @@ 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"; const ENOUGH_TIME = 1000 * 60 * 60 * 2; @@ -19,7 +20,7 @@ describe("periodical checking of updates", () => { let processCheckingForUpdatesMock: AsyncFnMock<() => Promise>; beforeEach(() => { - jest.useFakeTimers(); + useFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); @@ -59,7 +60,7 @@ describe("periodical checking of updates", () => { it("when just not enough time passes, does not check for updates again automatically yet", () => { processCheckingForUpdatesMock.mockClear(); - jest.advanceTimersByTime(ENOUGH_TIME - 1); + advanceFakeTime(ENOUGH_TIME - 1); expect(processCheckingForUpdatesMock).not.toHaveBeenCalled(); }); @@ -67,7 +68,7 @@ describe("periodical checking of updates", () => { it("when just enough time passes, checks for updates again automatically", () => { processCheckingForUpdatesMock.mockClear(); - jest.advanceTimersByTime(ENOUGH_TIME); + advanceFakeTime(ENOUGH_TIME); expect(processCheckingForUpdatesMock).toHaveBeenCalled(); }); diff --git a/src/behaviours/cluster/sidebar-and-tab-navigation-for-core.test.tsx b/src/behaviours/cluster/sidebar-and-tab-navigation-for-core.test.tsx index 5258a51d88..96b4a6b2d7 100644 --- a/src/behaviours/cluster/sidebar-and-tab-navigation-for-core.test.tsx +++ b/src/behaviours/cluster/sidebar-and-tab-navigation-for-core.test.tsx @@ -22,6 +22,7 @@ import pathExistsInjectable from "../../common/fs/path-exists.injectable"; import readJsonFileInjectable from "../../common/fs/read-json-file.injectable"; import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token"; import sidebarStorageInjectable from "../../renderer/components/layout/sidebar-storage/sidebar-storage.injectable"; +import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; describe("cluster - sidebar and tab navigation for core", () => { let applicationBuilder: ApplicationBuilder; @@ -29,7 +30,7 @@ describe("cluster - sidebar and tab navigation for core", () => { let rendered: RenderResult; beforeEach(() => { - jest.useFakeTimers(); + useFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); rendererDi = applicationBuilder.dis.rendererDi; @@ -262,7 +263,7 @@ describe("cluster - sidebar and tab navigation for core", () => { }); it("when not enough time passes, does not store state for expanded sidebar items to file system yet", async () => { - jest.advanceTimersByTime(250 - 1); + advanceFakeTime(250 - 1); const pathExistsFake = rendererDi.inject(pathExistsInjectable); @@ -274,7 +275,7 @@ describe("cluster - sidebar and tab navigation for core", () => { }); it("when enough time passes, stores state for expanded sidebar items to file system", async () => { - jest.advanceTimersByTime(250); + advanceFakeTime(250); const readJsonFileFake = rendererDi.inject(readJsonFileInjectable); diff --git a/src/behaviours/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx b/src/behaviours/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx index 0f625965b8..75389c6631 100644 --- a/src/behaviours/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx +++ b/src/behaviours/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx @@ -18,6 +18,7 @@ import { navigateToRouteInjectionToken } from "../../common/front-end-routing/na import assert from "assert"; import type { FakeExtensionData } from "../../renderer/components/test-utils/get-renderer-extension-fake"; import { getRendererExtensionFakeFor } from "../../renderer/components/test-utils/get-renderer-extension-fake"; +import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; describe("cluster - sidebar and tab navigation for extensions", () => { let applicationBuilder: ApplicationBuilder; @@ -25,7 +26,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => { let rendered: RenderResult; beforeEach(() => { - jest.useFakeTimers(); + useFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); rendererDi = applicationBuilder.dis.rendererDi; @@ -278,7 +279,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => { }); it("when not enough time passes, does not store state for expanded sidebar items to file system yet", async () => { - jest.advanceTimersByTime(250 - 1); + advanceFakeTime(250 - 1); const pathExistsFake = rendererDi.inject(pathExistsInjectable); @@ -290,7 +291,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => { }); it("when enough time passes, stores state for expanded sidebar items to file system", async () => { - jest.advanceTimersByTime(250); + advanceFakeTime(250); const readJsonFileFake = rendererDi.inject(readJsonFileInjectable); diff --git a/src/behaviours/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts b/src/behaviours/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts index 5f96bb06fb..19360d77bd 100644 --- a/src/behaviours/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts +++ b/src/behaviours/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts @@ -10,6 +10,7 @@ import { lensWindowInjectionToken } from "../../main/start-main-application/lens import exitAppInjectable from "../../main/electron-app/features/exit-app.injectable"; import clusterManagerInjectable from "../../main/cluster-manager.injectable"; import stopServicesAndExitAppInjectable from "../../main/stop-services-and-exit-app.injectable"; +import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; describe("quitting the app using application menu", () => { describe("given application has started", () => { @@ -18,7 +19,7 @@ describe("quitting the app using application menu", () => { let exitAppMock: jest.Mock; beforeEach(async () => { - jest.useFakeTimers(); + useFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder().beforeApplicationStart( ({ mainDi }) => { @@ -71,14 +72,14 @@ describe("quitting the app using application menu", () => { }); it("after insufficient time passes, does not terminate application yet", () => { - jest.advanceTimersByTime(999); + advanceFakeTime(999); expect(exitAppMock).not.toHaveBeenCalled(); }); describe("after sufficient time passes", () => { beforeEach(() => { - jest.advanceTimersByTime(1000); + advanceFakeTime(1000); }); it("terminates application", () => {