Skip to content

Commit

Permalink
Add regression tests for the HTML entity bug
Browse files Browse the repository at this point in the history
This is the minimal reproducible test-case for this bug.

There's one test for each flavor of chosen, and I've confirmed that this
does, indeed, fail on master.
  • Loading branch information
Arun Srinivasan committed Aug 22, 2017
1 parent 5940e3b commit d4715b1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/jquery/searching.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe "Searching", ->
it "should not match the actual text of HTML entities", ->
tmpl = "
<select data-placeholder='Choose an HTML Entity...'>
<option value=''></option>
<option value='This & That'>This &amp; That</option>
<option value='This < That'>This &lt; That</option>
</select>
"

div = $("<div>").html(tmpl)
select = div.find("select")
select.chosen({search_contains: true})

container = div.find(".chosen-container")
container.trigger("mousedown") # open the drop

# Both options should be active
results = div.find(".active-result")
expect(results.size()).toBe(2)

# Search for the html entity by name
search_field = div.find(".chosen-search input").first()
search_field.val("mp")
search_field.trigger("keyup")

results = div.find(".active-result")
expect(results.size()).toBe(0)
30 changes: 30 additions & 0 deletions spec/proto/searching.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe "Searching", ->
it "should not match the actual text of HTML entities", ->
tmpl = "
<select data-placeholder='Choose an HTML Entity...'>
<option value=''></option>
<option value='This & That'>This &amp; That</option>
<option value='This < That'>This &lt; That</option>
</select>
"

div = new Element('div')
document.body.insert(div)
div.update(tmpl)
select = div.down('select')
new Chosen(select, {search_contains: true})

container = div.down('.chosen-container')
simulant.fire(container, 'mousedown') # open the drop

# Both options should be active
results = div.select('.active-result')
expect(results.length).toBe(2)

# Search for the html entity by name
search_field = div.down(".chosen-search input")
search_field.value = "mp"
simulant.fire(search_field, 'keyup')

results = div.select(".active-result")
expect(results.length).toBe(0)

0 comments on commit d4715b1

Please sign in to comment.