2015-10-06 07:22:22 +08:00
|
|
|
React = require 'react/addons'
|
|
|
|
TestUtils = React.addons.TestUtils
|
2016-01-19 15:18:19 +08:00
|
|
|
AccountSwitcher = require './../lib/components/account-switcher'
|
|
|
|
SidebarStore = require './../lib/sidebar-store'
|
2015-10-06 07:22:22 +08:00
|
|
|
{AccountStore} = require 'nylas-exports'
|
|
|
|
|
2016-01-12 05:39:25 +08:00
|
|
|
describe "AccountSwitcher", ->
|
2015-10-06 07:22:22 +08:00
|
|
|
switcher = null
|
|
|
|
|
|
|
|
beforeEach ->
|
2016-01-12 05:38:44 +08:00
|
|
|
account = AccountStore.accounts()[0]
|
2016-01-26 03:42:39 +08:00
|
|
|
accounts = [
|
2016-01-12 05:38:44 +08:00
|
|
|
account,
|
|
|
|
{
|
|
|
|
emailAddress: "dillon@nylas.com",
|
|
|
|
provider: "exchange"
|
|
|
|
label: "work"
|
|
|
|
}
|
|
|
|
]
|
2015-10-06 07:22:22 +08:00
|
|
|
switcher = TestUtils.renderIntoDocument(
|
2016-01-26 03:42:39 +08:00
|
|
|
<AccountSwitcher accounts={accounts} focusedAccounts={[account]} />
|
2015-10-06 07:22:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
it "doesn't render the dropdown if nothing clicked", ->
|
|
|
|
openDropdown = TestUtils.scryRenderedDOMComponentsWithClass switcher, 'open'
|
|
|
|
expect(openDropdown.length).toBe 0
|
|
|
|
|
|
|
|
it "shows the dropdown on click", ->
|
|
|
|
toggler = TestUtils.findRenderedDOMComponentWithClass switcher, 'primary-item'
|
|
|
|
TestUtils.Simulate.click toggler
|
|
|
|
openDropdown = TestUtils.scryRenderedDOMComponentsWithClass switcher, 'open'
|
|
|
|
expect(openDropdown.length).toBe 1
|
|
|
|
|
|
|
|
it "hides the dropdown on blur", ->
|
|
|
|
toggler = TestUtils.findRenderedDOMComponentWithClass switcher, 'primary-item'
|
|
|
|
TestUtils.Simulate.click toggler
|
|
|
|
toggler = TestUtils.findRenderedDOMComponentWithClass switcher, 'primary-item'
|
|
|
|
TestUtils.Simulate.blur toggler
|
|
|
|
openDropdown = TestUtils.scryRenderedDOMComponentsWithClass switcher, 'open'
|
|
|
|
expect(openDropdown.length).toBe 0
|
|
|
|
|
|
|
|
it "shows other accounts and the 'Add Account' button", ->
|
|
|
|
toggler = TestUtils.findRenderedDOMComponentWithClass switcher, 'primary-item'
|
|
|
|
TestUtils.Simulate.click toggler
|
|
|
|
|
|
|
|
dropdown = TestUtils.findRenderedDOMComponentWithClass switcher, "dropdown"
|
|
|
|
items = TestUtils.scryRenderedDOMComponentsWithClass dropdown, "secondary-item"
|
|
|
|
newAccountButton = TestUtils.scryRenderedDOMComponentsWithClass dropdown, "new-account-option"
|
|
|
|
|
2016-01-26 03:42:39 +08:00
|
|
|
# The unified Inbox item, then both accounts, then the manage item
|
|
|
|
expect(items.length).toBe 4
|
2015-10-06 07:22:22 +08:00
|
|
|
expect(newAccountButton.length).toBe 1
|