mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix tests
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
197dbe6cb0
commit
5c8139b025
@ -34,6 +34,10 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
|||||||
return requestMain(broadcastMainChannel, ...args);
|
return requestMain(broadcastMainChannel, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!webContents) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const subFrames = getSubFrames();
|
const subFrames = getSubFrames();
|
||||||
const views = webContents.getAllWebContents();
|
const views = webContents.getAllWebContents();
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
import { BrowserWindow, webContents } from "electron";
|
import { BrowserWindow, webContents } from "electron";
|
||||||
import { broadcastMessage } from "../../common/ipc";
|
import { broadcastMessage } from "../../common/ipc";
|
||||||
|
|
||||||
type WindowAction = "goBack" | "goForward" | "minimize" | "toggleMaximize" | "close";
|
type WindowAction = "back" | "forward" | "minimize" | "toggleMaximize" | "close";
|
||||||
|
|
||||||
export function windowAction(action: WindowAction) {
|
export function windowAction(action: WindowAction) {
|
||||||
const window = BrowserWindow.getFocusedWindow();
|
const window = BrowserWindow.getFocusedWindow();
|
||||||
@ -30,12 +30,12 @@ export function windowAction(action: WindowAction) {
|
|||||||
if (!window) return;
|
if (!window) return;
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "goBack": {
|
case "back": {
|
||||||
window.webContents.goBack();
|
window.webContents.goBack();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "goForward": {
|
case "forward": {
|
||||||
window.webContents.goForward();
|
window.webContents.goForward();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -59,18 +59,6 @@ export function windowAction(action: WindowAction) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action === "goBack") {
|
|
||||||
window.webContents.goBack();
|
|
||||||
} else if (action === "goForward") {
|
|
||||||
window.webContents.goForward();
|
|
||||||
} else if (action === "toggleMaximize") {
|
|
||||||
if (window.isMaximized()) {
|
|
||||||
window.unmaximize();
|
|
||||||
} else {
|
|
||||||
window.maximize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onLocationChange() {
|
export function onLocationChange() {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { fireEvent } from "@testing-library/react";
|
|||||||
import "@testing-library/jest-dom/extend-expect";
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
import { TopBar } from "./top-bar";
|
import { TopBar } from "./top-bar";
|
||||||
import { IpcMainWindowEvents } from "../../../../common/ipc";
|
import { IpcMainWindowEvents } from "../../../../common/ipc";
|
||||||
import { broadcastMessage } from "../../../../common/ipc";
|
import { broadcastMessage, requestMain } from "../../../../common/ipc";
|
||||||
import * as vars from "../../../../common/vars";
|
import * as vars from "../../../../common/vars";
|
||||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||||
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
||||||
@ -33,23 +33,6 @@ jest.mock("../../../../common/vars", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockMinimize = jest.fn();
|
|
||||||
const mockMaximize = jest.fn();
|
|
||||||
const mockUnmaximize = jest.fn();
|
|
||||||
const mockClose = jest.fn();
|
|
||||||
|
|
||||||
jest.mock("@electron/remote", () => {
|
|
||||||
return {
|
|
||||||
getCurrentWindow: () => ({
|
|
||||||
minimize: () => mockMinimize(),
|
|
||||||
maximize: () => mockMaximize(),
|
|
||||||
unmaximize: () => mockUnmaximize(),
|
|
||||||
close: () => mockClose(),
|
|
||||||
isMaximized: () => false,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("<TopBar/> in Windows and Linux", () => {
|
describe("<TopBar/> in Windows and Linux", () => {
|
||||||
let render: DiRender;
|
let render: DiRender;
|
||||||
|
|
||||||
@ -107,12 +90,12 @@ describe("<TopBar/> in Windows and Linux", () => {
|
|||||||
expect(broadcastMessage).toHaveBeenCalledWith(IpcMainWindowEvents.OPEN_CONTEXT_MENU);
|
expect(broadcastMessage).toHaveBeenCalledWith(IpcMainWindowEvents.OPEN_CONTEXT_MENU);
|
||||||
|
|
||||||
fireEvent.click(minimize);
|
fireEvent.click(minimize);
|
||||||
expect(mockMinimize).toHaveBeenCalled();
|
expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "minimize");
|
||||||
|
|
||||||
fireEvent.click(maximize);
|
fireEvent.click(maximize);
|
||||||
expect(mockMaximize).toHaveBeenCalled();
|
expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "toggleMaximize");
|
||||||
|
|
||||||
fireEvent.click(close);
|
fireEvent.click(close);
|
||||||
expect(mockClose).toHaveBeenCalled();
|
expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "close");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -12,9 +12,9 @@ import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injec
|
|||||||
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
||||||
import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import directoryForUserDataInjectable
|
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
|
||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
|
import { IpcMainWindowEvents } from "../../../../common/ipc";
|
||||||
|
|
||||||
jest.mock("../../../../common/vars", () => {
|
jest.mock("../../../../common/vars", () => {
|
||||||
const SemVer = require("semver").SemVer;
|
const SemVer = require("semver").SemVer;
|
||||||
@ -27,6 +27,9 @@ jest.mock("../../../../common/vars", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const goBack = jest.fn();
|
||||||
|
const goForward = jest.fn();
|
||||||
|
|
||||||
jest.mock(
|
jest.mock(
|
||||||
"electron",
|
"electron",
|
||||||
() => ({
|
() => ({
|
||||||
@ -42,6 +45,25 @@ jest.mock(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
invoke: jest.fn(
|
||||||
|
(channel: string, action: string) => {
|
||||||
|
console.log("channel", channel, action);
|
||||||
|
|
||||||
|
if (channel !== IpcMainWindowEvents.WINDOW_ACTION) return;
|
||||||
|
|
||||||
|
switch(action) {
|
||||||
|
case "back": {
|
||||||
|
goBack();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "forward": {
|
||||||
|
goForward();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -50,24 +72,6 @@ jest.mock("../../+catalog", () => ({
|
|||||||
previousActiveTab: jest.fn(),
|
previousActiveTab: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const goBack = jest.fn();
|
|
||||||
const goForward = jest.fn();
|
|
||||||
|
|
||||||
jest.mock("@electron/remote", () => {
|
|
||||||
return {
|
|
||||||
webContents: {
|
|
||||||
getAllWebContents: () => {
|
|
||||||
return [{
|
|
||||||
getType: () => "window",
|
|
||||||
goBack,
|
|
||||||
goForward,
|
|
||||||
}];
|
|
||||||
},
|
|
||||||
},
|
|
||||||
getCurrentWindow: () => jest.fn(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("<TopBar/>", () => {
|
describe("<TopBar/>", () => {
|
||||||
let di: ConfigurableDependencyInjectionContainer;
|
let di: ConfigurableDependencyInjectionContainer;
|
||||||
let render: DiRender;
|
let render: DiRender;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user