Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows/Linux "About" window #885

Merged
merged 17 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Fixed critical dependency warning @okwme
* Fixed theme bg bug @okwme
* Fixed sorting bug on staking page @okwme
* "About Cosmos Voyager" menu item is now responsive on Windows and Linux @mappum
* Fixed preference page style bug @okwme
* Fixed missing node-ip in connection indicator @faboweb
* Launch sequence for dev improved @okwme
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function createWindow() {

// addMenu overwrites the default menu to only hold copy/paste actions to not confuse the user
// In development mode we want all the options including switching the devtools
if (!DEV) addMenu()
if (!DEV) addMenu(mainWindow)
}

function startProcess(name, args, env) {
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/menu.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { app, Menu } = require("electron")

module.exports = function() {
module.exports = function(mainWindow) {
let template = [
{
label: "Cosmos Voyager",
submenu: [
{
label: "About Cosmos Voyager",
selector: "orderFrontStandardAboutPanel:"
selector: "orderFrontStandardAboutPanel:",
click: () => openAboutMenu(mainWindow)
},
{ type: "separator" },
{
Expand Down Expand Up @@ -42,3 +43,8 @@ module.exports = function() {
let menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}

function openAboutMenu(mainWindow) {
if (process.platform === "darwin") return
mainWindow.webContents.send("open-about-menu")
}
6 changes: 5 additions & 1 deletion app/src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ async function main() {
console.log(hash)
store.commit("setNodeApprovalRequired", hash)
})
ipcRenderer.on("open-about-menu", event => {
// TODO: create an about page
router.push("/preferences")
})

let firstStart = true
ipcRenderer.on("connected", (event, nodeIP) => {
Expand All @@ -89,7 +93,7 @@ async function main() {

ipcRenderer.send("booted")

new Vue({
return new Vue({
router,
...App,
store
Expand Down
26 changes: 26 additions & 0 deletions test/unit/specs/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,32 @@ describe("App without analytics", () => {
expect(store.state.node.approvalRequired).toBe("THISISSOMEHASH")
})

it("triggers navigation to About on IPC message", async () => {
jest.resetModules()

let mockPush = jest.fn()
jest.mock(
"vue-router",
() =>
function() {
if (this == null) return
this.push = mockPush
}
)

const { ipcRenderer } = require("electron")
ipcRenderer.on = (type, cb) => {
if (type === "open-about-menu") {
cb(null)
}
}

let app = require("renderer/main.js")
expect(mockPush.mock.calls[0][0]).toBe("/preferences")

jest.resetModules()
})

it("sends a message to the main thread, that the app has loaded", () => {
const { ipcRenderer } = require("electron")
ipcRenderer.send = jest.fn()
Expand Down
56 changes: 56 additions & 0 deletions test/unit/specs/__snapshots__/menu.spec.js.snap
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,
],
]
`;
74 changes: 74 additions & 0 deletions test/unit/specs/menu.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const { join } = require("path")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You put in a lot of effort into this! Thank you!

I feel a little ambivalent about testing the menu function of electron. I just ignored the file: https://github.com/cosmos/voyager/pull/900/files#diff-50315a6edc0ec04526f1b8c64d3f1b24R24
I would like to get your opinion.


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)
})
})