mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Update SelectListView spec for API changes
This commit is contained in:
@@ -2,25 +2,25 @@ SelectListView = require '../src/select-list-view'
|
||||
{$, $$} = require 'atom'
|
||||
|
||||
describe "SelectListView", ->
|
||||
[selectList, array, list, miniEditor] = []
|
||||
[selectList, items, list, editorView] = []
|
||||
|
||||
beforeEach ->
|
||||
array = [
|
||||
items = [
|
||||
["A", "Alpha"], ["B", "Bravo"], ["C", "Charlie"],
|
||||
["D", "Delta"], ["E", "Echo"], ["F", "Foxtrot"]
|
||||
]
|
||||
|
||||
selectList = new SelectListView
|
||||
selectList.maxItems = 4
|
||||
selectList.filterKey = 1
|
||||
selectList.itemForElement = (element) ->
|
||||
$$ -> @li element[1], class: element[0]
|
||||
selectList.setMaxItems(4)
|
||||
selectList.getFilterKey = -> 1
|
||||
selectList.viewForItem = (item) ->
|
||||
$$ -> @li item[1], class: item[0]
|
||||
|
||||
selectList.confirmed = jasmine.createSpy('confirmed hook')
|
||||
selectList.cancelled = jasmine.createSpy('cancelled hook')
|
||||
|
||||
selectList.setArray(array)
|
||||
{list, miniEditor} = selectList
|
||||
selectList.setItems(items)
|
||||
{list, editorView} = selectList
|
||||
|
||||
describe "when an array is assigned", ->
|
||||
it "populates the list with up to maxItems items, based on the liForElement function", ->
|
||||
@@ -33,7 +33,7 @@ describe "SelectListView", ->
|
||||
selectList.attachToDom()
|
||||
|
||||
it "filters the elements in the list based on the scoreElement function and selects the first item", ->
|
||||
miniEditor.getEditor().insertText('la')
|
||||
editorView.getEditor().insertText('la')
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li').length).toBe 2
|
||||
@@ -43,54 +43,54 @@ describe "SelectListView", ->
|
||||
expect(selectList.error).not.toBeVisible()
|
||||
|
||||
it "displays an error if there are no matches, removes error when there are matches", ->
|
||||
miniEditor.getEditor().insertText('nothing will match this')
|
||||
editorView.getEditor().insertText('nothing will match this')
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li').length).toBe 0
|
||||
expect(selectList.error).not.toBeHidden()
|
||||
|
||||
miniEditor.getEditor().setText('la')
|
||||
editorView.getEditor().setText('la')
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li').length).toBe 2
|
||||
expect(selectList.error).not.toBeVisible()
|
||||
|
||||
it "displays no elements until the array has been set on the list", ->
|
||||
selectList.array = null
|
||||
selectList.items = null
|
||||
selectList.list.empty()
|
||||
miniEditor.getEditor().insertText('la')
|
||||
editorView.getEditor().insertText('la')
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li').length).toBe 0
|
||||
expect(selectList.error).toBeHidden()
|
||||
selectList.setArray(array)
|
||||
selectList.setItems(items)
|
||||
expect(list.find('li').length).toBe 2
|
||||
|
||||
describe "when core:move-up / core:move-down are triggered on the miniEditor", ->
|
||||
describe "when core:move-up / core:move-down are triggered on the editorView", ->
|
||||
it "selects the previous / next item in the list, or wraps around to the other side", ->
|
||||
expect(list.find('li:first')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'core:move-up'
|
||||
editorView.trigger 'core:move-up'
|
||||
|
||||
expect(list.find('li:first')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:last')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'core:move-down'
|
||||
editorView.trigger 'core:move-down'
|
||||
|
||||
expect(list.find('li:first')).toHaveClass 'selected'
|
||||
expect(list.find('li:last')).not.toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'core:move-down'
|
||||
editorView.trigger 'core:move-down'
|
||||
|
||||
expect(list.find('li:eq(0)')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:eq(1)')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'core:move-down'
|
||||
editorView.trigger 'core:move-down'
|
||||
|
||||
expect(list.find('li:eq(1)')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:eq(2)')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'core:move-up'
|
||||
editorView.trigger 'core:move-up'
|
||||
|
||||
expect(list.find('li:eq(2)')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:eq(1)')).toHaveClass 'selected'
|
||||
@@ -100,43 +100,43 @@ describe "SelectListView", ->
|
||||
itemHeight = list.find('li').outerHeight()
|
||||
list.height(itemHeight * 2)
|
||||
|
||||
miniEditor.trigger 'core:move-down'
|
||||
miniEditor.trigger 'core:move-down'
|
||||
editorView.trigger 'core:move-down'
|
||||
editorView.trigger 'core:move-down'
|
||||
expect(list.scrollBottom()).toBe itemHeight * 3
|
||||
|
||||
miniEditor.trigger 'core:move-down'
|
||||
editorView.trigger 'core:move-down'
|
||||
expect(list.scrollBottom()).toBe itemHeight * 4
|
||||
|
||||
miniEditor.trigger 'core:move-up'
|
||||
miniEditor.trigger 'core:move-up'
|
||||
editorView.trigger 'core:move-up'
|
||||
editorView.trigger 'core:move-up'
|
||||
expect(list.scrollTop()).toBe itemHeight
|
||||
|
||||
describe "the core:confirm event", ->
|
||||
describe "when there is an item selected (because the list in not empty)", ->
|
||||
it "triggers the selected hook with the selected array element", ->
|
||||
miniEditor.trigger 'core:move-down'
|
||||
miniEditor.trigger 'core:move-down'
|
||||
miniEditor.trigger 'core:confirm'
|
||||
expect(selectList.confirmed).toHaveBeenCalledWith(array[2])
|
||||
editorView.trigger 'core:move-down'
|
||||
editorView.trigger 'core:move-down'
|
||||
editorView.trigger 'core:confirm'
|
||||
expect(selectList.confirmed).toHaveBeenCalledWith(items[2])
|
||||
|
||||
describe "when there is no item selected (because the list is empty)", ->
|
||||
beforeEach ->
|
||||
selectList.attachToDom()
|
||||
|
||||
it "does not trigger the confirmed hook", ->
|
||||
miniEditor.getEditor().insertText("i will never match anything")
|
||||
editorView.getEditor().insertText("i will never match anything")
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li')).not.toExist()
|
||||
miniEditor.trigger 'core:confirm'
|
||||
editorView.trigger 'core:confirm'
|
||||
expect(selectList.confirmed).not.toHaveBeenCalled()
|
||||
|
||||
it "does trigger the cancelled hook", ->
|
||||
miniEditor.getEditor().insertText("i will never match anything")
|
||||
editorView.getEditor().insertText("i will never match anything")
|
||||
window.advanceClock(selectList.inputThrottle)
|
||||
|
||||
expect(list.find('li')).not.toExist()
|
||||
miniEditor.trigger 'core:confirm'
|
||||
editorView.trigger 'core:confirm'
|
||||
expect(selectList.cancelled).toHaveBeenCalled()
|
||||
|
||||
describe "when a list item is clicked", ->
|
||||
@@ -147,12 +147,12 @@ describe "SelectListView", ->
|
||||
expect(item).toHaveClass 'selected'
|
||||
item.mouseup()
|
||||
|
||||
expect(selectList.confirmed).toHaveBeenCalledWith(array[1])
|
||||
expect(selectList.confirmed).toHaveBeenCalledWith(items[1])
|
||||
|
||||
describe "the core:cancel event", ->
|
||||
it "triggers the cancelled hook and detaches and empties the select list", ->
|
||||
spyOn(selectList, 'detach')
|
||||
miniEditor.trigger 'core:cancel'
|
||||
editorView.trigger 'core:cancel'
|
||||
expect(selectList.cancelled).toHaveBeenCalled()
|
||||
expect(selectList.detach).toHaveBeenCalled()
|
||||
expect(selectList.list).toBeEmpty()
|
||||
@@ -160,7 +160,7 @@ describe "SelectListView", ->
|
||||
describe "when the mini editor loses focus", ->
|
||||
it "triggers the cancelled hook and detaches the select list", ->
|
||||
spyOn(selectList, 'detach')
|
||||
miniEditor.hiddenInput.trigger 'focusout'
|
||||
editorView.hiddenInput.trigger 'focusout'
|
||||
expect(selectList.cancelled).toHaveBeenCalled()
|
||||
expect(selectList.detach).toHaveBeenCalled()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user