Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update power/notification specs to expect #13497

Merged
merged 2 commits into from
Aug 31, 2018

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Jun 28, 2018

Description of Change

This PR updates the notification, power-monitor, and power-save-monitor specs as part of ongoing work to migrate our specs from assert to chai's expect with dirty-chai for better error messages.

/cc @alexeykuzmin

Checklist
Release Notes

Notes: no-notes

@codebytere codebytere requested review from a team June 28, 2018 23:52
after(async () => {
await reset()
})
after(async () => { await reset() })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass reset to the after() call.
reset function returns a Promise, and after can properly handle it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert.equal(n.actions[0].text, '3')
assert.equal(n.actions[1].type, 'button')
assert.equal(n.actions[1].text, '4')
expect(n.actions[0].type).to.equal('button')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check that n.actions is an array of the expected size first?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert.equal(n.actions[0].text, '1')
assert.equal(n.actions[1].type, 'button')
assert.equal(n.actions[1].text, '2')
expect(n.actions[0].type).to.equal('button')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check that n.actions is an array of the expected size first?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

logindMock.on('MethodCalled', onceMethodCalled(done))
// lazy load powerMonitor after we listen to MethodCalled mock signal
dbusMockPowerMonitor = require('electron').remote.powerMonitor
})

it('should call Inhibit to delay suspend', async () => {
const calls = await getCalls()
assert.equal(calls.length, 1)
assert.deepEqual(calls[0].slice(1), [
expect(calls.length).to.equal(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array of length 1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

dbusMockPowerMonitor.once('resume', () => done())
emitSignal('org.freedesktop.login1.Manager', 'PrepareForSleep',
'b', [['b', false]])
})

it('should have called Inhibit again', async () => {
const calls = await getCalls()
assert.equal(calls.length, 2)
assert.deepEqual(calls[1].slice(1), [
expect(calls.length).to.equal(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array of length 2?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

assert.ok(idleState)
it('notify current system idle state', done => {
powerMonitor.querySystemIdleState(1, idleState => {
expect(idleState).to.be.true()
done()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've heard that async/await is cool =)

it('notify current system idle state', async () => {
  const idleState = await new Promise(
      resolve => powerMonitor.querySystemIdleState(1, resolve))
  expect(idleState).to.be.true()
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels forced in this simple case, I would leave it as is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok =/

const id = powerSaveBlocker.start('prevent-app-suspension')
assert.ok(id != null)
assert.equal(powerSaveBlocker.isStarted(id), true)
expect(id).to.not.be.null()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not null, what it is? A number, an object, a symbol?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@alexeykuzmin
Copy link
Contributor

@codebytere Sorry for a slow reaction to your PRs =/
You're doing a great job making the tests better )

@codebytere
Copy link
Member Author

@alexeykuzmin no worries 😁 i'm just coming back online after PTO so i'm gonna follow up and address these soon!

@miniak
Copy link
Contributor

miniak commented Aug 27, 2018

@codebytere, @alexeykuzmin I've rebased the branch to fix the conflict with api-process-spec.js, which I've already converted before in a separate PR. I've also addressed a few of the comments.

@miniak miniak changed the title spec: update power/process specs to expect spec: update power/notification specs to expect Aug 27, 2018
@alexeykuzmin alexeykuzmin changed the title spec: update power/notification specs to expect test: update power/notification specs to expect Aug 27, 2018
@ckerr ckerr added the semver/minor backwards-compatible functionality label Aug 27, 2018
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I agree with @alexeykuzmin about using async / await but it's not a blocker for an expectification PR

@alexeykuzmin
Copy link
Contributor

Only gn builds failed and only because the branch is relatively old.
Should be good to merge.

@MarshallOfSound MarshallOfSound merged commit dac435b into master Aug 31, 2018
@release-clerk
Copy link

release-clerk bot commented Aug 31, 2018

No Release Notes

@MarshallOfSound MarshallOfSound deleted the expect-more-specs branch August 31, 2018 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants