refactor: ginify Tray (#22822)

* refactor: ginify Tray

* lint

* improve argument parsing logic

* remove redundant imports from tray.js

* new Tray produces an instanceof Tray

* make Constructible generic

* lint

* clean up on exit
This commit is contained in:
Jeremy Apthorp 2020-03-29 18:32:02 -07:00 committed by GitHub
parent 76ae3b7ecb
commit a3e28788ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 380 additions and 88 deletions

View file

@ -18,7 +18,7 @@ describe('tray module', () => {
const badPath = path.resolve('I', 'Do', 'Not', 'Exist');
expect(() => {
tray = new Tray(badPath);
}).to.throw(/Image could not be created from .*/);
}).to.throw(/Error processing argument at index 0/);
});
ifit(process.platform === 'win32')('throws a descriptive error if an invlaid guid is given', () => {
@ -32,6 +32,10 @@ describe('tray module', () => {
tray = new Tray(nativeImage.createEmpty(), '0019A433-3526-48BA-A66C-676742C0FEFB');
}).to.not.throw();
});
it('is an instance of Tray', () => {
expect(tray).to.be.an.instanceOf(Tray);
});
});
ifdescribe(process.platform === 'darwin')('tray get/set ignoreDoubleClickEvents', () => {
@ -80,6 +84,29 @@ describe('tray module', () => {
tray.popUpContextMenu(menu);
}).to.not.throw();
});
it('can be called with a position', () => {
expect(() => {
tray.popUpContextMenu({ x: 0, y: 0 } as any);
}).to.not.throw();
});
it('can be called with a menu and a position', () => {
const menu = Menu.buildFromTemplate([{ label: 'Test' }]);
expect(() => {
tray.popUpContextMenu(menu, { x: 0, y: 0 });
}).to.not.throw();
});
it('throws an error on invalid arguments', () => {
expect(() => {
tray.popUpContextMenu({} as any);
}).to.throw(/index 0/);
const menu = Menu.buildFromTemplate([{ label: 'Test' }]);
expect(() => {
tray.popUpContextMenu(menu, {} as any);
}).to.throw(/index 1/);
});
});
describe('tray.closeContextMenu()', () => {