-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only use double quotes when interpolation is used
- Loading branch information
Showing
5 changed files
with
191 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,87 @@ | ||
describe "Basic setup", -> | ||
it "should add chosen to jQuery object", -> | ||
describe 'Basic setup', -> | ||
it 'should add chosen to jQuery object', -> | ||
expect(jQuery.fn.chosen).toBeDefined() | ||
|
||
it "should create very basic chosen", -> | ||
tmpl = " | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
it 'should create very basic chosen', -> | ||
tmpl = ''' | ||
<select data-placeholder="Choose a Country..."> | ||
<option value=""></option> | ||
<option value="United States">United States</option> | ||
<option value="United Kingdom">United Kingdom</option> | ||
<option value="Afghanistan">Afghanistan</option> | ||
</select> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
''' | ||
div = $('<div>').html(tmpl) | ||
select = div.find('select') | ||
expect(select.size()).toBe(1) | ||
select.chosen() | ||
# very simple check that the necessary elements have been created | ||
["container", "container-single", "single", "default"].forEach (clazz)-> | ||
['container', 'container-single', 'single', 'default'].forEach (clazz)-> | ||
el = div.find(".chosen-#{clazz}") | ||
expect(el.size()).toBe(1) | ||
|
||
# test a few interactions | ||
expect(select.val()).toBe "" | ||
expect(select.val()).toBe '' | ||
|
||
container = div.find(".chosen-container") | ||
container.trigger("mousedown") # open the drop | ||
expect(container.hasClass("chosen-container-active")).toBe true | ||
container = div.find('.chosen-container') | ||
container.trigger('mousedown') # open the drop | ||
expect(container.hasClass('chosen-container-active')).toBe true | ||
#select an item | ||
container.find(".active-result").last().trigger("mouseup") | ||
container.find('.active-result').last().trigger('mouseup') | ||
|
||
expect(select.val()).toBe "Afghanistan" | ||
expect(select.val()).toBe 'Afghanistan' | ||
|
||
describe "data-placeholder", -> | ||
describe 'data-placeholder', -> | ||
|
||
it "should render", -> | ||
tmpl = " | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
it 'should render', -> | ||
tmpl = ''' | ||
<select data-placeholder="Choose a Country..."> | ||
<option value=""></option> | ||
<option value="United States">United States</option> | ||
<option value="United Kingdom">United Kingdom</option> | ||
<option value="Afghanistan">Afghanistan</option> | ||
</select> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
''' | ||
div = $('<div>').html(tmpl) | ||
select = div.find('select') | ||
expect(select.size()).toBe(1) | ||
select.chosen() | ||
placeholder = div.find(".chosen-single > span") | ||
expect(placeholder.text()).toBe("Choose a Country...") | ||
placeholder = div.find('.chosen-single > span') | ||
expect(placeholder.text()).toBe('Choose a Country...') | ||
|
||
it "should render with special characters", -> | ||
tmpl = " | ||
<select data-placeholder='<None>'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
it 'should render with special characters', -> | ||
tmpl = ''' | ||
<select data-placeholder="<None>"> | ||
<option value=""></option> | ||
<option value="United States">United States</option> | ||
<option value="United Kingdom">United Kingdom</option> | ||
<option value="Afghanistan">Afghanistan</option> | ||
</select> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
''' | ||
div = $('<div>').html(tmpl) | ||
select = div.find('select') | ||
expect(select.size()).toBe(1) | ||
select.chosen() | ||
placeholder = div.find(".chosen-single > span") | ||
expect(placeholder.text()).toBe("<None>") | ||
placeholder = div.find('.chosen-single > span') | ||
expect(placeholder.text()).toBe('<None>') | ||
|
||
describe "disabled fieldset", -> | ||
describe 'disabled fieldset', -> | ||
|
||
it "should render as disabled", -> | ||
tmpl = " | ||
it 'should render as disabled', -> | ||
tmpl = ''' | ||
<fieldset disabled> | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
<select data-placeholder="Choose a Country..."> | ||
<option value=""></option> | ||
<option value="United States">United States</option> | ||
<option value="United Kingdom">United Kingdom</option> | ||
<option value="Afghanistan">Afghanistan</option> | ||
</select> | ||
</fieldset> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
''' | ||
div = $('<div>').html(tmpl) | ||
select = div.find('select') | ||
expect(select.size()).toBe(1) | ||
select.chosen() | ||
|
||
container = div.find(".chosen-container") | ||
expect(container.hasClass("chosen-disabled")).toBe true | ||
container = div.find('.chosen-container') | ||
expect(container.hasClass('chosen-disabled')).toBe true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
describe "Events", -> | ||
it "chosen should fire the right events", -> | ||
tmpl = " | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
describe 'Events', -> | ||
it 'chosen should fire the right events', -> | ||
tmpl = ''' | ||
<select data-placeholder="Choose a Country..."> | ||
<option value=""></option> | ||
<option value="United States">United States</option> | ||
<option value="United Kingdom">United Kingdom</option> | ||
<option value="Afghanistan">Afghanistan</option> | ||
</select> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
''' | ||
div = $('<div>').html(tmpl) | ||
select = div.find('select') | ||
expect(select.size()).toBe(1) | ||
select.chosen() | ||
# very simple check that the necessary elements have been created | ||
["container", "container-single", "single", "default"].forEach (clazz)-> | ||
['container', 'container-single', 'single', 'default'].forEach (clazz)-> | ||
el = div.find(".chosen-#{clazz}") | ||
expect(el.size()).toBe(1) | ||
|
||
# test a few interactions | ||
event_sequence = [] | ||
div.on 'input change', (evt) -> event_sequence.push evt.type | ||
|
||
container = div.find(".chosen-container") | ||
container.trigger("mousedown") # open the drop | ||
expect(container.hasClass("chosen-container-active")).toBe true | ||
container = div.find('.chosen-container') | ||
container.trigger('mousedown') # open the drop | ||
expect(container.hasClass('chosen-container-active')).toBe true | ||
#select an item | ||
container.find(".active-result").last().trigger("mouseup") | ||
container.find('.active-result').last().trigger('mouseup') | ||
|
||
expect(event_sequence).toEqual ['input', 'change'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
describe "search", -> | ||
it "should display only matching items when entering a search term", -> | ||
tmpl = " | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
</select> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
describe 'search', -> | ||
it 'should display only matching items when entering a search term', -> | ||
tmpl = ''' | ||
<select data-placeholder="Choose a Country..."> | ||
<option value=""></option> | ||
<option value="United States">United States</option> | ||
<option value="United Kingdom">United Kingdom</option> | ||
<option value="Afghanistan">Afghanistan</option> | ||
</select> | ||
''' | ||
div = $('<div>').html(tmpl) | ||
select = div.find('select') | ||
select.chosen() | ||
|
||
container = div.find(".chosen-container") | ||
container.trigger("mousedown") # open the drop | ||
container = div.find('.chosen-container') | ||
container.trigger('mousedown') # open the drop | ||
# Expect all results to be shown | ||
results = div.find(".active-result") | ||
results = div.find('.active-result') | ||
expect(results.size()).toBe(3) | ||
|
||
# Enter some text in the search field. | ||
search_field = div.find(".chosen-search input").first() | ||
search_field.val("Afgh") | ||
search_field = div.find('.chosen-search input').first() | ||
search_field.val('Afgh') | ||
search_field.trigger('keyup') | ||
|
||
# Expect to only have one result: 'Afghanistan'. | ||
results = div.find(".active-result") | ||
results = div.find('.active-result') | ||
expect(results.size()).toBe(1) | ||
expect(results.first().text()).toBe "Afghanistan" | ||
expect(results.first().text()).toBe 'Afghanistan' | ||
|
||
it "should only show max_shown_results items in results", -> | ||
tmpl = " | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
</select> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
it 'should only show max_shown_results items in results', -> | ||
tmpl = ''' | ||
<select data-placeholder="Choose a Country..."> | ||
<option value=""></option> | ||
<option value="United States">United States</option> | ||
<option value="United Kingdom">United Kingdom</option> | ||
<option value="Afghanistan">Afghanistan</option> | ||
</select> | ||
''' | ||
div = $('<div>').html(tmpl) | ||
select = div.find('select') | ||
select.chosen({max_shown_results: 1 }) | ||
|
||
container = div.find(".chosen-container") | ||
container.trigger("mousedown") # open the drop | ||
results = div.find(".active-result") | ||
container = div.find('.chosen-container') | ||
container.trigger('mousedown') # open the drop | ||
results = div.find('.active-result') | ||
expect(results.size()).toBe(1) | ||
|
||
# Enter some text in the search field. | ||
search_field = div.find(".chosen-search input").first() | ||
search_field.val("United") | ||
search_field.trigger("keyup") | ||
search_field = div.find('.chosen-search input').first() | ||
search_field.val('United') | ||
search_field.trigger('keyup') | ||
|
||
# Showing only one result: the one that occurs first. | ||
results = div.find(".active-result") | ||
results = div.find('.active-result') | ||
expect(results.size()).toBe(1) | ||
expect(results.first().text()).toBe "United States" | ||
expect(results.first().text()).toBe 'United States' | ||
|
||
# Showing still only one result, but not the first one. | ||
search_field.val("United Ki") | ||
search_field.trigger("keyup") | ||
results = div.find(".active-result") | ||
search_field.val('United Ki') | ||
search_field.trigger('keyup') | ||
results = div.find('.active-result') | ||
expect(results.size()).toBe(1) | ||
expect(results.first().text()).toBe "United Kingdom" | ||
expect(results.first().text()).toBe 'United Kingdom' |
Oops, something went wrong.