2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-02-19 06:24:34 +08:00
|
|
|
proxyquire = require 'proxyquire'
|
|
|
|
Reflux = require 'reflux'
|
2015-05-15 08:08:30 +08:00
|
|
|
{Actions} = require 'nylas-exports'
|
2015-02-19 06:24:34 +08:00
|
|
|
|
|
|
|
stubUpdaterState = null
|
|
|
|
stubUpdaterReleaseVersion = null
|
|
|
|
ipcSendArgs = null
|
|
|
|
|
|
|
|
PackageMain = proxyquire "../lib/main",
|
|
|
|
"ipc":
|
|
|
|
send: ->
|
|
|
|
ipcSendArgs = arguments
|
|
|
|
"remote":
|
|
|
|
getGlobal: (global) ->
|
|
|
|
autoUpdateManager:
|
|
|
|
releaseVersion: stubUpdaterReleaseVersion
|
|
|
|
getState: -> stubUpdaterState
|
|
|
|
|
2015-02-21 04:19:34 +08:00
|
|
|
describe "NotificationUpdateAvailable", ->
|
2015-02-19 06:24:34 +08:00
|
|
|
beforeEach ->
|
|
|
|
stubUpdaterState = 'idle'
|
|
|
|
stubUpdaterReleaseVersion = undefined
|
|
|
|
ipcSendArgs = null
|
|
|
|
@package = PackageMain
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
@package.deactivate()
|
|
|
|
|
|
|
|
describe "activate", ->
|
|
|
|
it "should display a notification immediately if one is available", ->
|
|
|
|
spyOn(@package, 'displayNotification')
|
|
|
|
stubUpdaterState = 'update-available'
|
|
|
|
@package.activate()
|
|
|
|
expect(@package.displayNotification).toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should not display a notification if no update is avialable", ->
|
|
|
|
spyOn(@package, 'displayNotification')
|
|
|
|
stubUpdaterState = 'no-update-available'
|
|
|
|
@package.activate()
|
|
|
|
expect(@package.displayNotification).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should listen for `window:update-available`", ->
|
2015-03-26 09:22:52 +08:00
|
|
|
spyOn(atom, 'onUpdateAvailable').andCallThrough()
|
2015-02-19 06:24:34 +08:00
|
|
|
@package.activate()
|
2015-03-26 09:22:52 +08:00
|
|
|
expect(atom.onUpdateAvailable).toHaveBeenCalled()
|
2015-02-19 06:24:34 +08:00
|
|
|
|
|
|
|
describe "displayNotification", ->
|
|
|
|
beforeEach ->
|
|
|
|
@package.activate()
|
|
|
|
|
|
|
|
it "should fire a postNotification Action", ->
|
|
|
|
spyOn(Actions, 'postNotification')
|
|
|
|
@package.displayNotification()
|
|
|
|
expect(Actions.postNotification).toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should include the version if one is provided", ->
|
|
|
|
spyOn(Actions, 'postNotification')
|
|
|
|
|
|
|
|
version = '0.515.0-123123'
|
|
|
|
@package.displayNotification(version)
|
|
|
|
expect(Actions.postNotification).toHaveBeenCalled()
|
|
|
|
|
|
|
|
notifOptions = Actions.postNotification.mostRecentCall.args[0]
|
|
|
|
expect(notifOptions.message.indexOf(version) > 0).toBe(true)
|
|
|
|
|
|
|
|
describe "when the action is taken", ->
|
|
|
|
it "should fire the `application:install-update` IPC event", ->
|
|
|
|
Actions.notificationActionTaken({notification: {}, action: {id: 'release-bar:install-update'}})
|
2015-05-20 07:06:59 +08:00
|
|
|
expect(Array.prototype.slice.call(ipcSendArgs)).toEqual(['command', 'application:install-update'])
|
2015-02-19 06:24:34 +08:00
|
|
|
|