1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/behaviours/update-app/trigger-updating-using-tray.test.ts
Janne Savolainen 1f0918b0a5
Introduce a tray item for updating application
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-06-03 07:45:28 +03:00

97 lines
3.1 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import quitAndInstallUpdateInjectable from "../../main/electron-app/features/quit-and-install-update.injectable";
import type { RenderResult } from "@testing-library/react";
describe("trigger updating using tray", () => {
let applicationBuilder: ApplicationBuilder;
let quitAndInstallUpdateMock: jest.Mock;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
quitAndInstallUpdateMock = jest.fn();
mainDi.override(quitAndInstallUpdateInjectable, () => quitAndInstallUpdateMock);
});
});
describe("given no update available, when started", () => {
let rendered: RenderResult;
beforeEach(async () => {
rendered = await applicationBuilder.render();
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("does not quit and install update yet", () => {
expect(quitAndInstallUpdateMock).not.toHaveBeenCalled();
});
it("does not have possibility to trigger installation of an update", () => {
const trayItem = applicationBuilder.tray.get("trigger-application-update");
expect(trayItem).toBe(undefined);
});
describe("when an update becomes available", () => {
beforeEach(() => {
applicationBuilder.applicationUpdater.makeUpdateAvailable(true);
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("does not quit and install update yet", () => {
expect(quitAndInstallUpdateMock).not.toHaveBeenCalled();
});
it("has possibility to trigger installation of the update", () => {
const trayItem = applicationBuilder.tray.get("trigger-application-update");
expect(trayItem).not.toBe(undefined);
});
describe("when triggering installation of the update", () => {
beforeEach(() => {
applicationBuilder.tray.click("trigger-application-update");
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("quits application and installs update", () => {
expect(quitAndInstallUpdateMock).toHaveBeenCalled();
});
});
describe("when update becomes unavailable", () => {
beforeEach(async () => {
applicationBuilder.applicationUpdater.makeUpdateAvailable(false);
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("does not have possibility to trigger installation of the update", () => {
const trayItem = applicationBuilder.tray.get("trigger-application-update");
expect(trayItem).toBe(undefined);
});
});
});
});
});