Mailspring/spec-nylas/action-bridge-spec.coffee
Ben Gotow 607ca3bf10 feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.

This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.

When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.

Search bar doesn't need to do full refresh on clear if it never committed

Allow drafts to be switched to a different account when not in reply to an existing thread

Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal

Show many dots for many accounts in long polling status bar

add/remove accounts from prefs

Spec fixes!

Test Plan: Run tests, none broken!

Reviewers: evan, dillon

Reviewed By: evan, dillon

Differential Revision: https://phab.nylas.com/D1928
2015-08-21 15:29:58 -07:00

102 lines
3.9 KiB
CoffeeScript

Reflux = require 'reflux'
Actions = require '../src/flux/actions'
Message = require '../src/flux/models/message'
DatabaseStore = require '../src/flux/stores/database-store'
AccountStore = require '../src/flux/stores/account-store'
ActionBridge = require '../src/flux/action-bridge',
_ = require 'underscore'
ipc =
on: ->
send: ->
describe "ActionBridge", ->
describe "in the editor window", ->
beforeEach ->
spyOn(atom, "getWindowType").andReturn "default"
spyOn(atom, "isMainWindow").andReturn true
@bridge = new ActionBridge(ipc)
it "should have the role Role.ROOT", ->
expect(@bridge.role).toBe(ActionBridge.Role.ROOT)
it "should rebroadcast global actions", ->
spyOn(@bridge, 'onRebroadcast')
testAction = Actions[Actions.globalActions[0]]
testAction('bla')
expect(@bridge.onRebroadcast).toHaveBeenCalled()
it "should rebroadcast when the DatabaseStore triggers", ->
spyOn(@bridge, 'onRebroadcast')
DatabaseStore.trigger({})
expect(@bridge.onRebroadcast).toHaveBeenCalled()
it "should not rebroadcast mainWindow actions since it is the main window", ->
spyOn(@bridge, 'onRebroadcast')
testAction = Actions.didMakeAPIRequest
testAction('bla')
expect(@bridge.onRebroadcast).not.toHaveBeenCalled()
it "should not rebroadcast window actions", ->
spyOn(@bridge, 'onRebroadcast')
testAction = Actions[Actions.windowActions[0]]
testAction('bla')
expect(@bridge.onRebroadcast).not.toHaveBeenCalled()
describe "in a secondary window", ->
beforeEach ->
spyOn(atom, "getWindowType").andReturn "popout"
spyOn(atom, "isMainWindow").andReturn false
@bridge = new ActionBridge(ipc)
@message = new Message
id: 'test-id'
accountId: 'test-account-id'
it "should have the role Role.SECONDARY", ->
expect(@bridge.role).toBe(ActionBridge.Role.SECONDARY)
it "should rebroadcast global actions", ->
spyOn(@bridge, 'onRebroadcast')
testAction = Actions[Actions.globalActions[0]]
testAction('bla')
expect(@bridge.onRebroadcast).toHaveBeenCalled()
it "should rebroadcast mainWindow actions", ->
spyOn(@bridge, 'onRebroadcast')
testAction = Actions.didMakeAPIRequest
testAction('bla')
expect(@bridge.onRebroadcast).toHaveBeenCalled()
it "should not rebroadcast window actions", ->
spyOn(@bridge, 'onRebroadcast')
testAction = Actions[Actions.windowActions[0]]
testAction('bla')
expect(@bridge.onRebroadcast).not.toHaveBeenCalled()
describe "onRebroadcast", ->
beforeEach ->
spyOn(atom, "getWindowType").andReturn "popout"
spyOn(atom, "isMainWindow").andReturn false
@bridge = new ActionBridge(ipc)
describe "when called with TargetWindows.ALL", ->
it "should broadcast the action over IPC to all windows", ->
spyOn(ipc, 'send')
Actions.didSwapModel.firing = false
@bridge.onRebroadcast(ActionBridge.TargetWindows.ALL, 'didSwapModel', [{oldModel: '1', newModel: 2}])
expect(ipc.send).toHaveBeenCalledWith('action-bridge-rebroadcast-to-all', 'popout', 'didSwapModel', '[{"oldModel":"1","newModel":2}]')
describe "when called with TargetWindows.MAIN", ->
it "should broadcast the action over IPC to the main window only", ->
spyOn(ipc, 'send')
Actions.didSwapModel.firing = false
@bridge.onRebroadcast(ActionBridge.TargetWindows.MAIN, 'didSwapModel', [{oldModel: '1', newModel: 2}])
expect(ipc.send).toHaveBeenCalledWith('action-bridge-rebroadcast-to-main', 'popout', 'didSwapModel', '[{"oldModel":"1","newModel":2}]')
it "should not do anything if the current invocation of the Action was triggered by itself", ->
spyOn(ipc, 'send')
Actions.didSwapModel.firing = true
@bridge.onRebroadcast(ActionBridge.TargetWindows.ALL, 'didSwapModel', [{oldModel: '1', newModel: 2}])
expect(ipc.send).not.toHaveBeenCalled()