diff --git a/internal_packages/composer/lib/contenteditable-component.cjsx b/internal_packages/composer/lib/contenteditable-component.cjsx index def8f1b90..6277a5eb4 100644 --- a/internal_packages/composer/lib/contenteditable-component.cjsx +++ b/internal_packages/composer/lib/contenteditable-component.cjsx @@ -14,7 +14,7 @@ class ContenteditableComponent extends React.Component html: React.PropTypes.string initialSelectionSnapshot: React.PropTypes.object - filters: React.PropTypes.object + filters: React.PropTypes.array footerElements: React.PropTypes.node # Passes an absolute top coordinate to scroll to. diff --git a/internal_packages/composer/spec/expanded-participants-spec.cjsx b/internal_packages/composer/spec/expanded-participants-spec.cjsx index e9b2f81bf..e06a17fc1 100644 --- a/internal_packages/composer/spec/expanded-participants-spec.cjsx +++ b/internal_packages/composer/spec/expanded-participants-spec.cjsx @@ -72,11 +72,12 @@ describe "ExpandedParticipants", -> it "pops out the composer when clicked", -> spyOn(Actions, "composePopoutDraft") - makeField.call(@, mode: "inline") + onPopoutComposer = jasmine.createSpy('onPopoutComposer') + makeField.call(@, mode: "inline", onPopoutComposer: onPopoutComposer) el = ReactTestUtils.findRenderedDOMComponentWithClass(@fields, "show-popout") ReactTestUtils.Simulate.click(React.findDOMNode(el)) - expect(Actions.composePopoutDraft).toHaveBeenCalled() - expect(Actions.composePopoutDraft.calls.length).toBe 1 + expect(onPopoutComposer).toHaveBeenCalled() + expect(onPopoutComposer.calls.length).toBe 1 it "shows and focuses cc when clicked", -> makeField.call(@) diff --git a/internal_packages/search-bar/spec/search-bar-spec.cjsx b/internal_packages/search-bar/spec/search-bar-spec.cjsx index e9e6aa030..227a667d8 100644 --- a/internal_packages/search-bar/spec/search-bar-spec.cjsx +++ b/internal_packages/search-bar/spec/search-bar-spec.cjsx @@ -8,6 +8,7 @@ SearchSuggestionStore = require '../lib/search-suggestion-store' describe 'SearchBar', -> beforeEach -> + spyOn(atom, "isMainWindow").andReturn true @searchBar = ReactTestUtils.renderIntoDocument() input = ReactTestUtils.findRenderedDOMComponentWithTag(@searchBar, "input") @input = React.findDOMNode(input) diff --git a/spec-nylas/stores/contact-store-spec.coffee b/spec-nylas/stores/contact-store-spec.coffee index 492e058f7..927371ae5 100644 --- a/spec-nylas/stores/contact-store-spec.coffee +++ b/spec-nylas/stores/contact-store-spec.coffee @@ -7,6 +7,7 @@ AccountStore = require '../../src/flux/stores/account-store' describe "ContactStore", -> beforeEach -> + spyOn(atom, "isMainWindow").andReturn true atom.testOrganizationUnit = "folder" ContactStore._contactCache = [] ContactStore._fetchOffset = 0 @@ -52,38 +53,38 @@ describe "ContactStore", -> ContactStore._contactCache = [@c1,@c2,@c3,@c4,@c5,@c6,@c7] it "can find by first name", -> - results = ContactStore.searchContacts("First") + results = ContactStore.searchContacts("First", noPromise: true) 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") + results = ContactStore.searchContacts("Last", noPromise: true) expect(results.length).toBe 1 expect(results[0]).toBe @c3 it "can find by email", -> - results = ContactStore.searchContacts("1test") + results = ContactStore.searchContacts("1test", noPromise: true) expect(results.length).toBe 1 expect(results[0]).toBe @c1 it "is case insensitive", -> - results = ContactStore.searchContacts("FIrsT") + results = ContactStore.searchContacts("FIrsT", noPromise: true) 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) + results = ContactStore.searchContacts("FIrsT", limit: 1, noPromise: true) expect(results.length).toBe 1 expect(results[0]).toBe @c2 it "returns no more than 5 by default", -> - results = ContactStore.searchContacts("fi") + results = ContactStore.searchContacts("fi", noPromise: true) expect(results.length).toBe 5 it "can return more than 5 if requested", -> - results = ContactStore.searchContacts("fi", limit: 6) + results = ContactStore.searchContacts("fi", limit: 6, noPromise: true) expect(results.length).toBe 6 describe 'parseContactsInString', -> @@ -114,6 +115,8 @@ describe "ContactStore", -> _.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 + waitsForPromise -> + ContactStore.parseContactsInString(key).then (contacts) -> + contacts = contacts.map (c) -> c.toString() + expectedContacts = value.map (c) -> c.toString() + expect(contacts).toEqual expectedContacts diff --git a/spec-nylas/stores/draft-store-spec.coffee b/spec-nylas/stores/draft-store-spec.coffee index 6acdf4f61..f43f1fc2e 100644 --- a/spec-nylas/stores/draft-store-spec.coffee +++ b/spec-nylas/stores/draft-store-spec.coffee @@ -390,13 +390,10 @@ describe "DraftStore", -> # A helper method that makes it easy to test _newMessageWithContext, which # is asynchronous and whose output is a model persisted to the database. @_callNewMessageWithContext = (context, attributesCallback, modelCallback) -> - runs -> - DraftStore._newMessageWithContext(context, attributesCallback) - waitsFor -> - DatabaseStore.persistModel.callCount > 0 - runs -> - model = DatabaseStore.persistModel.mostRecentCall.args[0] - modelCallback(model) if modelCallback + waitsForPromise -> + DraftStore._newMessageWithContext(context, attributesCallback).then -> + model = DatabaseStore.persistModel.mostRecentCall.args[0] + modelCallback(model) if modelCallback it "should create a new message", -> @_callNewMessageWithContext {threadId: fakeThread.id} @@ -779,6 +776,7 @@ describe "DraftStore", -> describe "session teardown", -> beforeEach -> + spyOn(atom, 'isMainWindow').andReturn true @draftTeardown = jasmine.createSpy('draft teardown') @session = draftClientId: "abc" @@ -798,6 +796,9 @@ describe "DraftStore", -> expect(@draftTeardown).toHaveBeenCalled describe "mailto handling", -> + beforeEach -> + spyOn(atom, 'isMainWindow').andReturn true + describe "extensions", -> beforeEach -> DraftStore.registerExtension(TestExtension) @@ -809,30 +810,39 @@ describe "DraftStore", -> spyOn(DatabaseStore, 'persistModel').andCallFake (draft) -> received = draft Promise.resolve() - DraftStore._onHandleMailtoLink('mailto:bengotow@gmail.com') - expect(received.body.indexOf("Edited by TestExtension!")).toBe(0) + waitsForPromise -> + DraftStore._onHandleMailtoLink('mailto:bengotow@gmail.com').then -> + expect(received.body.indexOf("Edited by TestExtension!")).toBe(0) - it "should be case-insensitive towards subject keys", -> - received = null - spyOn(DraftStore, '_finalizeAndPersistNewMessage').andCallFake (draft) -> - received = draft - Promise.resolve({draftClientId: 123}) + describe "when testing subject keys", -> + beforeEach -> + spyOn(DraftStore, '_finalizeAndPersistNewMessage').andCallFake (draft) -> + Promise.resolve({draftClientId: 123}) - expected = "EmailSubjectLOLOL" - DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?subject=' + expected) - expect(received.subject).toBe(expected) + @expected = "EmailSubjectLOLOL" - DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?Subject=' + expected) - expect(received.subject).toBe(expected) + it "works for lowercase", -> + waitsForPromise => + DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?subject=' + @expected).then => + received = DraftStore._finalizeAndPersistNewMessage.mostRecentCall.args[0] + expect(received.subject).toBe(@expected) - DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?SUBJECT=' + expected) - expect(received.subject).toBe(expected) + it "works for title case", -> + waitsForPromise => + DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?Subject=' + @expected).then => + received = DraftStore._finalizeAndPersistNewMessage.mostRecentCall.args[0] + expect(received.subject).toBe(@expected) - it "should correctly instantiate drafts for a wide range of mailto URLs", -> - received = null - spyOn(DatabaseStore, 'persistModel').andCallFake (draft) -> - received = draft - Promise.resolve() + it "works for uppercase", -> + waitsForPromise => + DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?SUBJECT=' + @expected).then => + received = DraftStore._finalizeAndPersistNewMessage.mostRecentCall.args[0] + expect(received.subject).toBe(@expected) + + describe "should correctly instantiate drafts for a wide range of mailto URLs", -> + beforeEach -> + spyOn(DatabaseStore, 'persistModel').andCallFake (draft) -> + Promise.resolve() links = [ 'mailto:' @@ -895,12 +905,15 @@ describe "DraftStore", -> ) ] - for link, idx in links - DraftStore._onHandleMailtoLink(link) - expectedDraft = expected[idx] - expect(received['subject']).toEqual(expectedDraft['subject']) - for attr in ['to', 'cc', 'bcc', 'subject'] - for contact, jdx in received[attr] - expectedContact = expectedDraft[attr][jdx] - expect(contact.email).toEqual(expectedContact.email) - expect(contact.name).toEqual(expectedContact.name) + links.forEach (link, idx) -> + it "works for #{link}", -> + waitsForPromise -> + DraftStore._onHandleMailtoLink(link).then -> + expectedDraft = expected[idx] + received = DatabaseStore.persistModel.mostRecentCall.args[0] + expect(received['subject']).toEqual(expectedDraft['subject']) + for attr in ['to', 'cc', 'bcc', 'subject'] + for contact, jdx in received[attr] + expectedContact = expectedDraft[attr][jdx] + expect(contact.email).toEqual(expectedContact.email) + expect(contact.name).toEqual(expectedContact.name)