2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2016-05-04 07:42:28 +08:00
|
|
|
Thread = require('../../src/flux/models/thread').default
|
2015-04-09 10:25:00 +08:00
|
|
|
FocusedContentStore = require '../../src/flux/stores/focused-content-store'
|
2016-10-28 09:48:33 +08:00
|
|
|
Actions = require('../../src/flux/actions').default
|
2015-04-09 10:25:00 +08:00
|
|
|
|
2016-01-26 09:28:28 +08:00
|
|
|
testThread = new Thread(id: '123', accountId: TEST_ACCOUNT_ID)
|
2015-04-09 10:25:00 +08:00
|
|
|
|
|
|
|
describe "FocusedContentStore", ->
|
2015-06-12 09:00:40 +08:00
|
|
|
describe "onSetFocus", ->
|
2015-04-09 10:25:00 +08:00
|
|
|
it "should not trigger if the thread is already focused", ->
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
|
2015-09-28 16:32:20 +08:00
|
|
|
spyOn(FocusedContentStore, 'triggerAfterAnimationFrame')
|
2015-04-09 10:25:00 +08:00
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
|
2015-09-28 16:32:20 +08:00
|
|
|
expect(FocusedContentStore.triggerAfterAnimationFrame).not.toHaveBeenCalled()
|
2015-04-09 10:25:00 +08:00
|
|
|
|
|
|
|
it "should not trigger if the focus is already null", ->
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: null})
|
2015-09-28 16:32:20 +08:00
|
|
|
spyOn(FocusedContentStore, 'triggerAfterAnimationFrame')
|
2015-04-09 10:25:00 +08:00
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: null})
|
2015-09-28 16:32:20 +08:00
|
|
|
expect(FocusedContentStore.triggerAfterAnimationFrame).not.toHaveBeenCalled()
|
2015-04-09 10:25:00 +08:00
|
|
|
|
|
|
|
it "should trigger otherwise", ->
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: null})
|
2015-09-28 16:32:20 +08:00
|
|
|
spyOn(FocusedContentStore, 'triggerAfterAnimationFrame')
|
2015-04-09 10:25:00 +08:00
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
|
2015-09-28 16:32:20 +08:00
|
|
|
expect(FocusedContentStore.triggerAfterAnimationFrame).toHaveBeenCalled()
|
2015-04-09 10:25:00 +08:00
|
|
|
|
|
|
|
describe "threadId", ->
|
|
|
|
it "should return the id of the focused thread", ->
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
|
|
|
|
expect(FocusedContentStore.focusedId('thread')).toBe(testThread.id)
|
|
|
|
|
|
|
|
describe "thread", ->
|
|
|
|
it "should return the focused thread object", ->
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
|
|
|
|
expect(FocusedContentStore.focused('thread')).toBe(testThread)
|