Skip to content

Instantly share code, notes, and snippets.

@davidpadbury
Created March 3, 2011 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidpadbury/852722 to your computer and use it in GitHub Desktop.
Save davidpadbury/852722 to your computer and use it in GitHub Desktop.
(function ($) {
module('Details Pane', {
setup: function () {
this.details = $('<div id="details-pane"><div /></div>')
.appendTo('#qunit-fixture');
this.ajax = $.ajax;
this.savedGet = mstats.datastore.get;
this.savedFetch = mstats.dataManager.fetch;
$.ajax = function (options) {
options.success = function () { }; // to prevent the actual call
};
},
teardown: function () {
$.ajax = this.ajax;
mstats.datastore.get = this.savedGet;
mstats.dataManager.fetch = this.savedFetch;
}
});
test('When details.selected fires, then attempt to load template from $.datastore', function () {
expect(1);
var definedToken = 'vehicle.details.html',
vid = 4;
mstats.datastore.get = function (token) {
if (token == definedToken) {
equal(token, definedToken, 'Details Pane is loading template when details.selected fires');
}
};
this.details.detailsPane();
mstats.pubsub.publish('details.selected', vid);
this.details.detailsPane('destroy');
});
test('When details.selected fires and template is not in $.datastore, then fetch template from server', function () {
expect(3);
var definedToken = 'vehicle.details.html',
definedFormat = 'html',
vid = 44;
mstats.datastore.get = function (token) {
if (token == definedToken) {
return undefined;
}
};
mstats.dataManager.fetch = function (endpoint, format) {
if (format == definedFormat) {
ok(true, 'Details Pane is fetching data when details.selected fires and $.datastore is empty');
equal(endpoint, 'vehicle/details/' + vid, 'Details Pane is formating the fetch url correctly');
equal(format, definedFormat, 'Details Pane is fetching from server when not cached ');
}
};
this.details.detailsPane();
mstats.pubsub.publish('details.selected', vid);
this.details.detailsPane('destroy');
});
} (jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment