Mailspring/internal_packages/account-sidebar/spec/account-switcher-spec.cjsx

54 lines
2 KiB
Text
Raw Normal View History

React = require 'react/addons'
TestUtils = React.addons.TestUtils
AccountSwitcher = require './../lib/account-switcher'
2016-01-12 05:38:44 +08:00
AccountSidebarStore = require './../lib/account-sidebar-store'
{AccountStore} = require 'nylas-exports'
2016-01-12 05:39:25 +08:00
describe "AccountSwitcher", ->
switcher = null
beforeEach ->
2016-01-12 05:38:44 +08:00
account = AccountStore.accounts()[0]
spyOn(AccountStore, "accounts").andReturn [
account,
{
emailAddress: "dillon@nylas.com",
provider: "exchange"
label: "work"
}
]
spyOn(AccountSidebarStore, "currentAccount").andReturn account
switcher = TestUtils.renderIntoDocument(
<AccountSwitcher />
)
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"
expect(items.length).toBe 3
expect(newAccountButton.length).toBe 1