-
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.
Merge pull request #2287 from harvesthq/jasmine-tests-on-ci
Jasmine tests on ci
- Loading branch information
Showing
6 changed files
with
159 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -9,3 +9,5 @@ chosen.zip | |
.ruby-version | ||
.rbenv-gemsets | ||
.grunt | ||
_SpecRunner.html | ||
spec/public |
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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Event.simulate(@element, eventName[, options]) -> Element | ||
* | ||
* - @element: element to fire event on | ||
* - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported) | ||
* - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc. | ||
* | ||
* $('foo').simulate('click'); // => fires "click" event on an element with id=foo | ||
* | ||
**/ | ||
(function(){ | ||
|
||
var eventMatchers = { | ||
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/, | ||
'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/ | ||
} | ||
var defaultOptions = { | ||
pointerX: 0, | ||
pointerY: 0, | ||
button: 0, | ||
ctrlKey: false, | ||
altKey: false, | ||
shiftKey: false, | ||
metaKey: false, | ||
bubbles: true, | ||
cancelable: true | ||
} | ||
|
||
Event.simulate = function(element, eventName) { | ||
var options = Object.extend(Object.clone(defaultOptions), arguments[2] || { }); | ||
var oEvent, eventType = null; | ||
|
||
element = $(element); | ||
|
||
for (var name in eventMatchers) { | ||
if (eventMatchers[name].test(eventName)) { eventType = name; break; } | ||
} | ||
|
||
if (!eventType) | ||
throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported'); | ||
|
||
if (document.createEvent) { | ||
oEvent = document.createEvent(eventType); | ||
if (eventType == 'HTMLEvents') { | ||
oEvent.initEvent(eventName, options.bubbles, options.cancelable); | ||
} | ||
else { | ||
oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView, | ||
options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY, | ||
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element); | ||
} | ||
element.dispatchEvent(oEvent); | ||
} | ||
else { | ||
options.clientX = options.pointerX; | ||
options.clientY = options.pointerY; | ||
oEvent = Object.extend(document.createEventObject(), options); | ||
element.fireEvent('on' + eventName, oEvent); | ||
} | ||
return element; | ||
} | ||
|
||
Element.addMethods({ simulate: Event.simulate }); | ||
})(); |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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.size()).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.size()).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" | ||
|
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
describe "Basic setup", -> | ||
it "should add expose a Chosen global", -> | ||
expect(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 = new Element("div") | ||
document.body.insert(div) | ||
div.update(tmpl) | ||
select = div.down("select") | ||
expect(select).toBeDefined() | ||
new Chosen(select) | ||
# very simple check that the necessary elements have been created | ||
["container", "container-single", "single", "default"].forEach (clazz)-> | ||
el = div.down(".chosen-#{clazz}") | ||
expect(el).toBeDefined() | ||
|
||
# test a few interactions | ||
expect($F(select)).toBe "" | ||
|
||
container = div.down(".chosen-container") | ||
container.simulate("mousedown") # open the drop | ||
expect(container.hasClassName("chosen-container-active")).toBe true | ||
|
||
#select an item | ||
container.select(".active-result").last().simulate("mouseup") | ||
|
||
expect($F(select)).toBe "Afghanistan" | ||
div.remove() |