2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-03-18 07:19:16 +08:00
|
|
|
proxyquire = require 'proxyquire'
|
|
|
|
Contact = require '../../src/flux/models/contact'
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
ContactStore = require '../../src/flux/stores/contact-store'
|
2015-03-18 07:19:16 +08:00
|
|
|
DatabaseStore = require '../../src/flux/stores/database-store'
|
|
|
|
NamespaceStore = require '../../src/flux/stores/namespace-store'
|
fix(drafts): Various improvements and fixes to drafts, draft state management
Summary:
This diff contains a few major changes:
1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario:
- View thread with draft, edit draft
- Move to another thread
- Move back to thread with draft
- Move to another thread. Notice that one or more messages from thread with draft are still there.
There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great.
2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here:
- In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI.
- Previously, when you added a contact to To/CC/BCC, this happened:
<input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates
Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state.
To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source!
This diff includes a few minor fixes as well:
1. Draft.state is gone—use Message.object = draft instead
2. String model attributes should never be null
3. Pre-send checks that can cancel draft send
4. Put the entire curl history and task queue into feedback reports
5. Cache localIds for extra speed
6. Move us up to latest React
Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
|
|
|
|
|
|
|
describe "ContactStore", ->
|
2015-03-18 07:19:16 +08:00
|
|
|
beforeEach ->
|
2015-07-16 23:54:20 +08:00
|
|
|
atom.testOrganizationUnit = "folder"
|
2015-03-18 07:19:16 +08:00
|
|
|
ContactStore._contactCache = []
|
|
|
|
ContactStore._fetchOffset = 0
|
|
|
|
ContactStore._namespaceId = null
|
|
|
|
ContactStore._lastNamespaceId = null
|
|
|
|
NamespaceStore._current =
|
|
|
|
id: "nsid"
|
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
afterEach ->
|
|
|
|
atom.testOrganizationUnit = null
|
|
|
|
|
2015-03-18 07:19:16 +08:00
|
|
|
it "initializes the cache from the DB", ->
|
|
|
|
spyOn(DatabaseStore, "findAll").andCallFake -> Promise.resolve([])
|
2015-04-29 08:33:46 +08:00
|
|
|
ContactStore.constructor()
|
2015-03-18 07:19:16 +08:00
|
|
|
expect(ContactStore._contactCache.length).toBe 0
|
|
|
|
expect(ContactStore._fetchOffset).toBe 0
|
|
|
|
|
|
|
|
describe "when the Namespace updates from null to valid", ->
|
|
|
|
beforeEach ->
|
2015-04-07 02:46:20 +08:00
|
|
|
spyOn(ContactStore, "_refreshCache")
|
2015-03-18 07:19:16 +08:00
|
|
|
NamespaceStore.trigger()
|
|
|
|
|
|
|
|
it "triggers a database fetch", ->
|
2015-04-07 02:46:20 +08:00
|
|
|
expect(ContactStore._refreshCache.calls.length).toBe 1
|
2015-03-26 03:41:48 +08:00
|
|
|
|
2015-03-18 07:19:16 +08:00
|
|
|
describe "when the Namespace updates but the ID doesn't change", ->
|
|
|
|
it "does nothing", ->
|
2015-04-07 02:46:20 +08:00
|
|
|
spyOn(ContactStore, "_refreshCache")
|
2015-03-18 07:19:16 +08:00
|
|
|
ContactStore._contactCache = [1,2,3]
|
|
|
|
ContactStore._fetchOffset = 3
|
|
|
|
ContactStore._namespaceId = "nsid"
|
|
|
|
ContactStore._lastNamespaceId = "nsid"
|
|
|
|
NamespaceStore._current =
|
|
|
|
id: "nsid"
|
|
|
|
NamespaceStore.trigger()
|
|
|
|
expect(ContactStore._contactCache).toEqual [1,2,3]
|
|
|
|
expect(ContactStore._fetchOffset).toBe 3
|
2015-04-07 02:46:20 +08:00
|
|
|
expect(ContactStore._refreshCache).not.toHaveBeenCalled()
|
2015-03-18 07:19:16 +08:00
|
|
|
|
|
|
|
describe "when searching for a contact", ->
|
|
|
|
beforeEach ->
|
2015-05-15 08:08:30 +08:00
|
|
|
@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")
|
2015-03-18 07:19:16 +08:00
|
|
|
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
|
2015-07-13 22:25:30 +08:00
|
|
|
|
|
|
|
describe 'parseContactsInString', ->
|
|
|
|
testCases =
|
2015-08-04 04:06:28 +08:00
|
|
|
# Single contact test cases
|
2015-07-13 22:25:30 +08:00
|
|
|
"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")]
|
2015-08-04 04:06:28 +08:00
|
|
|
"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")]
|
2015-07-13 22:25:30 +08:00
|
|
|
"Evan (evan@nylas.com)": [new Contact(name: "Evan", email: "evan@nylas.com")]
|
2015-08-04 04:06:28 +08:00
|
|
|
|
|
|
|
# Multiple contact test cases
|
2015-07-13 22:25:30 +08:00
|
|
|
"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")
|
|
|
|
]
|
2015-08-04 04:06:28 +08:00
|
|
|
"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")
|
|
|
|
]
|
2015-07-13 22:25:30 +08:00
|
|
|
|
|
|
|
_.forEach testCases, (value, key) ->
|
|
|
|
it "works for #{key}", ->
|
2015-08-04 04:06:28 +08:00
|
|
|
testContacts = ContactStore.parseContactsInString(key).map (c) -> c.toString()
|
|
|
|
expectedContacts = value.map (c) -> c.toString()
|
2015-07-13 22:25:30 +08:00
|
|
|
expect(testContacts).toEqual expectedContacts
|