зеркало из https://github.com/electron/electron.git
test: clean up and augment Tray module spec (#19410)
* spec: clean and add a new tray spec * address feedback from @nornagon * destroy tray after every test consistently
This commit is contained in:
Родитель
86c2ea1cb8
Коммит
539078f281
|
@ -1,28 +1,35 @@
|
|||
import { expect } from 'chai'
|
||||
import { Menu, Tray, nativeImage } from 'electron'
|
||||
import { ifdescribe, ifit } from './spec-helpers'
|
||||
|
||||
describe('tray module', () => {
|
||||
let tray: Tray;
|
||||
|
||||
beforeEach(() => {
|
||||
tray = new Tray(nativeImage.createEmpty())
|
||||
})
|
||||
beforeEach(() => { tray = new Tray(nativeImage.createEmpty()) })
|
||||
|
||||
afterEach(() => {
|
||||
tray.destroy()
|
||||
tray = null as any
|
||||
})
|
||||
|
||||
describe('tray.setContextMenu', () => {
|
||||
afterEach(() => {
|
||||
tray.destroy()
|
||||
ifdescribe(process.platform === 'darwin')('tray get/set ignoreDoubleClickEvents', () => {
|
||||
it('returns false by default', () => {
|
||||
const ignored = tray.getIgnoreDoubleClickEvents()
|
||||
expect(ignored).to.be.false('ignored')
|
||||
})
|
||||
|
||||
it('accepts menu instance', () => {
|
||||
tray.setContextMenu(new Menu())
|
||||
})
|
||||
it('can be set to true', () => {
|
||||
tray.setIgnoreDoubleClickEvents(true)
|
||||
|
||||
it('accepts null', () => {
|
||||
tray.setContextMenu(null)
|
||||
const ignored = tray.getIgnoreDoubleClickEvents()
|
||||
expect(ignored).to.be.true('not ignored')
|
||||
})
|
||||
})
|
||||
|
||||
describe('tray.setContextMenu(menu)', () => {
|
||||
it('accepts both null and Menu as parameters', () => {
|
||||
expect(() => { tray.setContextMenu(new Menu()) }).to.not.throw()
|
||||
expect(() => { tray.setContextMenu(null) }).to.not.throw()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -35,16 +42,8 @@ describe('tray module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('tray.popUpContextMenu', () => {
|
||||
afterEach(() => {
|
||||
tray.destroy()
|
||||
})
|
||||
|
||||
before(function () {
|
||||
if (process.platform !== 'win32') this.skip()
|
||||
})
|
||||
|
||||
it('can be called when menu is showing', (done) => {
|
||||
describe('tray.popUpContextMenu()', () => {
|
||||
ifit(process.platform === 'win32')('can be called when menu is showing', function (done) {
|
||||
tray.setContextMenu(Menu.buildFromTemplate([{ label: 'Test' }]))
|
||||
setTimeout(() => {
|
||||
tray.popUpContextMenu()
|
||||
|
@ -54,31 +53,28 @@ describe('tray module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('tray.setImage', () => {
|
||||
describe('tray.getBounds()', () => {
|
||||
afterEach(() => { tray.destroy() })
|
||||
|
||||
ifit(process.platform !== 'linux') ('returns a bounds object', function () {
|
||||
const bounds = tray.getBounds()
|
||||
expect(bounds).to.be.an('object').and.to.have.all.keys('x', 'y', 'width', 'height');
|
||||
})
|
||||
})
|
||||
|
||||
describe('tray.setImage(image)', () => {
|
||||
it('accepts empty image', () => {
|
||||
tray.setImage(nativeImage.createEmpty())
|
||||
|
||||
tray.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('tray.setPressedImage', () => {
|
||||
describe('tray.setPressedImage(image)', () => {
|
||||
it('accepts empty image', () => {
|
||||
tray.setPressedImage(nativeImage.createEmpty())
|
||||
|
||||
tray.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('tray title get/set', () => {
|
||||
before(function () {
|
||||
if (process.platform !== 'darwin') this.skip()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
tray.destroy()
|
||||
})
|
||||
|
||||
ifdescribe(process.platform === 'darwin')('tray get/set title', () => {
|
||||
it('sets/gets non-empty title', () => {
|
||||
const title = 'Hello World!'
|
||||
tray.setTitle(title)
|
||||
|
|
Загрузка…
Ссылка в новой задаче