Fix more specs:

- SearchBar
- EventRSVPTask
- ContactStore
This commit is contained in:
Juan Tejada 2016-01-11 16:08:59 -08:00
parent 10cb195226
commit 7f2c8481ff
8 changed files with 32 additions and 26 deletions

View file

@ -329,14 +329,14 @@ describe "ComposerView", ->
expect(@composer._shouldShowFromField()).toBe false
it "disables if account has no aliases", ->
spyOn(AccountStore, 'itemWithId').andCallFake -> {id: 1, aliases: []}
spyOn(AccountStore, 'accountForId').andCallFake -> {id: 1, aliases: []}
useDraft.call @, replyToMessageId: null, files: []
makeComposer.call @
expect(@composer.state.enabledFields).not.toContain Fields.From
it "enables if it's a reply-to message", ->
aliases = ['A <a@b.c']
spyOn(AccountStore, 'itemWithId').andCallFake -> {id: 1, aliases: aliases}
spyOn(AccountStore, 'accountForId').andCallFake -> {id: 1, aliases: aliases}
useDraft.call @, replyToMessageId: "local-123", files: []
makeComposer.call @
expect(@composer.state.enabledFields).toContain Fields.From
@ -344,7 +344,7 @@ describe "ComposerView", ->
it "enables if requirements are met", ->
a1 = new Account()
a1.aliases = ['a1']
spyOn(AccountStore, 'itemWithId').andCallFake -> a1
spyOn(AccountStore, 'accountForId').andCallFake -> a1
useDraft.call @, replyToMessageId: null, files: []
makeComposer.call @
expect(@composer.state.enabledFields).toContain Fields.From

View file

@ -16,7 +16,7 @@ describe 'SearchBar', ->
spyOn(SearchActions, "queryChanged")
test = "::Hello: World::"
ReactTestUtils.Simulate.change @input, target: value: test
expect(SearchActions.queryChanged).toHaveBeenCalledWith(test)
expect(SearchActions.queryChanged).toHaveBeenCalledWith([all: test])
it 'preserves capitalization on searches', ->
test = "HeLlO wOrLd"

View file

@ -154,7 +154,7 @@ beforeEach ->
provider: "gmail"
name: TEST_ACCOUNT_NAME
emailAddress: TEST_ACCOUNT_EMAIL
organizationUnit: NylasEnv.testOrganizationUnit
organizationUnit: NylasEnv.testOrganizationUnit || 'label'
clientId: TEST_ACCOUNT_CLIENT_ID
serverId: TEST_ACCOUNT_ID
})

View file

