Apparently are not working properly and/or not documented
properly
describe '.loc-link'
before
window.XMLHttpRequest = JSpec.XHR;
runLivequeries = function() {
if ($.livequery) {
queries = $.livequery.queries;
for (var i = 0; i < queries.length; i++) {
queries[i].run();
}
}
};
$.ajaxSettings.async = false;
$.fx.off = true;
$.fn.fireEvent = function(event, obj) {
return this.each(function() {
runLivequeries();
var basic = {type: event, target: this, preventDefault: true};
$.extend(basic, obj || {});
$(this).trigger(event, [basic]);
});
};
end
before_each
$('#dom').empty();
end
before
tested = 'loc-link'
dom = $('#dom');
end
before_each
button = $("<div class='"+tested+"'
href='http://wut.com'>hi</div>");
mainpane = $("<div id='main-pane'></div>");
ajaxLoader = $("<div class='ajax-loader' style='visibility:
hidden;'></div>");
mainpane.append(ajaxLoader);
dom
.append(button);
.append(mainpane);
end
describe '#click'
before_each
ajaxLoader.css('visibility', 'hidden');
success = 'foobar!'
end
it "shows the ajax loader"
JSpec.XHR.returns(success);
jQuery(ajaxLoader).css('visibility').should.be 'hidden'
button.click();
jQuery(ajaxLoader).css('visibility').should.be 'visible'
end
it "makes an ajax request to the element's href attr"
button.click();
JSpec.XHR.url.should.equal button.attr('href')
end
describe "success"
before_each
JSpec.XHR.returns(success);
updateChar_called = false
old_updateChar = Relife.updateChar
Relife.updateChar = function() {
updateChar_called = true;
};
end
after_each
Relife.updateChar = old_updateChar
end
it "replaces the #main-pane with the results of the request"
button.click();
mainpane.text().should.equal success
end
it "calls Relife.updateChar()"
Relife.should.receive('updateChar')
button.click();
end
it "should not call Relife.updateChar if the no-char-reload
class is on it"
button.addClass('no-char-reload');
updateChar_called.should.be false
button.click();
updateChar_called.should.be false
end
end
describe "error"
before_each
stub(Relife, 'showError')
ajaxLoader.css('visibility', 'visible');
JSpec.XHR.returns('', 'application/json', 500);
end
it "should hide the ajax loader"
button.click();
ajaxLoader.css('visibility').should.equal 'hidden'
end
it "should call Relife.showError"
Relife.should.receive('showError')
button.click();
end
end
end
describe ".choice-adventure"
before
tested = 'choice-adventure'
end
should_behave_like('.loc-link')
end
end