mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make a primitive argument an object for readability
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
ac4642ec04
commit
6411b225c0
@ -159,7 +159,7 @@ describe("installing update using tray", () => {
|
||||
progressOfUpdateDownloadInjectable,
|
||||
);
|
||||
|
||||
progressOfUpdateDownload.set(42);
|
||||
progressOfUpdateDownload.set({ percentage: 42 });
|
||||
|
||||
expect(
|
||||
applicationBuilder.tray.get("check-for-updates")?.label?.get(),
|
||||
|
||||
@ -6,13 +6,17 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import createSyncBoxInjectable from "../../sync-box/create-sync-box.injectable";
|
||||
import { syncBoxInjectionToken } from "../../sync-box/sync-box-injection-token";
|
||||
|
||||
export interface ProgressOfDownload {
|
||||
percentage: number;
|
||||
}
|
||||
|
||||
const progressOfUpdateDownloadInjectable = getInjectable({
|
||||
id: "progress-of-update-download-state",
|
||||
|
||||
instantiate: (di) => {
|
||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||
|
||||
return createSyncBox("progress-of-update-download", 0);
|
||||
return createSyncBox<ProgressOfDownload>("progress-of-update-download", { percentage: 0 });
|
||||
},
|
||||
|
||||
injectionToken: syncBoxInjectionToken,
|
||||
|
||||
@ -41,7 +41,7 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
|
||||
|
||||
assert(discoveredVersion);
|
||||
|
||||
return `Downloading update ${discoveredVersion.version} (${progressOfUpdateDownload.value.get()}%)...`;
|
||||
return `Downloading update ${discoveredVersion.version} (${progressOfUpdateDownload.value.get().percentage}%)...`;
|
||||
}
|
||||
|
||||
if (checkingForUpdatesState.value.get()) {
|
||||
|
||||
@ -6,9 +6,10 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import electronUpdaterInjectable from "../../electron-app/features/electron-updater.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import type { ProgressInfo } from "electron-updater";
|
||||
import type { ProgressOfDownload } from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
||||
|
||||
export type DownloadPlatformUpdate = (
|
||||
onDownloadProgress: (percentage: number) => void
|
||||
onDownloadProgress: (arg: ProgressOfDownload) => void
|
||||
) => Promise<{ downloadWasSuccessful: boolean }>;
|
||||
|
||||
const downloadPlatformUpdateInjectable = getInjectable({
|
||||
@ -19,9 +20,10 @@ const downloadPlatformUpdateInjectable = getInjectable({
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return async (onDownloadProgress) => {
|
||||
onDownloadProgress(0);
|
||||
onDownloadProgress({ percentage: 0 });
|
||||
|
||||
const updateDownloadProgress = ({ percent }: ProgressInfo) => onDownloadProgress(percent);
|
||||
const updateDownloadProgress = ({ percent: percentage }: ProgressInfo) =>
|
||||
onDownloadProgress({ percentage });
|
||||
|
||||
electronUpdater.on("download-progress", updateDownloadProgress);
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
*/
|
||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||
import electronUpdaterInjectable from "../../electron-app/features/electron-updater.injectable";
|
||||
import type { DownloadPlatformUpdate } from "./download-platform-update.injectable";
|
||||
import downloadPlatformUpdateInjectable from "./download-platform-update.injectable";
|
||||
import type { AppUpdater } from "electron-updater";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
@ -14,7 +15,7 @@ import loggerInjectable from "../../../common/logger.injectable";
|
||||
import type { Logger } from "../../../common/logger";
|
||||
|
||||
describe("download-platform-update", () => {
|
||||
let downloadPlatformUpdate: (onDownloadProgress: (percentage: number) => void) => Promise<{ downloadWasSuccessful: boolean }>;
|
||||
let downloadPlatformUpdate: DownloadPlatformUpdate;
|
||||
let downloadUpdateMock: AsyncFnMock<() => void>;
|
||||
let electronUpdaterFake: AppUpdater;
|
||||
let electronUpdaterOnMock: jest.Mock;
|
||||
@ -68,7 +69,7 @@ describe("download-platform-update", () => {
|
||||
});
|
||||
|
||||
it("starts progress of download from 0", () => {
|
||||
expect(onDownloadProgressMock).toHaveBeenCalledWith(0);
|
||||
expect(onDownloadProgressMock).toHaveBeenCalledWith({ percentage: 0 });
|
||||
});
|
||||
|
||||
describe("when downloading progresses", () => {
|
||||
@ -89,7 +90,7 @@ describe("download-platform-update", () => {
|
||||
});
|
||||
|
||||
it("updates progress of the download", () => {
|
||||
expect(onDownloadProgressMock).toHaveBeenCalledWith(42);
|
||||
expect(onDownloadProgressMock).toHaveBeenCalledWith({ percentage: 42 });
|
||||
});
|
||||
|
||||
describe("when downloading resolves", () => {
|
||||
@ -119,7 +120,7 @@ describe("download-platform-update", () => {
|
||||
it("when starting download again, resets progress of download", () => {
|
||||
downloadPlatformUpdate(onDownloadProgressMock);
|
||||
|
||||
expect(onDownloadProgressMock).toHaveBeenCalledWith(0);
|
||||
expect(onDownloadProgressMock).toHaveBeenCalledWith({ percentage: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import downloadPlatformUpdateInjectable from "../download-platform-update/downlo
|
||||
import updateIsBeingDownloadedInjectable from "../../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable";
|
||||
import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable";
|
||||
import { action, runInAction } from "mobx";
|
||||
import type { ProgressOfDownload } from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
||||
import progressOfUpdateDownloadInjectable from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
||||
|
||||
const downloadUpdateInjectable = getInjectable({
|
||||
@ -18,13 +19,13 @@ const downloadUpdateInjectable = getInjectable({
|
||||
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
|
||||
const progressOfUpdateDownload = di.inject(progressOfUpdateDownloadInjectable);
|
||||
|
||||
const updateDownloadProgress = action((percentage: number) => {
|
||||
progressOfUpdateDownload.set(percentage);
|
||||
const updateDownloadProgress = action((progressOfDownload: ProgressOfDownload) => {
|
||||
progressOfUpdateDownload.set(progressOfDownload);
|
||||
});
|
||||
|
||||
return async () => {
|
||||
runInAction(() => {
|
||||
progressOfUpdateDownload.set(0);
|
||||
progressOfUpdateDownload.set({ percentage: 0 });
|
||||
downloadingUpdateState.set(true);
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user