mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 08:16:09 +08:00
fix(focused-content): Better test fixtures for previous fix
This commit is contained in:
parent
705200a138
commit
3b0a7910e0
|
@ -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", ->
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue