Fix MultiSelectListInteractionHandlers specs

This commit is contained in:
Juan Tejada 2016-01-21 17:07:32 -08:00
parent 946d81bf20
commit 6b144b867d

View file

@ -15,6 +15,8 @@ describe "MultiselectListInteractionHandler", ->
data = [@item, @itemFocus, @itemAfterFocus, @itemKeyboardFocus, @itemAfterKeyboardFocus]
@onFocusItem = jasmine.createSpy('onFocusItem')
@onSetCursorPosition = jasmine.createSpy('onSetCursorPosition')
@dataSource =
selection:
toggle: jasmine.createSpy('toggle')
@ -28,15 +30,18 @@ describe "MultiselectListInteractionHandler", ->
_.findIndex data, (item) -> item.id is id
count: -> data.length
@props =
dataSource: @dataSource
keyboardCursorId: 'keyboard-focus'
focusedId: 'focus'
onFocusItem: @onFocusItem
onSetCursorPosition: @onSetCursorPosition
@collection = 'threads'
@handler = new MultiselectListInteractionHandler(@dataSource, @collection)
@isRootSheet = true
@handler = new MultiselectListInteractionHandler(@props)
spyOn(WorkspaceStore, 'topSheet').andCallFake => {root: @isRootSheet}
spyOn(FocusedContentStore, 'keyboardCursorId').andCallFake -> 'keyboard-focus'
spyOn(FocusedContentStore, 'focusedId').andCallFake -> 'focus'
spyOn(Actions, 'setFocus')
spyOn(Actions, 'setCursorPosition')
it "should never show focus", ->
expect(@handler.shouldShowFocus()).toEqual(false)
@ -44,10 +49,13 @@ describe "MultiselectListInteractionHandler", ->
it "should always show the keyboard cursor", ->
expect(@handler.shouldShowKeyboardCursor()).toEqual(true)
it "should always show checkmarks", ->
expect(@handler.shouldShowCheckmarks()).toEqual(true)
describe "onClick", ->
it "should focus list items", ->
@handler.onClick(@item)
expect(Actions.setFocus).toHaveBeenCalledWith({collection: @collection, item: @item})
expect(@onFocusItem).toHaveBeenCalledWith(@item)
describe "onMetaClick", ->
it "shoud toggle selection", ->
@ -56,7 +64,7 @@ describe "MultiselectListInteractionHandler", ->
it "should focus the keyboard on the clicked item", ->
@handler.onMetaClick(@item)
expect(Actions.setCursorPosition).toHaveBeenCalledWith({collection: @collection, item: @item})
expect(@onSetCursorPosition).toHaveBeenCalledWith(@item)
describe "onShiftClick", ->
it "should expand selection", ->
@ -65,12 +73,12 @@ describe "MultiselectListInteractionHandler", ->
it "should focus the keyboard on the clicked item", ->
@handler.onShiftClick(@item)
expect(Actions.setCursorPosition).toHaveBeenCalledWith({collection: @collection, item: @item})
expect(@onSetCursorPosition).toHaveBeenCalledWith(@item)
describe "onEnter", ->
it "should focus the item with the current keyboard selection", ->
@handler.onEnter()
expect(Actions.setFocus).toHaveBeenCalledWith({collection: @collection, item: @itemKeyboardFocus})
expect(@onFocusItem).toHaveBeenCalledWith(@itemKeyboardFocus)
describe "onSelect (x key on keyboard)", ->
describe "on the root view", ->
@ -92,7 +100,7 @@ describe "MultiselectListInteractionHandler", ->
it "should shift the keyboard item", ->
@handler.onShift(1, {})
expect(Actions.setCursorPosition).toHaveBeenCalledWith({collection: @collection, item: @itemAfterKeyboardFocus})
expect(@onSetCursorPosition).toHaveBeenCalledWith(@itemAfterKeyboardFocus)
it "should walk selection if the select option is passed", ->
@handler.onShift(1, select: true)
@ -104,4 +112,4 @@ describe "MultiselectListInteractionHandler", ->
it "should shift the focused item", ->
@handler.onShift(1, {})
expect(Actions.setFocus).toHaveBeenCalledWith({collection: @collection, item: @itemAfterFocus})
expect(@onFocusItem).toHaveBeenCalledWith(@itemAfterFocus)