|
| 1 | +jest.mock("electron", () => ({ |
| 2 | + app: {}, |
| 3 | + BrowserWindow: { getAllWindows: () => [] }, |
| 4 | + shell: { openExternal: jest.fn(() => Promise.resolve()) }, |
| 5 | +})); |
| 6 | +jest.mock("electron-updater", () => ({ autoUpdater: { on: jest.fn(), downloadUpdate: jest.fn(), checkForUpdates: jest.fn() } })); |
| 7 | + |
| 8 | +import { shell } from "electron"; |
| 9 | +import { autoUpdater } from "electron-updater"; |
| 10 | +import { StereumUpdater, RELEASES_URL } from "../../../StereumUpdater"; |
| 11 | + |
| 12 | +const logger = { info: jest.fn(), error: jest.fn() }; |
| 13 | +const platform = Object.getOwnPropertyDescriptor(process, "platform"); |
| 14 | +const updaterOn = (name) => { |
| 15 | + Object.defineProperty(process, "platform", { value: name }); |
| 16 | + const updater = new StereumUpdater(logger, jest.fn()); |
| 17 | + updater.updateWindow = { close: jest.fn(() => Promise.resolve()) }; |
| 18 | + return updater; |
| 19 | +}; |
| 20 | + |
| 21 | +afterEach(() => { |
| 22 | + Object.defineProperty(process, "platform", platform); |
| 23 | + jest.clearAllMocks(); |
| 24 | +}); |
| 25 | + |
| 26 | +test.each(["darwin", "win32"])("on %s the update opens the release page and continues into the app", async (name) => { |
| 27 | + const updater = updaterOn(name); |
| 28 | + expect(updater.getUpdateMode()).toEqual({ manual: true, url: RELEASES_URL }); |
| 29 | + await updater.downloadUpdate(); |
| 30 | + expect(shell.openExternal).toHaveBeenCalledWith(RELEASES_URL); |
| 31 | + expect(autoUpdater.downloadUpdate).not.toHaveBeenCalled(); |
| 32 | + expect(updater.updateWindow.close).toHaveBeenCalled(); |
| 33 | + expect(updater.createWindow).toHaveBeenCalledWith(); |
| 34 | +}); |
| 35 | + |
| 36 | +test("on Linux the update still downloads and installs itself", async () => { |
| 37 | + const updater = updaterOn("linux"); |
| 38 | + expect(updater.getUpdateMode().manual).toBe(false); |
| 39 | + await updater.downloadUpdate(); |
| 40 | + expect(autoUpdater.downloadUpdate).toHaveBeenCalled(); |
| 41 | + expect(shell.openExternal).not.toHaveBeenCalled(); |
| 42 | +}); |
0 commit comments