-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`App Menu should create the app menu 1`] = ` | ||
Array [ | ||
Array [ | ||
Array [ | ||
Object { | ||
"label": "Cosmos Voyager", | ||
"submenu": Array [ | ||
Object { | ||
"click": [Function], | ||
"label": "About Cosmos Voyager", | ||
"selector": "orderFrontStandardAboutPanel:", | ||
}, | ||
Object { | ||
"type": "separator", | ||
}, | ||
Object { | ||
"accelerator": "Command+Q", | ||
"click": [Function], | ||
"label": "Quit", | ||
}, | ||
], | ||
}, | ||
Object { | ||
"label": "Edit", | ||
"submenu": Array [ | ||
Object { | ||
"accelerator": "CmdOrCtrl+X", | ||
"label": "Cut", | ||
"selector": "cut:", | ||
}, | ||
Object { | ||
"accelerator": "CmdOrCtrl+C", | ||
"label": "Copy", | ||
"selector": "copy:", | ||
}, | ||
Object { | ||
"accelerator": "CmdOrCtrl+V", | ||
"label": "Paste", | ||
"selector": "paste:", | ||
}, | ||
], | ||
}, | ||
], | ||
], | ||
] | ||
`; | ||
|
||
exports[`App Menu should create the app menu 2`] = ` | ||
Array [ | ||
Array [ | ||
undefined, | ||
], | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const { join } = require("path") | ||
|
||
let mainWindow | ||
describe("App Menu", () => { | ||
beforeEach(() => { | ||
jest.resetModules() | ||
jest.unmock("electron") | ||
|
||
mainWindow = { | ||
webContents: { send: jest.fn() } | ||
} | ||
|
||
jest.mock("electron", () => ({ | ||
Menu: { | ||
buildFromTemplate: jest.fn(menu => { | ||
menu | ||
}), | ||
setApplicationMenu: jest.fn() | ||
}, | ||
app: { | ||
quit: jest.fn() | ||
} | ||
})) | ||
|
||
let createMenu = require("../../../app/src/main/menu.js") | ||
|
||
createMenu(mainWindow) | ||
}) | ||
|
||
it("should create the app menu", function() { | ||
expect( | ||
require("electron").Menu.buildFromTemplate.mock.calls | ||
).toMatchSnapshot() | ||
expect( | ||
require("electron").Menu.setApplicationMenu.mock.calls | ||
).toMatchSnapshot() | ||
}) | ||
|
||
it("should quit app when clicking Quit menu item", function() { | ||
let menu = require("electron").Menu.buildFromTemplate.mock.calls[0][0] | ||
let quitItem = menu | ||
.find(({ label }) => label === "Cosmos Voyager") | ||
.submenu.find(({ label }) => label === "Quit") | ||
|
||
expect(require("electron").app.quit.mock.calls.length).toBe(0) | ||
quitItem.click() | ||
expect(require("electron").app.quit.mock.calls.length).toBe(1) | ||
}) | ||
|
||
it("should send 'open-about-menu' when clicking 'About'", function() { | ||
process.platform = "linux" | ||
let menu = require("electron").Menu.buildFromTemplate.mock.calls[0][0] | ||
let aboutItem = menu | ||
.find(({ label }) => label === "Cosmos Voyager") | ||
.submenu.find(({ label }) => label === "About Cosmos Voyager") | ||
|
||
expect(mainWindow.webContents.send.mock.calls.length).toBe(0) | ||
aboutItem.click() | ||
expect(mainWindow.webContents.send.mock.calls.length).toBe(1) | ||
expect(mainWindow.webContents.send.mock.calls[0][0]).toBe("open-about-menu") | ||
}) | ||
|
||
it("should not send 'open-about-menu' when clicking 'About' on mac", function() { | ||
process.platform = "darwin" | ||
let menu = require("electron").Menu.buildFromTemplate.mock.calls[0][0] | ||
let aboutItem = menu | ||
.find(({ label }) => label === "Cosmos Voyager") | ||
.submenu.find(({ label }) => label === "About Cosmos Voyager") | ||
|
||
expect(mainWindow.webContents.send.mock.calls.length).toBe(0) | ||
aboutItem.click() | ||
expect(mainWindow.webContents.send.mock.calls.length).toBe(0) | ||
}) | ||
}) |