2015-06-26 01:33:26 +08:00
|
|
|
React = require "react/addons"
|
|
|
|
TestUtils = React.addons.TestUtils
|
2015-07-16 23:54:20 +08:00
|
|
|
{Thread, FocusedContentStore, Actions} = require "nylas-exports"
|
2015-06-26 01:33:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
MessageToolbarItems = require '../lib/message-toolbar-items'
|
|
|
|
|
|
|
|
test_thread = (new Thread).fromJSON({
|
|
|
|
"id" : "thread_12345"
|
|
|
|
"subject" : "Subject 12345"
|
2015-07-16 23:54:20 +08:00
|
|
|
"starred": false
|
2015-06-26 01:33:26 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test_thread_starred = (new Thread).fromJSON({
|
|
|
|
"id" : "thread_starred_12345"
|
|
|
|
"subject" : "Subject 12345"
|
2015-07-16 23:54:20 +08:00
|
|
|
"starred": true
|
2015-06-26 01:33:26 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
describe "MessageToolbarItem starring", ->
|
|
|
|
it "stars a thread if the star button is clicked and thread is unstarred", ->
|
|
|
|
spyOn(FocusedContentStore, "focused").andCallFake ->
|
|
|
|
test_thread
|
|
|
|
spyOn(Actions, 'queueTask')
|
|
|
|
messageToolbarItems = TestUtils.renderIntoDocument(<MessageToolbarItems />)
|
|
|
|
|
|
|
|
starButton = React.findDOMNode(messageToolbarItems.refs.starButton)
|
|
|
|
TestUtils.Simulate.click starButton
|
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
expect(Actions.queueTask.mostRecentCall.args[0].objects).toEqual([test_thread])
|
|
|
|
expect(Actions.queueTask.mostRecentCall.args[0].newValues).toEqual(starred: true)
|
2015-06-26 01:33:26 +08:00
|
|
|
|
|
|
|
it "unstars a thread if the star button is clicked and thread is starred", ->
|
|
|
|
spyOn(FocusedContentStore, "focused").andCallFake ->
|
|
|
|
test_thread_starred
|
|
|
|
spyOn(Actions, 'queueTask')
|
|
|
|
messageToolbarItems = TestUtils.renderIntoDocument(<MessageToolbarItems />)
|
|
|
|
|
|
|
|
starButton = React.findDOMNode(messageToolbarItems.refs.starButton)
|
|
|
|
TestUtils.Simulate.click starButton
|
|
|
|
|
2015-07-16 23:54:20 +08:00
|
|
|
expect(Actions.queueTask.mostRecentCall.args[0].objects).toEqual([test_thread_starred])
|
|
|
|
expect(Actions.queueTask.mostRecentCall.args[0].newValues).toEqual(starred: false)
|