mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix flaky unit test (#5661)
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
96ed99a06b
commit
d1f5f1cdef
@ -12,7 +12,6 @@ import type { AsyncFnMock } from "@async-fn/jest";
|
|||||||
import asyncFn from "@async-fn/jest";
|
import asyncFn from "@async-fn/jest";
|
||||||
import type { ElectronWindow, LensWindowConfiguration } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
import type { ElectronWindow, LensWindowConfiguration } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import { flushPromises } from "../../common/test-utils/flush-promises";
|
|
||||||
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
||||||
|
|
||||||
describe("opening application window using tray", () => {
|
describe("opening application window using tray", () => {
|
||||||
@ -24,17 +23,28 @@ describe("opening application window using tray", () => {
|
|||||||
let callForApplicationWindowHtmlMock: AsyncFnMock<() => void>;
|
let callForApplicationWindowHtmlMock: AsyncFnMock<() => void>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
callForSplashWindowHtmlMock = asyncFn();
|
||||||
|
callForApplicationWindowHtmlMock = asyncFn();
|
||||||
|
|
||||||
applicationBuilder = getApplicationBuilder().beforeApplicationStart(
|
applicationBuilder = getApplicationBuilder().beforeApplicationStart(
|
||||||
({ mainDi }) => {
|
({ mainDi }) => {
|
||||||
mainDi.override(lensResourcesDirInjectable, () => "some-lens-resources-directory");
|
mainDi.override(lensResourcesDirInjectable, () => "some-lens-resources-directory");
|
||||||
|
|
||||||
|
const loadFileMock = jest
|
||||||
|
.fn(callForSplashWindowHtmlMock)
|
||||||
|
.mockImplementationOnce(() => Promise.resolve());
|
||||||
|
|
||||||
|
const loadUrlMock = jest
|
||||||
|
.fn(callForApplicationWindowHtmlMock)
|
||||||
|
.mockImplementationOnce(() => Promise.resolve());
|
||||||
|
|
||||||
createElectronWindowMock = jest.fn((configuration: LensWindowConfiguration) =>
|
createElectronWindowMock = jest.fn((configuration: LensWindowConfiguration) =>
|
||||||
({
|
({
|
||||||
splash: {
|
splash: {
|
||||||
send: () => {},
|
send: () => {},
|
||||||
close: () => {},
|
close: () => {},
|
||||||
show: () => {},
|
show: () => {},
|
||||||
loadFile: callForSplashWindowHtmlMock,
|
loadFile: loadFileMock,
|
||||||
loadUrl: () => { throw new Error("Should never come here"); },
|
loadUrl: () => { throw new Error("Should never come here"); },
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -43,7 +53,7 @@ describe("opening application window using tray", () => {
|
|||||||
close: () => {},
|
close: () => {},
|
||||||
show: () => {},
|
show: () => {},
|
||||||
loadFile: () => { throw new Error("Should never come here"); },
|
loadFile: () => { throw new Error("Should never come here"); },
|
||||||
loadUrl: callForApplicationWindowHtmlMock,
|
loadUrl: loadUrlMock,
|
||||||
},
|
},
|
||||||
}[configuration.id] as ElectronWindow));
|
}[configuration.id] as ElectronWindow));
|
||||||
|
|
||||||
@ -54,20 +64,10 @@ describe("opening application window using tray", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expectWindowsToBeOpen = expectWindowsToBeOpenFor(mainDi);
|
expectWindowsToBeOpen = expectWindowsToBeOpenFor(mainDi);
|
||||||
|
|
||||||
callForSplashWindowHtmlMock = asyncFn();
|
|
||||||
callForApplicationWindowHtmlMock = asyncFn();
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderPromise = applicationBuilder.render();
|
await applicationBuilder.render();
|
||||||
|
|
||||||
await flushPromises();
|
|
||||||
|
|
||||||
await callForSplashWindowHtmlMock.resolve();
|
|
||||||
await callForApplicationWindowHtmlMock.resolve();
|
|
||||||
|
|
||||||
await renderPromise;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("only an application window is open", () => {
|
it("only an application window is open", () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user