From 0c4e3dcc1ab497b245693a69d9729fbc2c7179fc Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Fri, 1 Jul 2022 09:59:05 +0300 Subject: [PATCH] Replace all usages of "now" from mobx-utils with our own kludge to get rid of shared global state between unit tests Signed-off-by: Janne Savolainen --- src/renderer/components/duration/reactive-duration.tsx | 4 ++-- .../components/status-bar/auto-update-component.tsx | 6 +++--- .../update-button/update-warning-level.injectable.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/renderer/components/duration/reactive-duration.tsx b/src/renderer/components/duration/reactive-duration.tsx index 4430315b38..ce38b82509 100644 --- a/src/renderer/components/duration/reactive-duration.tsx +++ b/src/renderer/components/duration/reactive-duration.tsx @@ -4,9 +4,9 @@ */ import { observer } from "mobx-react"; -import { now } from "mobx-utils"; import React from "react"; import { formatDuration } from "../../utils"; +import { reactiveNow } from "../../../common/utils/reactive-now/reactive-now"; export interface ReactiveDurationProps { timestamp: string | undefined; @@ -42,7 +42,7 @@ export const ReactiveDuration = observer(({ timestamp, compact = true }: Reactiv return ( <> - {formatDuration(now(computeUpdateInterval(timestampSeconds)) - timestampSeconds, compact)} + {formatDuration(reactiveNow(computeUpdateInterval(timestampSeconds)) - timestampSeconds, compact)} ); }); diff --git a/src/renderer/components/status-bar/auto-update-component.tsx b/src/renderer/components/status-bar/auto-update-component.tsx index 5a0b7e8acf..0f6e69c086 100644 --- a/src/renderer/components/status-bar/auto-update-component.tsx +++ b/src/renderer/components/status-bar/auto-update-component.tsx @@ -15,7 +15,7 @@ import type { UpdateIsBeingDownloaded } from "../../../common/application-update import updateIsBeingDownloadedInjectable from "../../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable"; import type { UpdatesAreBeingDiscovered } from "../../../common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable"; import updatesAreBeingDiscoveredInjectable from "../../../common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable"; -import { now as reactiveDateNow } from "mobx-utils"; +import { reactiveNow } from "../../../common/utils/reactive-now/reactive-now"; interface Dependencies { progressOfUpdateDownload: ProgressOfUpdateDownload; @@ -32,10 +32,10 @@ interface EndNoteProps { const EndNote = observer(({ version, note }: EndNoteProps) => { const [start] = useState(Date.now()); - if (start + 5000 <= reactiveDateNow()) { + if (start + 5000 <= reactiveNow()) { return idle(); } - + return note(version ?? ""); }); diff --git a/src/renderer/components/update-button/update-warning-level.injectable.ts b/src/renderer/components/update-button/update-warning-level.injectable.ts index 7db021c472..cc963ab27d 100644 --- a/src/renderer/components/update-button/update-warning-level.injectable.ts +++ b/src/renderer/components/update-button/update-warning-level.injectable.ts @@ -4,8 +4,8 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import { now as reactiveDateNow } from "mobx-utils"; import updateDownloadedDateTimeInjectable from "../../../common/application-update/update-downloaded-date-time/update-downloaded-date-time.injectable"; +import { reactiveNow } from "../../../common/utils/reactive-now/reactive-now"; const updateWarningLevelInjectable = getInjectable({ id: "update-warning-level", @@ -23,7 +23,7 @@ const updateWarningLevelInjectable = getInjectable({ const ONE_DAY = 1000 * 60 * 60 * 24; const downloadedAtTimestamp = new Date(downloadedAt).getTime(); - const currentDateTimeTimestamp = reactiveDateNow(ONE_DAY); + const currentDateTimeTimestamp = reactiveNow(ONE_DAY); const elapsedTime = currentDateTimeTimestamp - downloadedAtTimestamp;