Mailspring/internal_packages/account-sidebar/spec/account-switcher-spec.cjsx
Juan Tejada 9f998d1964 refactor(rip-current-account): Rips out AccountStore.current
Summary:
- WIP: Need to fix tests and some errors!
- Refactors Category class to hold information about its type
- Refactors CategoryStore to rely on observables instead of local caches
- Adds and updates Observables and helpers
- Refactors ContactStore to hold entire cache of contacts instead of per
  current account
  - Same for ContactRankingStore and other stores
- Refactors method names for AccountStore + some helpers
- Updates MailViewFilter to hold an account
  - Adds basic Unified filter
- Replaces AccountStore.current calls with either:
  - The account of the currently focused MailViewFilter
  - The account associated with a thread, message, file, etc...
  - A parameter to be passed in
  - Arbitrarily, the first account in the AccountsStore

Test Plan: - Unit tests

Reviewers: evan, bengotow

Differential Revision: https://phab.nylas.com/D2423
2016-01-08 14:22:13 -08:00

52 lines
1.9 KiB
CoffeeScript

React = require 'react/addons'
TestUtils = React.addons.TestUtils
AccountSwitcher = require './../lib/account-switcher'
{AccountStore} = require 'nylas-exports'
describe "AccountSwitcher", ->
switcher = null
beforeEach ->
spyOn(AccountStore, "accounts").andCallFake ->
[
AccountStore.current(),
{
emailAddress: "dillon@nylas.com",
provider: "exchange"
label: "work"
}
]
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