fix(focused-content): Better test fixtures for previous fix

This commit is contained in:
Ben Gotow 2015-09-28 01:32:20 -07:00
parent 705200a138
commit 3b0a7910e0
2 changed files with 12 additions and 10 deletions

View file

@ -9,21 +9,21 @@ describe "FocusedContentStore", ->
describe "onSetFocus", ->
it "should not trigger if the thread is already focused", ->
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
spyOn(FocusedContentStore, 'trigger')
spyOn(FocusedContentStore, 'triggerAfterAnimationFrame')
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
expect(FocusedContentStore.trigger).not.toHaveBeenCalled()
expect(FocusedContentStore.triggerAfterAnimationFrame).not.toHaveBeenCalled()
it "should not trigger if the focus is already null", ->
FocusedContentStore._onFocus({collection: 'thread', item: null})
spyOn(FocusedContentStore, 'trigger')
spyOn(FocusedContentStore, 'triggerAfterAnimationFrame')
FocusedContentStore._onFocus({collection: 'thread', item: null})
expect(FocusedContentStore.trigger).not.toHaveBeenCalled()
expect(FocusedContentStore.triggerAfterAnimationFrame).not.toHaveBeenCalled()
it "should trigger otherwise", ->
FocusedContentStore._onFocus({collection: 'thread', item: null})
spyOn(FocusedContentStore, 'trigger')
spyOn(FocusedContentStore, 'triggerAfterAnimationFrame')
FocusedContentStore._onFocus({collection: 'thread', item: testThread})
expect(FocusedContentStore.trigger).toHaveBeenCalled()
expect(FocusedContentStore.triggerAfterAnimationFrame).toHaveBeenCalled()
describe "threadId", ->
it "should return the id of the focused thread", ->

View file

@ -64,6 +64,10 @@ class FocusedContentStore
@listenTo Actions.setFocus, @_onFocus
@listenTo Actions.setCursorPosition, @_onFocusKeyboard
triggerAfterAnimationFrame: (payload) =>
window.requestAnimationFrame =>
@trigger(payload)
_resetInstanceVars: =>
@_focused = {}
@_keyboardCursor = {}
@ -81,8 +85,7 @@ class FocusedContentStore
return if @_keyboardCursor[collection]?.id is item?.id
@_keyboardCursor[collection] = item
window.requestAnimationFrame =>
@trigger({ impactsCollection: (c) -> c is collection })
@triggerAfterAnimationFrame({ impactsCollection: (c) -> c is collection })
_onFocus: ({collection, item}) =>
throw new Error("focus() requires a collection") unless collection
@ -90,8 +93,7 @@ class FocusedContentStore
@_focused[collection] = item
@_keyboardCursor[collection] = item if item
window.requestAnimationFrame =>
@trigger({ impactsCollection: (c) -> c is collection })
@triggerAfterAnimationFrame({ impactsCollection: (c) -> c is collection })
_onWorkspaceChange: =>
keyboardCursorEnabled = WorkspaceStore.layoutMode() is 'list'