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

Remove duplication from behavioural unit test

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-06-28 13:36:28 +03:00
parent 05ef1495e7
commit ca9a7460dd
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A

View File

@ -28,6 +28,8 @@ describe("encourage user to update when sufficient time passed since update was
let quitAndInstallUpdateMock: jest.MockedFunction<() => void>; let quitAndInstallUpdateMock: jest.MockedFunction<() => void>;
beforeEach(() => { beforeEach(() => {
jest.useFakeTimers();
applicationBuilder = getApplicationBuilder(); applicationBuilder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(({ mainDi }) => { applicationBuilder.beforeApplicationStart(({ mainDi }) => {
@ -79,95 +81,62 @@ describe("encourage user to update when sufficient time passed since update was
}); });
describe("when update downloaded", () => { describe("when update downloaded", () => {
let button: HTMLElement;
beforeEach(async () => { beforeEach(async () => {
await checkForPlatformUpdatesMock.resolve({ await checkForPlatformUpdatesMock.resolve({
updateWasDiscovered: true, updateWasDiscovered: true,
version: "some-version", version: "some-version",
}); });
await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true }); await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true });
await processCheckingForUpdatesPromise; await processCheckingForUpdatesPromise;
button = rendered.getByTestId("update-button");
}); });
it("shows update button to help user to update", () => { it("shows update button to help user to update", () => {
const button = rendered.queryByTestId("update-button");
expect(button).toBeInTheDocument(); expect(button).toBeInTheDocument();
}); });
it("has soft emotional indication in the button", () => { 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", () => { describe("when button is clicked", () => {
beforeEach(() => {
act(() => button.click());
});
it("shows dropdown with update item", () => { it("shows dropdown with update item", () => {
const button = rendered.queryByTestId("update-button");
act(() => button?.click());
expect(rendered.getByTestId("update-lens-menu-item")).toBeInTheDocument(); expect(rendered.getByTestId("update-lens-menu-item")).toBeInTheDocument();
}); });
it("when selected update now, restarts the application to update", () => { it("when selected update now, restarts the application to update", () => {
const button = rendered.queryByTestId("update-button");
act(() => button?.click());
const updateMenuItem = rendered.getByTestId("update-lens-menu-item"); const updateMenuItem = rendered.getByTestId("update-lens-menu-item");
act(() => updateMenuItem?.click()); act(() => updateMenuItem.click());
expect(quitAndInstallUpdateMock).toBeCalled(); expect(quitAndInstallUpdateMock).toBeCalled();
}); });
describe("when dropdown closed without clicking update item", () => { it("when dropdown closed without clicking update item, does not restart the application to update", () => {
it("does not restart the application to update", async () => { act(() => button.click());
const button = rendered.queryByTestId("update-button");
act(() => button?.click()); expect(quitAndInstallUpdateMock).not.toBeCalled();
act(() => button?.click());
expect(quitAndInstallUpdateMock).not.toBeCalled();
});
}); });
}); });
describe("given just enough time passes for medium update encouragement", () => { it("given just enough time passes for medium update encouragement, has medium emotional indication in the button", () => {
beforeAll(() => { jest.advanceTimersByTime(daysToMilliseconds(22));
jest.useFakeTimers();
});
it("has medium emotional indication in the button", () => { expect(button).toHaveAttribute("data-warning-level", "medium");
const button = rendered.getByTestId("update-button");
jest.advanceTimersByTime(daysToMilliseconds(22));
expect(button).toHaveAttribute("data-warning-level", "medium");
});
afterAll(() => {
jest.useRealTimers();
});
}); });
describe("given just enough time passes for severe update encouragement", () => { it("given just enough time passes for severe update encouragement, has severe emotional indication in the button", () => {
beforeAll(() => { jest.advanceTimersByTime(daysToMilliseconds(26));
jest.useFakeTimers();
});
it("has severe emotional indication in the button", () => { expect(button).toHaveAttribute("data-warning-level", "high");
const button = rendered.getByTestId("update-button");
jest.advanceTimersByTime(daysToMilliseconds(26));
expect(button).toHaveAttribute("data-warning-level", "high");
});
afterAll(() => {
jest.useRealTimers();
});
}); });
}); });
}); });