mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Backfill specs for SelectList
This commit is contained in:
@@ -30,12 +30,28 @@ describe "SelectList", ->
|
||||
expect(list.find('li:eq(0)')).toHaveClass 'A'
|
||||
|
||||
describe "when the text of the mini editor changes", ->
|
||||
beforeEach ->
|
||||
selectList.attachToDom()
|
||||
|
||||
it "filters the elements in the list based on the scoreElement function and selects the first item", ->
|
||||
miniEditor.insertText('la')
|
||||
expect(list.find('li').length).toBe 2
|
||||
expect(list.find('li:contains(Alpha)')).toExist()
|
||||
expect(list.find('li:contains(Delta)')).toExist()
|
||||
expect(list.find('li:first')).toHaveClass 'selected'
|
||||
expect(selectList.error).not.toBeVisible()
|
||||
expect(selectList).not.toHaveClass("error")
|
||||
|
||||
it "displays an error if there are no matches, removes error when there are matches", ->
|
||||
miniEditor.insertText('nothing will match this')
|
||||
expect(list.find('li').length).toBe 0
|
||||
expect(selectList.error).not.toBeHidden()
|
||||
expect(selectList).toHaveClass("error")
|
||||
|
||||
miniEditor.setText('la')
|
||||
expect(list.find('li').length).toBe 2
|
||||
expect(selectList.error).not.toBeVisible()
|
||||
expect(selectList).not.toHaveClass("error")
|
||||
|
||||
describe "when core:move-up / core:move-down are triggered on the miniEditor", ->
|
||||
it "selects the previous / next item in the list, or wraps around to the other side", ->
|
||||
|
||||
@@ -40,9 +40,14 @@ class SelectList extends View
|
||||
@selectItem(@list.find('li:first'))
|
||||
|
||||
setError: (message) ->
|
||||
@error.text(message)
|
||||
@error.show()
|
||||
@addClass("error")
|
||||
if not message or message.length == ""
|
||||
@error.text("")
|
||||
@error.hide()
|
||||
@removeClass("error")
|
||||
else
|
||||
@error.text(message)
|
||||
@error.show()
|
||||
@addClass("error")
|
||||
|
||||
populateList: ->
|
||||
filterQuery = @miniEditor.getText()
|
||||
@@ -51,10 +56,10 @@ class SelectList extends View
|
||||
else
|
||||
filteredArray = @array
|
||||
|
||||
@error.hide()
|
||||
@removeClass("error")
|
||||
@list.empty()
|
||||
if filteredArray.length
|
||||
@setError(null)
|
||||
|
||||
for i in [0...Math.min(filteredArray.length, @maxItems)]
|
||||
element = filteredArray[i]
|
||||
item = @itemForElement(element)
|
||||
|
||||
Reference in New Issue
Block a user