mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add Update button dropdown tests
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
5aa8718f90
commit
188c6d2cb2
@ -1,6 +1,6 @@
|
|||||||
import type { AsyncFnMock } from "@async-fn/jest";
|
import type { AsyncFnMock } from "@async-fn/jest";
|
||||||
import asyncFn from "@async-fn/jest";
|
import asyncFn from "@async-fn/jest";
|
||||||
import type { RenderResult } from "@testing-library/react";
|
import { act, RenderResult } from "@testing-library/react";
|
||||||
import type { CheckForPlatformUpdates } from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
|
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 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 type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
||||||
@ -16,11 +16,17 @@ import openAppContextMenuInjectable from "../../renderer/components/layout/top-b
|
|||||||
import toggleMaximizeWindowInjectable from "../../renderer/components/layout/top-bar/toggle-maximize-window.injectable";
|
import toggleMaximizeWindowInjectable from "../../renderer/components/layout/top-bar/toggle-maximize-window.injectable";
|
||||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||||
|
import restartAndInstallUpdateInjectable from "../../renderer/components/update-button/restart-and-install-update.injectable";
|
||||||
|
|
||||||
|
function daysToMilliseconds(days: number) {
|
||||||
|
return Math.round(days * 24 * 60 * 60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
describe("encourage user to update when sufficient time passed since update was downloaded", () => {
|
describe("encourage user to update when sufficient time passed since update was downloaded", () => {
|
||||||
let applicationBuilder: ApplicationBuilder;
|
let applicationBuilder: ApplicationBuilder;
|
||||||
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
|
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
|
||||||
let downloadPlatformUpdateMock: AsyncFnMock<DownloadPlatformUpdate>;
|
let downloadPlatformUpdateMock: AsyncFnMock<DownloadPlatformUpdate>;
|
||||||
|
let restartAndInstallUpdate: jest.MockedFunction<() => void>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
applicationBuilder = getApplicationBuilder();
|
applicationBuilder = getApplicationBuilder();
|
||||||
@ -45,6 +51,8 @@ describe("encourage user to update when sufficient time passed since update was
|
|||||||
mainDi.unoverride(periodicalCheckForUpdateWarningInjectable);
|
mainDi.unoverride(periodicalCheckForUpdateWarningInjectable);
|
||||||
mainDi.permitSideEffects(periodicalCheckForUpdateWarningInjectable);
|
mainDi.permitSideEffects(periodicalCheckForUpdateWarningInjectable);
|
||||||
|
|
||||||
|
rendererDi.override(restartAndInstallUpdateInjectable, () => restartAndInstallUpdate = jest.fn());
|
||||||
|
|
||||||
// TODO: Remove below lines when TopBar are free from side-effects
|
// TODO: Remove below lines when TopBar are free from side-effects
|
||||||
rendererDi.unoverride(openAppContextMenuInjectable);
|
rendererDi.unoverride(openAppContextMenuInjectable);
|
||||||
rendererDi.unoverride(goBackInjectable);
|
rendererDi.unoverride(goBackInjectable);
|
||||||
@ -102,6 +110,63 @@ describe("encourage user to update when sufficient time passed since update was
|
|||||||
|
|
||||||
expect(button).toBeInTheDocument();
|
expect(button).toBeInTheDocument();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("has soft emotional indication in the button", () => {
|
||||||
|
const button = rendered.getByTestId("update-button");
|
||||||
|
|
||||||
|
expect(button).toHaveAttribute("data-warning-level", "light")
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("when button is clicked", () => {
|
||||||
|
it("shows dropdown with update item", () => {
|
||||||
|
const button = rendered.queryByTestId("update-button");
|
||||||
|
|
||||||
|
act(() => button?.click());
|
||||||
|
|
||||||
|
expect(rendered.getByTestId("update-lens-menu-item")).toBeInTheDocument();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("when selected update now, restarts the application to update", () => {
|
||||||
|
const button = rendered.queryByTestId("update-button");
|
||||||
|
|
||||||
|
act(() => button?.click());
|
||||||
|
|
||||||
|
const updateMenuItem = rendered.getByTestId("update-lens-menu-item");
|
||||||
|
|
||||||
|
act(() => updateMenuItem?.click());
|
||||||
|
|
||||||
|
expect(restartAndInstallUpdate).toBeCalled();
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("when dropdown closed without clicking update item", () => {
|
||||||
|
it("does not restart the application to update", async () => {
|
||||||
|
const button = rendered.queryByTestId("update-button");
|
||||||
|
|
||||||
|
act(() => button?.click());
|
||||||
|
|
||||||
|
act(() => button?.click());
|
||||||
|
|
||||||
|
expect(restartAndInstallUpdate).not.toBeCalled();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("given just enough time passes for medium update encouragement", () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
jest.useFakeTimers();
|
||||||
|
jest.advanceTimersByTime(daysToMilliseconds(22));
|
||||||
|
})
|
||||||
|
|
||||||
|
it("has medium emotional indication in the button", () => {
|
||||||
|
const button = rendered.getByTestId("update-button");
|
||||||
|
|
||||||
|
expect(button).toHaveAttribute("data-warning-level", "medium")
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
jest.useRealTimers();
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user