From 3827202e5f46191c67f6990605210e8a4dc51d97 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Fri, 24 Jun 2022 15:14:35 +0300 Subject: [PATCH] Initial tests for installing update using topbar button Signed-off-by: Alex Andreev --- ...g-update-using-topbar-button.test.tsx.snap | 21 +++++ ...alling-update-using-topbar-button.test.tsx | 83 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/behaviours/application-update/__snapshots__/installing-update-using-topbar-button.test.tsx.snap create mode 100644 src/behaviours/application-update/installing-update-using-topbar-button.test.tsx 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 new file mode 100644 index 0000000000..bdeb41e272 --- /dev/null +++ b/src/behaviours/application-update/__snapshots__/installing-update-using-topbar-button.test.tsx.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`encourage user to update when sufficient time passed since update was downloaded when started renders 1`] = ` + +
+
+
+
+
+
+
+ +`; 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 new file mode 100644 index 0000000000..ea478d5fa8 --- /dev/null +++ b/src/behaviours/application-update/installing-update-using-topbar-button.test.tsx @@ -0,0 +1,83 @@ +import type { AsyncFnMock } from "@async-fn/jest"; +import asyncFn from "@async-fn/jest"; +import type { RenderResult } from "@testing-library/react"; +import type { CheckForPlatformUpdates } from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable"; +import checkForPlatformUpdatesInjectable from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable"; +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 publishIsConfiguredInjectable from "../../main/application-update/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"; + +describe("encourage user to update when sufficient time passed since update was downloaded", () => { + let applicationBuilder: ApplicationBuilder; + let checkForPlatformUpdatesMock: AsyncFnMock; + let downloadPlatformUpdateMock: AsyncFnMock; + + beforeEach(() => { + applicationBuilder = getApplicationBuilder(); + + applicationBuilder.beforeApplicationStart(({ mainDi }) => { + checkForPlatformUpdatesMock = asyncFn(); + downloadPlatformUpdateMock = asyncFn(); + + mainDi.override( + checkForPlatformUpdatesInjectable, + () => checkForPlatformUpdatesMock, + ); + + mainDi.override( + downloadPlatformUpdateInjectable, + () => downloadPlatformUpdateMock, + ); + + mainDi.override(electronUpdaterIsActiveInjectable, () => true); + mainDi.override(publishIsConfiguredInjectable, () => true); + }) + }); + + describe("when started", () => { + let rendered: RenderResult; + + beforeEach(async () => { + rendered = await applicationBuilder.render(); + }); + + it("renders", () => { + expect(rendered.baseElement).toMatchSnapshot(); + }); + + it("does not show update button yet", () => { + const button = rendered.queryByTestId("update-button"); + + expect(button).toBeNull(); + }); + + describe("given the update check", () => { + let processCheckingForUpdatesPromise: Promise; + + beforeEach(async () => { + // TODO: initiate update check process automatically, not from tray + processCheckingForUpdatesPromise = applicationBuilder.tray.click("check-for-updates"); + }); + + describe("when update downloaded", () => { + beforeEach(async () => { + await checkForPlatformUpdatesMock.resolve({ + updateWasDiscovered: true, + version: "some-version", + }); + await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true }); + await processCheckingForUpdatesPromise; + }); + + it("shows update button to help user to update", () => { + const button = rendered.queryByTestId("update-button"); + + expect(button).toBeInTheDocument(); + }) + }); + }); + }); +}); \ No newline at end of file