Skip to content

Commit

Permalink
单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
niuniuland committed Nov 20, 2023
1 parent 64c99c9 commit 1e0cb93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 5 additions & 7 deletions packages/main/src/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ async function createWindow() {
}
});


browserWindow.webContents.on('will-navigate', (event, url) => {
browserWindow.webContents?.on('will-navigate', (event, url) => {
if (url !== browserWindow.webContents.getURL()) {
event.preventDefault();
shell.openExternal(url);
Expand All @@ -48,20 +47,20 @@ async function createWindow() {
/**
* icpMain
*/
ipcMain.handle('close', () => {
ipcMain?.handle('close', () => {
browserWindow?.close();
});
ipcMain.handle('minimize', () => {
ipcMain?.handle('minimize', () => {
browserWindow.minimize();
});
ipcMain.handle('maximize', () => {
ipcMain?.handle('maximize', () => {
if (browserWindow.isMaximized()) {
browserWindow.unmaximize();
} else {
browserWindow.maximize();
}
});
ipcMain.handle('isMaximized', () => {
ipcMain?.handle('isMaximized', () => {
return browserWindow.isMaximized();
});

Expand Down Expand Up @@ -93,7 +92,6 @@ async function createWindow() {
* Restore an existing BrowserWindow or Create a new BrowserWindow.
*/
export async function restoreOrCreateWindow() {

let window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed());

if (window === undefined) {
Expand Down
8 changes: 7 additions & 1 deletion packages/main/tests/unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ vi.mock('electron', () => {
},
};

return {BrowserWindow: bw, app};
// 模拟 ipcMain
const ipcMain = {
handle: vi.fn(),
// 根据需要模拟其他 ipcMain 方法
};

return { BrowserWindow: bw, app, ipcMain };
});

beforeEach(() => {
Expand Down

0 comments on commit 1e0cb93

Please sign in to comment.