mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Start on SelectList, a common base class for filterable lists
Like autocompleter, fuzzy-finder, and event palette
This commit is contained in:
committed by
Nathan Sobo
parent
389552c057
commit
a3f25fbc9b
69
spec/extensions/select-list-spec.coffee
Normal file
69
spec/extensions/select-list-spec.coffee
Normal file
@@ -0,0 +1,69 @@
|
||||
SelectList = require 'select-list'
|
||||
{$$} = require 'space-pen'
|
||||
$ = require 'jquery'
|
||||
|
||||
fdescribe "SelectList", ->
|
||||
[selectList, array, list, miniEditor] = []
|
||||
|
||||
beforeEach ->
|
||||
array = [
|
||||
["A", "Alpha"], ["B", "Bravo"], ["C", "Charlie"],
|
||||
["D", "Delta"], ["E", "Echo"], ["F", "Foxtrot"]
|
||||
]
|
||||
|
||||
selectList = new SelectList
|
||||
selectList.maxItems = 4
|
||||
selectList.filterKey = 1
|
||||
selectList.itemForElement = (element) ->
|
||||
$$ -> @li element[1], class: element[0]
|
||||
|
||||
selectList.setArray(array)
|
||||
{list, miniEditor} = selectList
|
||||
|
||||
describe "when an array is assigned", ->
|
||||
it "populates the list with up to maxItems items, based on the liForElement function", ->
|
||||
expect(list.find('li').length).toBe selectList.maxItems
|
||||
expect(list.find('li:eq(0)')).toHaveText 'Alpha'
|
||||
expect(list.find('li:eq(0)')).toHaveClass 'A'
|
||||
|
||||
describe "when the text of the mini editor changes", ->
|
||||
it "filters the elements in the list based on the scoreElement function", ->
|
||||
miniEditor.insertText('la')
|
||||
expect(list.find('li').length).toBe 2
|
||||
expect(list.find('li:contains(Alpha)')).toExist()
|
||||
expect(list.find('li:contains(Delta)')).toExist()
|
||||
|
||||
describe "when move-up / move-down are triggered on the miniEditor", ->
|
||||
it "selects the previous / next item in the list, if there is one", ->
|
||||
expect(list.find('li:first')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'move-up'
|
||||
|
||||
expect(list.find('li:first')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'move-down'
|
||||
|
||||
expect(list.find('li:eq(0)')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:eq(1)')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'move-down'
|
||||
|
||||
expect(list.find('li:eq(1)')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:eq(2)')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'move-up'
|
||||
|
||||
expect(list.find('li:eq(2)')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:eq(1)')).toHaveClass 'selected'
|
||||
|
||||
describe "the core:select event", ->
|
||||
it "triggers the selected hook", ->
|
||||
|
||||
describe "the core:cancel event", ->
|
||||
it "triggers the cancelled hook", ->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -49,8 +49,6 @@ describe 'jQuery extensions', ->
|
||||
@div id: 'c'
|
||||
@div id: 'd'
|
||||
|
||||
view.document 'A1'
|
||||
|
||||
view.document
|
||||
'a1': "This is event A2"
|
||||
'b2': "This is event b2"
|
||||
@@ -76,4 +74,4 @@ describe 'jQuery extensions', ->
|
||||
['b2', "B2: Looks evil. Kinda is."],
|
||||
['a1', "A1: Waste perfectly-good steak"],
|
||||
['a2']
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user