1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Linter fixes

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-06-28 10:23:14 +03:00
parent 4d852b9e02
commit a0bd4c003a
11 changed files with 81 additions and 43 deletions

View File

@ -1,6 +1,11 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import { act, RenderResult } from "@testing-library/react";
import type { RenderResult } from "@testing-library/react";
import { act } from "@testing-library/react";
import type { CheckForPlatformUpdates } from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
import checkForPlatformUpdatesInjectable from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
@ -67,7 +72,7 @@ describe("encourage user to update when sufficient time passed since update was
rendererDi.permitSideEffects(closeWindowInjectable);
rendererDi.permitSideEffects(maximizeWindowInjectable);
rendererDi.permitSideEffects(toggleMaximizeWindowInjectable);
})
});
});
describe("when started", () => {
@ -109,13 +114,13 @@ describe("encourage user to update when sufficient time passed since update was
const button = rendered.queryByTestId("update-button");
expect(button).toBeInTheDocument();
})
});
it("has soft emotional indication in the button", () => {
const button = rendered.getByTestId("update-button");
expect(button).toHaveAttribute("data-warning-level", "light")
})
expect(button).toHaveAttribute("data-warning-level", "light");
});
describe("when button is clicked", () => {
it("shows dropdown with update item", () => {
@ -124,7 +129,7 @@ describe("encourage user to update when sufficient time passed since update was
act(() => button?.click());
expect(rendered.getByTestId("update-lens-menu-item")).toBeInTheDocument();
})
});
it("when selected update now, restarts the application to update", () => {
const button = rendered.queryByTestId("update-button");
@ -136,7 +141,7 @@ describe("encourage user to update when sufficient time passed since update was
act(() => updateMenuItem?.click());
expect(restartAndInstallUpdate).toBeCalled();
})
});
describe("when dropdown closed without clicking update item", () => {
it("does not restart the application to update", async () => {
@ -147,46 +152,46 @@ describe("encourage user to update when sufficient time passed since update was
act(() => button?.click());
expect(restartAndInstallUpdate).not.toBeCalled();
})
})
})
});
});
});
describe("given just enough time passes for medium update encouragement", () => {
beforeAll(() => {
jest.useFakeTimers();
})
});
it("has medium emotional indication in the button", () => {
const button = rendered.getByTestId("update-button");
jest.advanceTimersByTime(daysToMilliseconds(22));
expect(button).toHaveAttribute("data-warning-level", "medium")
})
expect(button).toHaveAttribute("data-warning-level", "medium");
});
afterAll(() => {
jest.useRealTimers();
})
})
});
});
describe("given just enough time passes for severe update encouragement", () => {
beforeAll(() => {
jest.useFakeTimers();
})
});
it("has severe emotional indication in the button", () => {
const button = rendered.getByTestId("update-button");
jest.advanceTimersByTime(daysToMilliseconds(26));
expect(button).toHaveAttribute("data-warning-level", "high")
})
expect(button).toHaveAttribute("data-warning-level", "high");
});
afterAll(() => {
jest.useRealTimers();
})
})
});
});
});
});
});
});
});

View File

@ -3,7 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { MessageChannel, messageChannelInjectionToken } from "../../utils/channel/message-channel-injection-token";
import type { MessageChannel } from "../../utils/channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../../utils/channel/message-channel-injection-token";
export type RestartAndInstallUpdateChannel = MessageChannel;

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable";
import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token";
@ -9,12 +13,12 @@ const updateWarningLevelInjectable = getInjectable({
const createSyncBox = di.inject(createSyncBoxInjectable);
return createSyncBox<"light" | "medium" | "high" | "">(
"update-warning-level",
"",
);
"update-warning-level",
"",
);
},
injectionToken: syncBoxInjectionToken,
});
export default updateWarningLevelInjectable;
export default updateWarningLevelInjectable;

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import setUpdateWarningLevelInjectable from "./set-update-warning-level.injectable";
@ -26,4 +30,4 @@ const periodicalCheckForUpdateWarningInjectable = getInjectable({
causesSideEffects: true,
});
export default periodicalCheckForUpdateWarningInjectable;
export default periodicalCheckForUpdateWarningInjectable;

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import updateDownloadedDateInjectable from "./update-downloaded-date.injectable";
@ -9,8 +13,8 @@ const setUpdateDownloadedDateInjectable = getInjectable({
return (date: Date) => {
downloadedDate.set(date);
}
}
};
},
});
export default setUpdateDownloadedDateInjectable;
export default setUpdateDownloadedDateInjectable;

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import updateDownloadedDateInjectable from "./update-downloaded-date.injectable";
import { UpdateWarningLevelCalculator } from "./update-warning-level-calculator";
@ -12,9 +16,10 @@ const setUpdateWarningLevelInjectable = getInjectable({
return () => {
const newLevel = new UpdateWarningLevelCalculator(updateDownloadedDate.value.get()).get();
updateWarningLevel.set(newLevel);
}
}
};
},
});
export default setUpdateWarningLevelInjectable;
export default setUpdateWarningLevelInjectable;

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { afterRootFrameIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/after-root-frame-is-ready-injection-token";
import downloadUpdateInjectable from "../download-update/download-update.injectable";

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import createSyncBoxInjectable from "../../../common/utils/sync-box/create-sync-box.injectable";
import { syncBoxInjectionToken } from "../../../common/utils/sync-box/sync-box-injection-token";
@ -9,12 +13,12 @@ const updateDownloadedDateInjectable = getInjectable({
const createSyncBox = di.inject(createSyncBoxInjectable);
return createSyncBox<Date | null>(
"update-downloaded-date",
null,
);
"update-downloaded-date",
null,
);
},
injectionToken: syncBoxInjectionToken,
});
export default updateDownloadedDateInjectable;
export default updateDownloadedDateInjectable;

View File

@ -1,12 +1,14 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
type WarningLevel = "high" | "medium" | "light" | "";
export class UpdateWarningLevelCalculator {
private onceADay = 1000 * 60 * 60 * 24;
private level: WarningLevel = "";
constructor (private updateDownloadedDate: Date | null) {
constructor(private updateDownloadedDate: Date | null) {
}
get(): WarningLevel {
@ -48,4 +50,4 @@ export class UpdateWarningLevelCalculator {
this.level = "light";
}
}
}
}

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import restartAndInstallUpdateChannel from "../../../common/application-update/update-warning-level/restart-and-install-update-channel.injectable";
import messageToChannelInjectable from "../../utils/channel/message-to-channel.injectable";
@ -15,4 +19,4 @@ const restartAndInstallUpdateInjectable = getInjectable({
},
});
export default restartAndInstallUpdateInjectable;
export default restartAndInstallUpdateInjectable;

View File

@ -14,7 +14,8 @@ import { Icon } from "../icon";
import { withInjectables } from "@ogre-tools/injectable-react";
import { observer } from "mobx-react";
import updateWarningLevelInjectable from "../../../common/application-update/update-warning-level/update-warning-level.injectable";
import { computed, IComputedValue } from "mobx";
import type { IComputedValue } from "mobx";
import { computed } from "mobx";
import restartAndInstallUpdateInjectable from "./restart-and-install-update.injectable";
interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> {