test: update power/notification specs to expect (#13497)

* spec: update power/process specs to expect

* Address comments
This commit is contained in:
Shelley Vohr 2018-08-31 13:52:32 -07:00 committed by Samuel Attard
parent 586a6f2e6d
commit dac435b411
3 changed files with 71 additions and 62 deletions

View file

@ -1,4 +1,8 @@
const assert = require('assert') const chai = require('chai')
const dirtyChai = require('dirty-chai')
const {expect} = chai
chai.use(dirtyChai)
const {Notification} = require('electron').remote const {Notification} = require('electron').remote
@ -13,29 +17,29 @@ describe('Notification module', () => {
closeButtonText: 'closeButtonText' closeButtonText: 'closeButtonText'
}) })
assert.equal(n.title, 'title') expect(n.title).to.equal('title')
n.title = 'title1' n.title = 'title1'
assert.equal(n.title, 'title1') expect(n.title).to.equal('title1')
assert.equal(n.subtitle, 'subtitle') expect(n.subtitle).equal('subtitle')
n.subtitle = 'subtitle1' n.subtitle = 'subtitle1'
assert.equal(n.subtitle, 'subtitle1') expect(n.subtitle).equal('subtitle1')
assert.equal(n.body, 'body') expect(n.body).to.equal('body')
n.body = 'body1' n.body = 'body1'
assert.equal(n.body, 'body1') expect(n.body).to.equal('body1')
assert.equal(n.replyPlaceholder, 'replyPlaceholder') expect(n.replyPlaceholder).to.equal('replyPlaceholder')
n.replyPlaceholder = 'replyPlaceholder1' n.replyPlaceholder = 'replyPlaceholder1'
assert.equal(n.replyPlaceholder, 'replyPlaceholder1') expect(n.replyPlaceholder).to.equal('replyPlaceholder1')
assert.equal(n.sound, 'sound') expect(n.sound).to.equal('sound')
n.sound = 'sound1' n.sound = 'sound1'
assert.equal(n.sound, 'sound1') expect(n.sound).to.equal('sound1')
assert.equal(n.closeButtonText, 'closeButtonText') expect(n.closeButtonText).to.equal('closeButtonText')
n.closeButtonText = 'closeButtonText1' n.closeButtonText = 'closeButtonText1'
assert.equal(n.closeButtonText, 'closeButtonText1') expect(n.closeButtonText).to.equal('closeButtonText1')
}) })
it('inits, gets and sets basic boolean properties correctly', () => { it('inits, gets and sets basic boolean properties correctly', () => {
@ -44,13 +48,13 @@ describe('Notification module', () => {
hasReply: true hasReply: true
}) })
assert.equal(n.silent, true) expect(n.silent).to.be.true()
n.silent = false n.silent = false
assert.equal(n.silent, false) expect(n.silent).to.be.false()
assert.equal(n.hasReply, true) expect(n.hasReply).to.be.true()
n.hasReply = false n.hasReply = false
assert.equal(n.hasReply, false) expect(n.hasReply).to.be.false()
}) })
it('inits, gets and sets actions correctly', () => { it('inits, gets and sets actions correctly', () => {
@ -66,10 +70,11 @@ describe('Notification module', () => {
] ]
}) })
assert.equal(n.actions[0].type, 'button') expect(n.actions.length).to.equal(2)
assert.equal(n.actions[0].text, '1') expect(n.actions[0].type).to.equal('button')
assert.equal(n.actions[1].type, 'button') expect(n.actions[0].text).to.equal('1')
assert.equal(n.actions[1].text, '2') expect(n.actions[1].type).to.equal('button')
expect(n.actions[1].text).to.equal('2')
n.actions = [ n.actions = [
{ {
@ -81,10 +86,11 @@ describe('Notification module', () => {
} }
] ]
assert.equal(n.actions[0].type, 'button') expect(n.actions.length).to.equal(2)
assert.equal(n.actions[0].text, '3') expect(n.actions[0].type).to.equal('button')
assert.equal(n.actions[1].type, 'button') expect(n.actions[0].text).to.equal('3')
assert.equal(n.actions[1].text, '4') expect(n.actions[1].type).to.equal('button')
expect(n.actions[1].text).to.equal('4')
}) })
// TODO(sethlu): Find way to test init with notification icon? // TODO(sethlu): Find way to test init with notification icon?

