Introduce a tray item for updating application

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen committed 2022-05-20 14:07:53 +03:00
1 parent 8d3bc40aa9
commit 84ac22904d
13 files changed
+359 -2

No files matched your search

@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`trigger updating using tray given no update available, when started renders 1`] = `
<body>
<div />
</body>
`;
exports[`trigger updating using tray given no update available, when started when an update becomes available renders 1`] = `
<body>
<div />
</body>
`;
exports[`trigger updating using tray given no update available, when started when an update becomes available when triggering installation of the update renders 1`] = `
<body>
<div />
</body>
`;
exports[`trigger updating using tray given no update available, when started when an update becomes available when update becomes unavailable renders 1`] = `
<body>
<div />
</body>
`;
@@ -0,0 +1,96 @@
/**
* 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);
});
});
});
});
});