mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
81d2edcaf9
Summary: This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`. This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work. When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account. Search bar doesn't need to do full refresh on clear if it never committed Allow drafts to be switched to a different account when not in reply to an existing thread Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal Show many dots for many accounts in long polling status bar add/remove accounts from prefs Spec fixes! Test Plan: Run tests, none broken! Reviewers: evan, dillon Reviewed By: evan, dillon Differential Revision: https://phab.nylas.com/D1928
122 lines
5.2 KiB
CoffeeScript
122 lines
5.2 KiB
CoffeeScript
_ = require 'underscore'
|
|
proxyquire = require 'proxyquire'
|
|
Contact = require '../../src/flux/models/contact'
|
|
ContactStore = require '../../src/flux/stores/contact-store'
|
|
DatabaseStore = require '../../src/flux/stores/database-store'
|
|
AccountStore = require '../../src/flux/stores/account-store'
|
|
|
|
describe "ContactStore", ->
|
|
beforeEach ->
|
|
atom.testOrganizationUnit = "folder"
|
|
ContactStore._contactCache = []
|
|
ContactStore._fetchOffset = 0
|
|
ContactStore._accountId = null
|
|
AccountStore._current =
|
|
id: "test_account_id"
|
|
|
|
afterEach ->
|
|
atom.testOrganizationUnit = null
|
|
|
|
it "initializes the cache from the DB", ->
|
|
spyOn(DatabaseStore, "findAll").andCallFake -> Promise.resolve([])
|
|
ContactStore.constructor()
|
|
expect(ContactStore._contactCache.length).toBe 0
|
|
expect(ContactStore._fetchOffset).toBe 0
|
|
|
|
describe "when the Account updates from null to valid", ->
|
|
beforeEach ->
|
|
spyOn(ContactStore, "_refreshCache")
|
|
AccountStore.trigger()
|
|
|
|
it "triggers a database fetch", ->
|
|
expect(ContactStore._refreshCache.calls.length).toBe 1
|
|
|
|
describe "when the Account updates but the ID doesn't change", ->
|
|
it "does nothing", ->
|
|
spyOn(ContactStore, "_refreshCache")
|
|
ContactStore._contactCache = [1,2,3]
|
|
ContactStore._fetchOffset = 3
|
|
ContactStore._accountId = "test_account_id"
|
|
AccountStore._current =
|
|
id: "test_account_id"
|
|
AccountStore.trigger()
|
|
expect(ContactStore._contactCache).toEqual [1,2,3]
|
|
expect(ContactStore._fetchOffset).toBe 3
|
|
expect(ContactStore._refreshCache).not.toHaveBeenCalled()
|
|
|
|
describe "when searching for a contact", ->
|
|
beforeEach ->
|
|
@c1 = new Contact(name: "", email: "1test@nylas.com")
|
|
@c2 = new Contact(name: "First", email: "2test@nylas.com")
|
|
@c3 = new Contact(name: "First Last", email: "3test@nylas.com")
|
|
@c4 = new Contact(name: "Fit", email: "fit@nylas.com")
|
|
@c5 = new Contact(name: "Fins", email: "fins@nylas.com")
|
|
@c6 = new Contact(name: "Fill", email: "fill@nylas.com")
|
|
@c7 = new Contact(name: "Fin", email: "fin@nylas.com")
|
|
ContactStore._contactCache = [@c1,@c2,@c3,@c4,@c5,@c6,@c7]
|
|
|
|
it "can find by first name", ->
|
|
results = ContactStore.searchContacts("First")
|
|
expect(results.length).toBe 2
|
|
expect(results[0]).toBe @c2
|
|
expect(results[1]).toBe @c3
|
|
|
|
it "can find by last name", ->
|
|
results = ContactStore.searchContacts("Last")
|
|
expect(results.length).toBe 1
|
|
expect(results[0]).toBe @c3
|
|
|
|
it "can find by email", ->
|
|
results = ContactStore.searchContacts("1test")
|
|
expect(results.length).toBe 1
|
|
expect(results[0]).toBe @c1
|
|
|
|
it "is case insensitive", ->
|
|
results = ContactStore.searchContacts("FIrsT")
|
|
expect(results.length).toBe 2
|
|
expect(results[0]).toBe @c2
|
|
expect(results[1]).toBe @c3
|
|
|
|
it "only returns the number requested", ->
|
|
results = ContactStore.searchContacts("FIrsT", limit: 1)
|
|
expect(results.length).toBe 1
|
|
expect(results[0]).toBe @c2
|
|
|
|
it "returns no more than 5 by default", ->
|
|
results = ContactStore.searchContacts("fi")
|
|
expect(results.length).toBe 5
|
|
|
|
it "can return more than 5 if requested", ->
|
|
results = ContactStore.searchContacts("fi", limit: 6)
|
|
expect(results.length).toBe 6
|
|
|
|
describe 'parseContactsInString', ->
|
|
testCases =
|
|
# Single contact test cases
|
|
"evan@nylas.com": [new Contact(name: "evan@nylas.com", email: "evan@nylas.com")]
|
|
"Evan Morikawa": []
|
|
"Evan Morikawa <evan@nylas.com>": [new Contact(name: "Evan Morikawa", email: "evan@nylas.com")]
|
|
"Evan Morikawa (evan@nylas.com)": [new Contact(name: "Evan Morikawa", email: "evan@nylas.com")]
|
|
"spang (Christine Spang) <noreply+phabricator@nilas.com>": [new Contact(name: "spang (Christine Spang)", email: "noreply+phabricator@nilas.com")]
|
|
"spang 'Christine Spang' <noreply+phabricator@nilas.com>": [new Contact(name: "spang 'Christine Spang'", email: "noreply+phabricator@nilas.com")]
|
|
"spang \"Christine Spang\" <noreply+phabricator@nilas.com>": [new Contact(name: "spang \"Christine Spang\"", email: "noreply+phabricator@nilas.com")]
|
|
"Evan (evan@nylas.com)": [new Contact(name: "Evan", email: "evan@nylas.com")]
|
|
"\"Michael\" (mg@nylas.com)": [new Contact(name: "Michael", email: "mg@nylas.com")]
|
|
|
|
# Multiple contact test cases
|
|
"Evan Morikawa <evan@nylas.com>, Ben <ben@nylas.com>": [
|
|
new Contact(name: "Evan Morikawa", email: "evan@nylas.com")
|
|
new Contact(name: "Ben", email: "ben@nylas.com")
|
|
]
|
|
"mark@nylas.com\nGleb (gleb@nylas.com)\rEvan Morikawa <evan@nylas.com>, spang (Christine Spang) <noreply+phabricator@nilas.com>": [
|
|
new Contact(name: "", email: "mark@nylas.com")
|
|
new Contact(name: "Gleb", email: "gleb@nylas.com")
|
|
new Contact(name: "Evan Morikawa", email: "evan@nylas.com")
|
|
new Contact(name: "spang (Christine Spang)", email: "noreply+phabricator@nilas.com")
|
|
]
|
|
|
|
_.forEach testCases, (value, key) ->
|
|
it "works for #{key}", ->
|
|
testContacts = ContactStore.parseContactsInString(key).map (c) -> c.toString()
|
|
expectedContacts = value.map (c) -> c.toString()
|
|
expect(testContacts).toEqual expectedContacts
|