Mailspring/spec/stores/account-store-spec.coffee
Juan Tejada 415d612458 feat(account-prefs): Adds new page for Account in preferences
Summary:
Adds the new Account preferences page. This consists of two major React components,
PreferencesAccountList and PreferencesAccountDetails, both of which use EditableList.

I added a bunch of fixes and updated the API for EditableList, plus a bit of
refactoring for PreferencesAccount component, and a bunch of CSS so its a big diff.

The detailed changelog:

Updates to EditableList:
  - Fix bug updating selection state when arrows pressed to move selection
  - Add new props:
    - allowEmptySelection to allow the list to have no selection
    - createInputProps to pass aditional props to the createInput
  - Add scroll region for list items
  - Update styles and refactor render methods

Other Updates:
- Updates Account model to hold aliases and a label
  - Adds getter for label to default to email
- Update accountswitcher to display label, update styles and spec

- Refactor PreferencesAccounts component:
  - Splits it into smaller components,
  - Removes unused code
- Splits preferences styelsheets into smaller separate stylesheet for
  account page. Adds some updates and fixes (scroll-region padding)
- Update AccountStore to be able to perform updates on an account.
- Adds new Action to update account, and an action to remove account to
  be consistent with Action usage
- Adds components for Account list and Aliases list using EditableList

Test Plan: - All specs pass, but need to write new tests!

Reviewers: bengotow, evan

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2332
2015-12-10 15:27:29 -08:00

92 lines
3 KiB
CoffeeScript

_ = require 'underscore'
AccountStore = require '../../src/flux/stores/account-store'
Account = require '../../src/flux/models/account'
describe "AccountStore", ->
beforeEach ->
@instance = null
@constructor = AccountStore.constructor
afterEach ->
@instance.stopListeningToAll()
it "should initialize using data saved in config", ->
accounts =
[{
"id": "123",
"client_id" : 'local-4f9d476a-c173',
"server_id" : '123',
"email_address":"bengotow@gmail.com",
"object":"account"
"organization_unit": "label"
},{
"id": "1234",
"client_id" : 'local-4f9d476a-c175',
"server_id" : '1234',
"email_address":"ben@nylas.com",
"object":"account"
"organization_unit": "label"
}]
spyOn(NylasEnv.config, 'get').andCallFake (key) ->
if key is 'nylas.accounts'
return accounts
else if key is 'nylas.currentAccountIndex'
return 1
@instance = new @constructor
expect(@instance.items()).toEqual([
(new Account).fromJSON(accounts[0]),
(new Account).fromJSON(accounts[1])
])
expect(@instance.current() instanceof Account).toBe(true)
expect(@instance.current().id).toEqual(accounts[1]['id'])
expect(@instance.current().emailAddress).toEqual(accounts[1]['email_address'])
it "should initialize current() to null if data is not present", ->
spyOn(NylasEnv.config, 'get').andCallFake -> null
@instance = new @constructor
expect(@instance.current()).toEqual(null)
it "should initialize current() to null if data is invalid", ->
spyOn(NylasEnv.config, 'get').andCallFake -> "this isn't an object"
@instance = new @constructor
expect(@instance.current()).toEqual(null)
describe "adding account from json", ->
beforeEach ->
spyOn(NylasEnv.config, "set")
@json =
"id": "1234",
"client_id" : 'local-4f9d476a-c175',
"server_id" : '1234',
"email_address":"ben@nylas.com",
"provider":"gmail",
"object":"account"
"auth_token": "auth-123"
"organization_unit": "label"
@instance = new @constructor
spyOn(@instance, "_onSelectAccount").andCallThrough()
spyOn(@instance, "trigger")
@instance.addAccountFromJSON(@json)
it "sets the tokens", ->
expect(@instance._tokens["1234"]).toBe "auth-123"
it "sets the accounts", ->
account = (new Account).fromJSON(@json)
expect(@instance._accounts.length).toBe 1
expect(@instance._accounts[0]).toEqual account
it "saves the config", ->
expect(NylasEnv.config.save).toHaveBeenCalled()
expect(NylasEnv.config.set.calls.length).toBe 4
it "selects the account", ->
expect(@instance._index).toBe 0
expect(@instance._onSelectAccount).toHaveBeenCalledWith("1234")
expect(@instance._onSelectAccount.calls.length).toBe 1
it "triggers", ->
expect(@instance.trigger).toHaveBeenCalled()
expect(@instance.trigger.calls.length).toBe 1