@ -1,5 +1,6 @@
_ = require 'underscore'
proxyquire = require 'proxyquire'
Rx = require 'rx-lite'
{NylasTestUtils} = require 'nylas-exports'
Contact = require '../../src/flux/models/contact'
NylasAPI = require '../../src/flux/nylas-api'
ContactStore = require '../../src/flux/stores/contact-store'
@ -7,6 +8,8 @@ ContactRankingStore = require '../../src/flux/stores/contact-ranking-store'
DatabaseStore = require '../../src/flux/stores/database-store'
AccountStore = require '../../src/flux/stores/account-store'
{mockObservable} = NylasTestUtils
describe "ContactStore", ->
beforeEach ->
spyOn(NylasEnv, "isMainWindow").andReturn true
@ -32,38 +35,39 @@ describe "ContactStore", ->
afterEach ->
NylasEnv.testOrganizationUnit = null
describe "when the Account updates from null to valid", ->
describe "when Contacts change", ->
beforeEach ->
spyOn(ContactStore, "_refreshCache")
AccountStore.trigger()
spyOn(Rx.Observable, 'fromQuery').andReturn mockObservable([])
ContactStore._registerObservables()
it "triggers a database fetch", ->
expect(ContactStore._refreshCache.calls.length).toBe 1
describe "ranking contacts", ->
beforeEach ->
ContactStore._accountId = TEST_ACCOUNT_ID
@c1 = new Contact(name: "Evan A", email: "evanA@nylas.com")
@c2 = new Contact(name: "Evan B", email: "evanB@nylas.com")
@c3 = new Contact(name: "Evan C", email: "evanC@nylas.com")
@c4 = new Contact(name: "Ben", email: "ben@nylas.com")
spyOn(DatabaseStore, "findAll").andCallFake ->
where: -> Promise.resolve([@c3, @c1, @c2, @c4])
@accountId = TEST_ACCOUNT_ID
@c1 = new Contact({name: "Evan A", email: "evanA@nylas.com", @accountId})
@c2 = new Contact({name: "Evan B", email: "evanB@nylas.com", @accountId})
@c3 = new Contact({name: "Evan C", email: "evanC@nylas.com", @accountId})
@c4 = new Contact({name: "Ben", email: "ben@nylas.com"})
@contacts = [@c3, @c1, @c2, @c4]
it "triggers a sort on a contact refresh", ->
spyOn(ContactStore, "_sortContactsCacheWithRankings")
ContactStore.__refreshCache()
advanceClock(100)
ContactStore.__refreshCache(@contacts)
expect(ContactStore._sortContactsCacheWithRankings).toHaveBeenCalled()
it "sorts the contact cache by the rankings", ->
spyOn(ContactRankingStore, 'value').andReturn
spyOn(ContactRankingStore, 'valueFor').andReturn
"evana@nylas.com": 10
"evanb@nylas.com": 1
"evanc@nylas.com": 0.1
ContactStore._contactCache = [@c3, @c1, @c2, @c4]
cache = {}
cache[@accountId] = [@c3, @c1, @c2, @c4]
ContactStore._contactCache = cache
ContactStore._sortContactsCacheWithRankings()
expect(ContactStore._contactCache).toEqual [@c1, @c2, @c3, @c4]
expect(ContactStore._contactCache[@accountId]).toEqual [@c1, @c2, @c3, @c4]
describe "when the Account updates but the ID doesn't change", ->
it "does nothing", ->

View file

@ -35,7 +35,7 @@ describe "EventRSVPTask", ->
"email": @myEmail,
"status": 'noreply'}
]
@task = new EventRSVPTask(@event, "no")
@task = new EventRSVPTask({accountId: TEST_ACCOUNT_ID}, @event, "no")
describe "performLocal", ->
it "should mark our status as no", ->

View file

@ -1,7 +1,6 @@
Actions = require '../actions'
Account = require '../models/account'
Utils = require '../models/utils'
MenuHelpers = require '../../menu-helpers'
DatabaseStore = require './database-store'
_ = require 'underscore'

View file

@ -40,11 +40,12 @@ class ContactStore extends NylasStore
if NylasEnv.isMainWindow() or NylasEnv.inSpecMode()
@_contactCache = {}
@listenTo ContactRankingStore, @_sortContactsCacheWithRankings
@_registerObservers()
@_registerObservables()
@_refreshCache()
_registerObservers: =>
_registerObservables: =>
# TODO I'm a bit worried about how big a cache this might be
@disposable?.dispose()
query = DatabaseStore.findAll(Contact)
@_disposable = Rx.Observable.fromQuery(query).subscribe(@_onContactsChanged)
@ -62,6 +63,7 @@ class ContactStore extends NylasStore
#
# Returns an {Array} of matching {Contact} models
#
# TODO pass accountId in all the appropriate places
searchContacts: (search, options={}) =>
{limit, noPromise, accountId} = options
if not NylasEnv.isMainWindow()
@ -101,8 +103,8 @@ class ContactStore extends NylasStore
false
matches = []
contacts = if account?
@_contactCache[account.id]
contacts = if accountId?
@_contactCache[accountId]
else
_.flatten(_.values(@_contactCache))

View file

@ -4,6 +4,7 @@ WorkspaceStore = require './workspace-store'
AccountStore = require './account-store'
Account = require '../models/account'
MailboxPerspective = require '../../mailbox-perspective'
MenuHelpers = require '../../menu-helpers'
CategoryStore = require './category-store'
Actions = require '../actions'