1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
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>
</select>
"
div = $("<div>").html(tmpl)
select = div.find("select")
expect(select.length).toBe(1)
select.chosen()
# very simple check that the necessary elements have been created
["container", "container-single", "single", "default"].forEach (clazz)->
el = div.find(".chosen-#{clazz}")
expect(el.length).toBe(1)
# test a few interactions
expect(select.val()).toBe ""
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")
expect(select.val()).toBe "Afghanistan"
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>
</select>
"
div = $("<div>").html(tmpl)
select = div.find("select")
expect(select.length).toBe(1)
select.chosen()
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>
</select>
"
div = $("<div>").html(tmpl)
select = div.find("select")
expect(select.length).toBe(1)
select.chosen()
placeholder = div.find(".chosen-single > span")
expect(placeholder.text()).toBe("<None>")
describe "disabled fieldset", ->
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>
</fieldset>
"
div = $("<div>").html(tmpl)
select = div.find("select")
expect(select.length).toBe(1)
select.chosen()
container = div.find(".chosen-container")
expect(container.hasClass("chosen-disabled")).toBe true
|