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);
|
||||
}
|
||||
|
||||
if (!webContents) {
|
||||
return;
|
||||
}
|
||||
|
||||
const subFrames = getSubFrames();
|
||||
const views = webContents.getAllWebContents();
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
import { BrowserWindow, webContents } from "electron";
|
||||
import { broadcastMessage } from "../../common/ipc";
|
||||
|
||||
type WindowAction = "goBack" | "goForward" | "minimize" | "toggleMaximize" | "close";
|
||||
type WindowAction = "back" | "forward" | "minimize" | "toggleMaximize" | "close";
|
||||
|
||||
export function windowAction(action: WindowAction) {
|
||||
const window = BrowserWindow.getFocusedWindow();
|
||||
@ -30,12 +30,12 @@ export function windowAction(action: WindowAction) {
|
||||
if (!window) return;
|
||||
|
||||
switch (action) {
|
||||
case "goBack": {
|
||||
case "back": {
|
||||
window.webContents.goBack();
|
||||
break;
|
||||
}
|
||||
|
||||
case "goForward": {
|
||||
case "forward": {
|
||||
window.webContents.goForward();
|
||||
break;
|
||||
}
|
||||
@ -59,18 +59,6 @@ export function windowAction(action: WindowAction) {
|
||||
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() {
|
||||
|
||||
@ -8,7 +8,7 @@ import { fireEvent } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
import { TopBar } from "./top-bar";
|
||||
import { IpcMainWindowEvents } from "../../../../common/ipc";
|
||||
import { broadcastMessage } from "../../../../common/ipc";
|
||||
import { broadcastMessage, requestMain } from "../../../../common/ipc";
|
||||
import * as vars from "../../../../common/vars";
|
||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||
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", () => {
|
||||
let render: DiRender;
|
||||
|
||||
@ -107,12 +90,12 @@ describe("<TopBar/> in Windows and Linux", () => {
|
||||
expect(broadcastMessage).toHaveBeenCalledWith(IpcMainWindowEvents.OPEN_CONTEXT_MENU);
|
||||
|
||||
fireEvent.click(minimize);
|
||||
expect(mockMinimize).toHaveBeenCalled();
|
||||
expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "minimize");
|
||||
|
||||
fireEvent.click(maximize);
|
||||
expect(mockMaximize).toHaveBeenCalled();
|
||||
expect(requestMain).toHaveBeenCalledWith(IpcMainWindowEvents.WINDOW_ACTION, "toggleMaximize");
|
||||
|
||||
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 topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
||||
import { computed } from "mobx";
|
||||
import directoryForUserDataInjectable
|
||||
from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import mockFs from "mock-fs";
|
||||
import { IpcMainWindowEvents } from "../../../../common/ipc";
|
||||
|
||||
jest.mock("../../../../common/vars", () => {
|
||||
const SemVer = require("semver").SemVer;
|
||||
@ -27,6 +27,9 @@ jest.mock("../../../../common/vars", () => {
|
||||
};
|
||||
});
|
||||
|
||||
const goBack = jest.fn();
|
||||
const goForward = jest.fn();
|
||||
|
||||
jest.mock(
|
||||
"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(),
|
||||
}));
|
||||
|
||||
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/>", () => {
|
||||
let di: ConfigurableDependencyInjectionContainer;
|
||||
let render: DiRender;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user