fix(specs): fix contenteditable and contact search specs

This commit is contained in:
Evan Morikawa 2015-09-22 16:40:33 -07:00
parent b50d488f2e
commit a35416ae94
5 changed files with 67 additions and 49 deletions

View file

@ -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.

View file

@ -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(@)

View file

@ -8,6 +8,7 @@ SearchSuggestionStore = require '../lib/search-suggestion-store'
describe 'SearchBar', ->
beforeEach ->
spyOn(atom, "isMainWindow").andReturn true
@searchBar = ReactTestUtils.renderIntoDocument(<SearchBar />)
input = ReactTestUtils.findRenderedDOMComponentWithTag(@searchBar, "input")
@input = React.findDOMNode(input)

View file

@ -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

View file

@ -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)