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

Testing warning level changes over time

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-31 15:03:05 +03:00
parent 73969ed17a
commit 1bd4c46ed2
2 changed files with 46 additions and 5 deletions

View File

@ -32,13 +32,14 @@ describe("app-update-warning", () => {
removeItem: jest.fn(),
clear: jest.fn(),
}) as never);
appUpdateWarning = di.inject(appUpdateWarningInjectable);
appUpdateWarning.init();
});
describe("given AppUpdateWarning with update date set", () => {
describe("given AppUpdateWarning with update date set throught the event", () => {
beforeEach(() => {
appUpdateWarning = di.inject(appUpdateWarningInjectable);
appUpdateWarning.init();
});
it.skip("returns light warning level when update-downloaded event received", () => {
expect(appUpdateWarning.warningLevel).toBe("light");
});
@ -126,4 +127,42 @@ describe("app-update-warning", () => {
});
});
});
describe("given AppUpdateWarning with warning level changing over time", () => {
let appUpdateWarning: AppUpdateWarning;
beforeEach(() => {
jest.useFakeTimers("modern");
jest.setSystemTime(new Date("2022-05-30T05:30:00.000Z").getTime());
jest.spyOn(global, "setInterval");
appUpdateWarning = di.inject(appUpdateWarningInjectable);
appUpdateWarning.init();
})
afterEach(() => {
jest.useRealTimers();
});
it("calls setInterval with correct arguments", () => {
const onceADay = 1000 * 60 * 60 * 24;
expect(setInterval).toHaveBeenCalledTimes(1);
expect(setInterval).toHaveBeenCalledWith(expect.any(Function), onceADay);
});
it("shows light warning level if less than 20 days passed", () => {
jest.advanceTimersByTime(1000 * 60 * 60 * 24 * 5);
expect(appUpdateWarning.warningLevel).toBe("light");
});
it("shows medium warning level if more than 20 days passed", () => {
jest.advanceTimersByTime(1000 * 60 * 60 * 24 * 21);
expect(appUpdateWarning.warningLevel).toBe("medium");
});
it("shows high warning level if more than 2 days passed", () => {
jest.advanceTimersByTime(1000 * 60 * 60 * 24 * 30);
expect(appUpdateWarning.warningLevel).toBe("high");
});
});
});

View File

@ -11,6 +11,8 @@ const appUpdateWarningInjectable = getInjectable({
id: "app-update-warning",
instantiate: (di) => {
AppUpdateWarning.resetInstance();
return AppUpdateWarning.createInstance({
ipcRenderer: di.inject(ipcRendererInjectable),
sessionStorage: di.inject(sessionStorageInjectable),