2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-04-09 10:25:00 +08:00
|
|
|
Thread = require '../../src/flux/models/thread'
|
|
|
|
FocusedContentStore = require '../../src/flux/stores/focused-content-store'
|
|
|
|
Actions = require '../../src/flux/actions'
|
|
|
|
|
2015-08-27 05:10:28 +08:00
|
|
|
testThread = new Thread(id: '123', accountId: 'abc')
|
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})
|
|
|
|
spyOn(FocusedContentStore, 'trigger')
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
|
|
|
|
expect(FocusedContentStore.trigger).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should not trigger if the focus is already null", ->
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: null})
|
|
|
|
spyOn(FocusedContentStore, 'trigger')
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: null})
|
|
|
|
expect(FocusedContentStore.trigger).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should trigger otherwise", ->
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: null})
|
|
|
|
spyOn(FocusedContentStore, 'trigger')
|
|
|
|
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
|
|
|
|
expect(FocusedContentStore.trigger).toHaveBeenCalled()
|
|
|
|
|
|
|
|
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)
|