Skip to content

Commit

Permalink
fix failing tests, preserve options passed into menu.set({})
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann committed Oct 29, 2021
1 parent 8073ac6 commit 2bcf65f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
14 changes: 4 additions & 10 deletions packages/server/lib/gui/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ const { shell } = require('electron')
const appData = require('../util/app_data')
const open = require('../util/open')

// let onLogOutClicked = function () {}
// hoist up options and allow calling menu.set({})
// to override existing options or be called multiple
// times to preserve existing options
let options = {}

module.exports = {
set (opts = {}) {
_.defaults(options, opts, {
withDevTools: false,
})

// // this set by modes/interactive and needs to be preserved if the menu
// // is set again by launcher when the Electron browser is run
// if (options.onLogOutClicked) {
// ({ onLogOutClicked } = options)
// }
_.extend(options, opts)

const template = [
{
Expand Down
1 change: 0 additions & 1 deletion packages/server/lib/modes/interactive-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export = {
// instance here instead of callback functions
menu.set({
withDevTools: isDev(),
withGraphiQL: isDev(),
onLogOutClicked () {
return bus.emit('menu:item:clicked', 'log:out')
},
Expand Down
16 changes: 16 additions & 0 deletions packages/server/test/unit/gui/menu_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ describe('gui/menu', function () {
expect(onLogOutClicked).to.be.called
})

it('merges options and calls callback functions', () => {
const onLogOutClicked1 = sinon.stub()
const onLogOutClicked2 = sinon.stub()

menu.set()
menu.set({ onLogOutClicked: onLogOutClicked1 })
menu.set({ onLogOutClicked: onLogOutClicked2 })

getSubMenuItem(getMenuItem('File'), 'Log Out').click()

expect(onLogOutClicked1).not.to.be.called
expect(onLogOutClicked2).to.be.called
})

it('calls original logout callback when menu is reset without new callback', () => {
const onLogOutClicked = sinon.stub()

Expand Down Expand Up @@ -260,6 +274,8 @@ describe('gui/menu', function () {
expect(labels).to.eql([
'Reload',
'Toggle Developer Tools',
'GraphiQL',
'View App Data',
])
})

Expand Down

0 comments on commit 2bcf65f

Please sign in to comment.