Commit 7b36e879 authored by Tasso Evangelista's avatar Tasso Evangelista

Add some unit tests for menus

parent c1cab6f7
......@@ -62,6 +62,7 @@ const createTemplate = ({
type: 'separator',
},
{
id: 'quit',
label: i18n.__('&Quit %s', appName),
accelerator: 'CommandOrControl+Q',
click: () => events.emit('quit'),
......@@ -278,6 +279,7 @@ const createTemplate = ({
click: () => events.emit('open-url', 'https://rocket.chat'),
},
{
id: 'about',
label: i18n.__('About %s', appName),
click: () => events.emit('about'),
},
......@@ -300,6 +302,10 @@ class Menus extends EventEmitter {
this.update();
}
getItem(id) {
return Menu.getApplicationMenu().getMenuItemById(id);
}
async update() {
const template = createTemplate({ appName: app.getName(), ...this.state }, this);
const menu = Menu.buildFromTemplate(template);
......
/* eslint-env node, mocha */
import { Menu } from 'electron';
import { expect } from 'chai';
import sinon from 'sinon';
import menus from './menus';
describe('menus', () => {
let menu;
beforeEach(async() => {
await menus.update();
menu = Menu.getApplicationMenu();
});
it('should be the application menu', () => {
expect(menu.items).to.not.be.empty;
});
it('should update on set state', () => {
sinon.spy(menus, 'update');
menus.setState({});
expect(menus.update.calledOnce).to.be.true;
});
const itShouldHaveAnItem = (id, which) => it(`should have an item "${ id }"`, () => {
const item = menus.getItem(id);
expect(item).to.not.be.null;
which && which(item);
});
itShouldHaveAnItem('quit', (item) => {
const spy = sinon.spy();
menus.on('quit', spy);
item.click();
expect(spy.called).to.be.true;
});
itShouldHaveAnItem('about', (item) => {
const spy = sinon.spy();
menus.on('about', spy);
item.click();
expect(spy.called).to.be.true;
});
});
......@@ -33,6 +33,30 @@
dependencies:
eslint-plugin-import "^2.14.0"
"@sinonjs/commons@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.0.2.tgz#3e0ac737781627b8844257fadc3d803997d0526e"
dependencies:
type-detect "4.0.8"
"@sinonjs/formatio@3.0.0", "@sinonjs/formatio@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-3.0.0.tgz#9d282d81030a03a03fa0c5ce31fd8786a4da311a"
dependencies:
"@sinonjs/samsam" "2.1.0"
"@sinonjs/samsam@2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-2.1.0.tgz#b8b8f5b819605bd63601a6ede459156880f38ea3"
dependencies:
array-from "^2.1.1"
"@sinonjs/samsam@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-2.1.1.tgz#f352621c24c9e9ab2ed293a7655e8d46bfd64c16"
dependencies:
array-from "^2.1.1"
"@types/estree@0.0.39":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
......@@ -348,6 +372,10 @@ array-find-index@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/array-find-index/-/array-find-index-1.0.2.tgz#df010aa1287e164bbda6f9723b0a96a1ec4187a1"
array-from@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/array-from/-/array-from-2.1.1.tgz#cfe9d8c26628b9dc5aecc62a9f5d8f1f352c1195"
array-ify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/array-ify/-/array-ify-1.0.0.tgz#9e528762b4a9066ad163a6962a364418e9626ece"
......@@ -1543,7 +1571,7 @@ dezalgo@^1.0.0, dezalgo@~1.0.3:
asap "^2.0.0"
wrappy "1"
diff@3.5.0:
diff@3.5.0, diff@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
......@@ -3521,6 +3549,10 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"
just-extend@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-3.0.0.tgz#cee004031eaabf6406da03a7b84e4fe9d78ef288"
kind-of@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-1.1.0.tgz#140a3d2d41a36d2efcfa9377b62c24f8495a5c44"
......@@ -3789,6 +3821,10 @@ lodash.flatten@^4.2.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
lodash.isarguments@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"
......@@ -3879,6 +3915,10 @@ lodash@~1.0.1:
version "1.0.2"
resolved "http://registry.npmjs.org/lodash/-/lodash-1.0.2.tgz#8f57560c83b59fc270bd3d561b690043430e2551"
lolex@^2.3.2, lolex@^2.7.4:
version "2.7.5"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.5.tgz#113001d56bfc7e02d56e36291cc5c413d1aa0733"
longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
......@@ -4279,6 +4319,16 @@ nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
nise@^1.4.5:
version "1.4.5"
resolved "https://registry.yarnpkg.com/nise/-/nise-1.4.5.tgz#979a97a19c48d627bb53703726ae8d53ce8d4b3e"
dependencies:
"@sinonjs/formatio" "3.0.0"
just-extend "^3.0.0"
lolex "^2.3.2"
path-to-regexp "^1.7.0"
text-encoding "^0.6.4"
node-fetch-npm@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/node-fetch-npm/-/node-fetch-npm-2.0.2.tgz#7258c9046182dca345b4208eda918daf33697ff7"
......@@ -4955,6 +5005,12 @@ path-root@^0.1.1:
dependencies:
path-root-regex "^0.1.0"
path-to-regexp@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
dependencies:
isarray "0.0.1"
path-type@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
......@@ -5754,6 +5810,20 @@ single-line-log@^1.1.2:
dependencies:
string-width "^1.0.1"
sinon@^6.3.4:
version "6.3.4"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-6.3.4.tgz#6f076d7ddcf381af6c16468ac83d30333a756ec8"
dependencies:
"@sinonjs/commons" "^1.0.2"
"@sinonjs/formatio" "^3.0.0"
"@sinonjs/samsam" "^2.1.1"
diff "^3.5.0"
lodash.get "^4.4.2"
lolex "^2.7.4"
nise "^1.4.5"
supports-color "^5.5.0"
type-detect "^4.0.8"
slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
......@@ -6148,7 +6218,7 @@ supports-color@^3.1.0:
dependencies:
has-flag "^1.0.0"
supports-color@^5.3.0:
supports-color@^5.3.0, supports-color@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
dependencies:
......@@ -6225,6 +6295,10 @@ term-size@^1.2.0:
dependencies:
execa "^0.7.0"
text-encoding@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
text-extensions@^1.0.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/text-extensions/-/text-extensions-1.8.0.tgz#6f343c62268843019b21a616a003557bdb952d2b"
......@@ -6365,7 +6439,7 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"
type-detect@^4.0.0:
type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment