Skip to content

Commit

Permalink
Added testing of append [and fixed errors]
Browse files Browse the repository at this point in the history
  • Loading branch information
ratnikov committed Feb 27, 2009
1 parent c89d837 commit 3f3f95c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/errors.js
Expand Up @@ -11,7 +11,7 @@ AjaxResource.Errors.prototype.ul = function() {
return this.error_div().find("ul");
};

AjaxResource.Errors.prototype.append = function(error) {
AjaxResource.Errors.prototype.append = function(errors) {
var self = this;
jQuery.each(errors, function() {
if (this.length == 2) {
Expand Down
32 changes: 26 additions & 6 deletions test/errors_test.js
@@ -1,26 +1,28 @@

jQuery(document).ready(function() {
var inner_errors = null;

test("Truthitest", function() {
ok(true);
});

module("Init");
test("Should recognize error div correctly", function() {
inner_errors = new AjaxResource.Errors('#inner-div');
var inner_errors = new AjaxResource.Errors('#inner-div');
same(inner_errors.error_div().get(), jQuery("#inner-error-div").get(), "Should return only the inner div");

main_errors = new AjaxResource.Errors('#main');
var main_errors = new AjaxResource.Errors('#main');
same(main_errors.error_div().get(), jQuery("#main-error-div, #inner-error-div").get(), "Should return both error divs");

all_errors = new AjaxResource.Errors(document);
var all_errors = new AjaxResource.Errors(document);
same(all_errors.error_div().get(), jQuery("div.error").get(), "Should match all error divs on the page.");
});

module("#ul");
test("Should return ul within the error div", function() {
var inner_ul = (new AjaxResource.Errors('#inner-div')).ul();
matches_only(inner_ul, '#inner-ul', "Should include the inner ul");
matches_only((new AjaxResource.Errors('#main')).ul(), [ '#inner-ul', '#main-ul', ], "Should include both inner and main uls");
matches_only((new AjaxResource.Errors('#main')).ul(), [ '#inner-ul', '#main-ul' ], "Should include both inner and main uls");
});

module("UI effects", {
Expand All @@ -29,8 +31,6 @@ jQuery(document).ready(function() {
}
});

var inner_errors = null;

test("#hide and #show should hide and show the error div", function() {
ok(inner_errors.error_div().is(":visible"), "Error div should be visible at beginning of test");
inner_errors.hide();
Expand All @@ -39,4 +39,24 @@ jQuery(document).ready(function() {
inner_errors.show();
ok(inner_errors.error_div().is(":visible"), "Error div should become visible after #show is invoked");
});

module("#append", {
setup : function() {
inner_errors = new AjaxResource.Errors('#inner-div');
}
});

test("append messages to the ul with li tags", function() {
var appended = [];
inner_errors.ul = function() {
return {
append: function(content) {
appended.push(content);
}
};
};

inner_errors.append([ [ "foo", "is awesome" ], [ "base", "bar is bad" ] ]);
same(appended, [ "<li>foo is awesome</li>", "<li>bar is bad</li>" ], "Should parse errors and embedd the messages in <li> tags");
});
});

0 comments on commit 3f3f95c

Please sign in to comment.