Skip to content

Commit

Permalink
only use double quotes when interpolation is used
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Nov 27, 2016
1 parent 1644b22 commit 7557c1e
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 192 deletions.
114 changes: 57 additions & 57 deletions spec/jquery/basic.spec.coffee
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='&lt;None&gt;'>
<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="&lt;None&gt;">
<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
32 changes: 16 additions & 16 deletions spec/jquery/events.spec.coffee
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']
84 changes: 42 additions & 42 deletions spec/jquery/max_shown_results.spec.coffee
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'
Loading

0 comments on commit 7557c1e

Please sign in to comment.