View file

@ -6,10 +6,14 @@
// //
// See https://pypi.python.org/pypi/python-dbusmock for more information about // See https://pypi.python.org/pypi/python-dbusmock for more information about
// python-dbusmock. // python-dbusmock.
const assert = require('assert') const chai = require('chai')
const dirtyChai = require('dirty-chai')
const dbus = require('dbus-native') const dbus = require('dbus-native')
const Promise = require('bluebird') const Promise = require('bluebird')
const {expect} = chai
chai.use(dirtyChai)
const skip = process.platform !== 'linux' || !process.env.DBUS_SYSTEM_BUS_ADDRESS const skip = process.platform !== 'linux' || !process.env.DBUS_SYSTEM_BUS_ADDRESS
// TODO(alexeykuzmin): [Ch66] Crashes on Linux ia32. Fix it and enable back. // TODO(alexeykuzmin): [Ch66] Crashes on Linux ia32. Fix it and enable back.
@ -27,9 +31,7 @@ xdescribe('powerMonitor', () => {
reset = Promise.promisify(logindMock.Reset, {context: logindMock}) reset = Promise.promisify(logindMock.Reset, {context: logindMock})
}) })
after(async () => { after(reset)
await reset()
})
} }
(skip ? describe.skip : describe)('when powerMonitor module is loaded with dbus mock', () => { (skip ? describe.skip : describe)('when powerMonitor module is loaded with dbus mock', () => {
@ -41,7 +43,7 @@ xdescribe('powerMonitor', () => {
return cb return cb
} }
before((done) => { before(done => {
logindMock.on('MethodCalled', onceMethodCalled(done)) logindMock.on('MethodCalled', onceMethodCalled(done))
// lazy load powerMonitor after we listen to MethodCalled mock signal // lazy load powerMonitor after we listen to MethodCalled mock signal
dbusMockPowerMonitor = require('electron').remote.powerMonitor dbusMockPowerMonitor = require('electron').remote.powerMonitor
@ -49,8 +51,8 @@ xdescribe('powerMonitor', () => {
it('should call Inhibit to delay suspend', async () => { it('should call Inhibit to delay suspend', async () => {
const calls = await getCalls() const calls = await getCalls()
assert.equal(calls.length, 1) expect(calls).to.be.an('array').that.has.lengthOf(1)
assert.deepEqual(calls[0].slice(1), [ expect(calls[0].slice(1)).to.deep.equal([
'Inhibit', [ 'Inhibit', [
[[{type: 's', child: []}], ['sleep']], [[{type: 's', child: []}], ['sleep']],
[[{type: 's', child: []}], ['electron']], [[{type: 's', child: []}], ['electron']],
@ -68,7 +70,7 @@ xdescribe('powerMonitor', () => {
}) })
describe('when PrepareForSleep(false) signal is sent by logind', () => { describe('when PrepareForSleep(false) signal is sent by logind', () => {
it('should emit "resume" event', (done) => { it('should emit "resume" event', done => {
dbusMockPowerMonitor.once('resume', () => done()) dbusMockPowerMonitor.once('resume', () => done())
emitSignal('org.freedesktop.login1.Manager', 'PrepareForSleep', emitSignal('org.freedesktop.login1.Manager', 'PrepareForSleep',
'b', [['b', false]]) 'b', [['b', false]])
@ -76,8 +78,8 @@ xdescribe('powerMonitor', () => {
it('should have called Inhibit again', async () => { it('should have called Inhibit again', async () => {
const calls = await getCalls() const calls = await getCalls()
assert.equal(calls.length, 2) expect(calls).to.be.an('array').that.has.lengthOf(2)
assert.deepEqual(calls[1].slice(1), [ expect(calls[1].slice(1)).to.deep.equal([
'Inhibit', [ 'Inhibit', [
[[{type: 's', child: []}], ['sleep']], [[{type: 's', child: []}], ['sleep']],
[[{type: 's', child: []}], ['electron']], [[{type: 's', child: []}], ['electron']],
@ -92,14 +94,14 @@ xdescribe('powerMonitor', () => {
describe('when a listener is added to shutdown event', () => { describe('when a listener is added to shutdown event', () => {
before(async () => { before(async () => {
const calls = await getCalls() const calls = await getCalls()
assert.equal(calls.length, 2) expect(calls).to.be.an('array').that.has.lengthOf(2)
dbusMockPowerMonitor.once('shutdown', () => { }) dbusMockPowerMonitor.once('shutdown', () => { })
}) })
it('should call Inhibit to delay shutdown', async () => { it('should call Inhibit to delay shutdown', async () => {
const calls = await getCalls() const calls = await getCalls()
assert.equal(calls.length, 3) expect(calls).to.be.an('array').that.has.lengthOf(3)
assert.deepEqual(calls[2].slice(1), [ expect(calls[2].slice(1)).to.deep.equal([
'Inhibit', [ 'Inhibit', [
[[{type: 's', child: []}], ['shutdown']], [[{type: 's', child: []}], ['shutdown']],
[[{type: 's', child: []}], ['electron']], [[{type: 's', child: []}], ['electron']],
@ -110,7 +112,7 @@ xdescribe('powerMonitor', () => {
}) })
describe('when PrepareForShutdown(true) signal is sent by logind', () => { describe('when PrepareForShutdown(true) signal is sent by logind', () => {
it('should emit "shutdown" event', (done) => { it('should emit "shutdown" event', done => {
dbusMockPowerMonitor.once('shutdown', () => { done() }) dbusMockPowerMonitor.once('shutdown', () => { done() })
emitSignal('org.freedesktop.login1.Manager', 'PrepareForShutdown', emitSignal('org.freedesktop.login1.Manager', 'PrepareForShutdown',
'b', [['b', true]]) 'b', [['b', true]])
@ -126,35 +128,32 @@ xdescribe('powerMonitor', () => {
}) })
describe('powerMonitor.querySystemIdleState', () => { describe('powerMonitor.querySystemIdleState', () => {
it('notify current system idle state', (done) => { it('notify current system idle state', done => {
powerMonitor.querySystemIdleState(1, (idleState) => { powerMonitor.querySystemIdleState(1, idleState => {
assert.ok(idleState) expect(idleState).to.be.true()
done() done()
}) })
}) })
it('does not accept non positive integer threshold', () => { it('does not accept non positive integer threshold', () => {
assert.throws(() => { expect(() => {
powerMonitor.querySystemIdleState(-1, (idleState) => { powerMonitor.querySystemIdleState(-1, (idleState) => {})
}) }).to.throw()
})
assert.throws(() => { expect(() => {
powerMonitor.querySystemIdleState(NaN, (idleState) => { powerMonitor.querySystemIdleState(NaN, (idleState) => {})
}) }).to.throw()
})
assert.throws(() => { expect(() => {
powerMonitor.querySystemIdleState('a', (idleState) => { powerMonitor.querySystemIdleState('a', (idleState) => {})
}) }).to.throw()
})
}) })
}) })
describe('powerMonitor.querySystemIdleTime', () => { describe('powerMonitor.querySystemIdleTime', () => {
it('notify current system idle time', (done) => { it('notify current system idle time', done => {
powerMonitor.querySystemIdleTime((idleTime) => { powerMonitor.querySystemIdleTime(idleTime => {
assert.ok(idleTime >= 0) expect(idleTime).to.be.at.least(0)
done() done()
}) })
}) })

View file

@ -1,13 +1,17 @@
const {powerSaveBlocker} = require('electron').remote const {powerSaveBlocker} = require('electron').remote
const assert = require('assert') const chai = require('chai')
const dirtyChai = require('dirty-chai')
const {expect} = chai
chai.use(dirtyChai)
describe('powerSaveBlocker module', () => { describe('powerSaveBlocker module', () => {
it('can be started and stopped', () => { it('can be started and stopped', () => {
assert.equal(powerSaveBlocker.isStarted(-1), false) expect(powerSaveBlocker.isStarted(-1)).to.be.false()
const id = powerSaveBlocker.start('prevent-app-suspension') const id = powerSaveBlocker.start('prevent-app-suspension')
assert.ok(id != null) expect(id).to.to.be.a('number')
assert.equal(powerSaveBlocker.isStarted(id), true) expect(powerSaveBlocker.isStarted(id)).to.be.true()
powerSaveBlocker.stop(id) powerSaveBlocker.stop(id)
assert.equal(powerSaveBlocker.isStarted(id), false) expect(powerSaveBlocker.isStarted(id)).to.be.false()
}) })
}) })