Permalink
Browse files

Added testing of append [and fixed errors]

  • Loading branch information...
1 parent c89d837 commit 3f3f95c46b5a9af7e8866369be9f43bd0590bccc @ratnikov ratnikov committed Feb 27, 2009
Showing with 27 additions and 7 deletions.
  1. +1 −1 src/errors.js
  2. +26 −6 test/errors_test.js
View
@@ -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) {
View
@@ -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", {
@@ -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();
@@ -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.