From 61aecfa58fead90d76a577e8a83cfb59950f6af7 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 16 Nov 2012 11:34:52 -0800 Subject: [PATCH] Backfill specs for SelectList --- spec/app/select-list-spec.coffee | 16 ++++++++++++++++ src/app/select-list.coffee | 15 ++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/spec/app/select-list-spec.coffee b/spec/app/select-list-spec.coffee index 49001c30a..5bcec040f 100644 --- a/spec/app/select-list-spec.coffee +++ b/spec/app/select-list-spec.coffee @@ -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", -> diff --git a/src/app/select-list.coffee b/src/app/select-list.coffee index 7cf86066c..4e81b2589 100644 --- a/src/app/select-list.coffee +++ b/src/app/select-list.coffee @@ -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)