Skip to content

Commit

Permalink
Test: Fix misuse of equal method & some spacing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkni committed Sep 25, 2015
1 parent 4df6cb8 commit 842e7ff
Show file tree
Hide file tree
Showing 6 changed files with 1,337 additions and 1,334 deletions.
96 changes: 48 additions & 48 deletions test/aria.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
module("aria");
module( "aria" );

test("Invalid field adds aria-invalid=true", function() {
var ariaInvalidFirstName = $("#ariaInvalidFirstName"),
form = $("#ariaInvalid");
test( "Invalid field adds aria-invalid=true", function() {
var ariaInvalidFirstName = $( "#ariaInvalidFirstName" ),
form = $( "#ariaInvalid" );

form.validate({
form.validate( {
rules: {
ariaInvalidFirstName: "required"
}
});
ariaInvalidFirstName.val("");
} );
ariaInvalidFirstName.val( "" );
ariaInvalidFirstName.valid();
equal(ariaInvalidFirstName.attr("aria-invalid"), "true");
});
equal( ariaInvalidFirstName.attr( "aria-invalid" ), "true" );
} );

test("Valid field adds aria-invalid=false", function() {
var ariaInvalidFirstName = $("#ariaInvalidFirstName"),
form = $("#ariaInvalid");
test( "Valid field adds aria-invalid=false", function() {
var ariaInvalidFirstName = $( "#ariaInvalidFirstName" ),
form = $( "#ariaInvalid" );

form.validate({
form.validate( {
rules: {
ariaInvalidFirstName: "required"
}
});
ariaInvalidFirstName.val("not empty");
} );
ariaInvalidFirstName.val( "not empty" );
ariaInvalidFirstName.valid();
equal(ariaInvalidFirstName.attr("aria-invalid"), "false");
equal($("#ariaInvalid [aria-invalid=false]").length, 1);
});
equal( ariaInvalidFirstName.attr( "aria-invalid" ), "false" );
equal( $( "#ariaInvalid [aria-invalid=false]" ).length, 1 );
} );

test("resetForm(): removes all aria-invalid attributes", function() {
var ariaInvalidFirstName = $("#ariaInvalidFirstName"),
form = $("#ariaInvalid"),
validator = form.validate({
test( "resetForm(): removes all aria-invalid attributes", function() {
var ariaInvalidFirstName = $( "#ariaInvalidFirstName" ),
form = $( "#ariaInvalid" ),
validator = form.validate( {
rules: {
ariaInvalidFirstName: "required"
}
});
} );

ariaInvalidFirstName.val("not empty");
ariaInvalidFirstName.val( "not empty" );
ariaInvalidFirstName.valid();
validator.resetForm();
equal($("#ariaInvalid [aria-invalid]").length, 0, "resetForm() should remove any aria-invalid attributes");
});
equal( $( "#ariaInvalid [aria-invalid]" ).length, 0, "resetForm() should remove any aria-invalid attributes" );
} );

test("Static required field adds aria-required", function() {
var ariaRequiredStatic = $("#ariaRequiredStatic"),
form = $("#ariaRequired");
test( "Static required field adds aria-required", function() {
var ariaRequiredStatic = $( "#ariaRequiredStatic" ),
form = $( "#ariaRequired" );

form.validate();
equal(ariaRequiredStatic.attr("aria-required"), "true");
});
equal( ariaRequiredStatic.attr( "aria-required" ), "true" );
} );

test("Data required field adds aria-required", function() {
var ariaRequiredData = $("#ariaRequiredData"),
form = $("#ariaRequired");
test( "Data required field adds aria-required", function() {
var ariaRequiredData = $( "#ariaRequiredData" ),
form = $( "#ariaRequired" );

form.validate();
equal(ariaRequiredData.attr("aria-required"), "true");
});
equal( ariaRequiredData.attr( "aria-required" ), "true" );
} );

test("Class required field adds aria-required", function() {
var ariaRequiredClass = $("#ariaRequiredClass"),
form = $("#ariaRequired");
test( "Class required field adds aria-required", function() {
var ariaRequiredClass = $( "#ariaRequiredClass" ),
form = $( "#ariaRequired" );

form.validate();
equal(ariaRequiredClass.attr("aria-required"), "true");
});
equal( ariaRequiredClass.attr( "aria-required" ), "true" );
} );

test("Dynamically required field adds aria-required after valid()", function() {
var ariaRequiredDynamic = $("#ariaRequiredDynamic"),
form = $("#ariaRequired");
test( "Dynamically required field adds aria-required after valid()", function() {
var ariaRequiredDynamic = $( "#ariaRequiredDynamic" ),
form = $( "#ariaRequired" );

form.resetForm();
form.validate({
form.validate( {
rules: {
ariaRequiredDynamic: "required"
}
});
} );
ariaRequiredDynamic.valid();
equal(ariaRequiredDynamic.attr("aria-required"), "true");
});
equal( ariaRequiredDynamic.attr( "aria-required" ), "true" );
} );
60 changes: 30 additions & 30 deletions test/error-placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ test( "error containers, simple", function() {

v.prepareForm();
ok( v.valid(), "form is valid" );
equal( 0, container.find( ".error:not(input)" ).length, "There should be no error labels" );
equal( "", container.find( "h3" ).html() );
equal( container.find( ".error:not(input)" ).length, 0, "There should be no error labels" );
equal( container.find( "h3" ).html(), "" );

v.prepareForm();
v.errorList = [
Expand All @@ -78,7 +78,7 @@ test( "error containers, simple", function() {
container.find( ".error:not(input)" ).each(function() {
ok( $( this ).is( ":visible" ), "Check that each label is visible" );
});
equal( "There are 2 errors in your form.", container.find( "h3" ).html() );
equal( container.find( "h3" ).html(), "There are 2 errors in your form." );

v.prepareForm();
ok( v.valid(), "form is valid after a reset" );
Expand All @@ -101,9 +101,9 @@ test( "error containers, with labelcontainer I", function() {
});

ok( v.valid(), "form is valid" );
equal( 0, container.find( ".error:not(input)" ).length, "There should be no error labels in the container" );
equal( 0, labelcontainer.find( ".error:not(input)" ).length, "There should be no error labels in the labelcontainer" );
equal( 0, labelcontainer.find( "li" ).length, "There should be no lis labels in the labelcontainer" );
equal( container.find( ".error:not(input)" ).length, 0, "There should be no error labels in the container" );
equal( labelcontainer.find( ".error:not(input)" ).length, 0, "There should be no error labels in the labelcontainer" );
equal( labelcontainer.find( "li" ).length, 0, "There should be no lis labels in the labelcontainer" );

v.errorList = [
{
Expand All @@ -123,14 +123,14 @@ test( "error containers, with labelcontainer I", function() {

ok( !v.valid(), "form is not valid after adding errors manually" );
v.showErrors();
equal( 0, container.find( ".error:not(input)" ).length, "There should be no error label in the container" );
equal( 2, labelcontainer.find( ".error:not(input)" ).length, "There should be two error labels in the labelcontainer" );
equal( 2, labelcontainer.find( "li" ).length, "There should be two error lis in the labelcontainer" );
equal( container.find( ".error:not(input)" ).length, 0, "There should be no error label in the container" );
equal( labelcontainer.find( ".error:not(input)" ).length, 2, "There should be two error labels in the labelcontainer" );
equal( labelcontainer.find( "li" ).length, 2, "There should be two error lis in the labelcontainer" );
ok( container.is( ":visible" ), "Check that the container is visible" );
ok( labelcontainer.is( ":visible" ), "Check that the labelcontainer is visible" );
labelcontainer.find( ".error:not(input)" ).each(function() {
ok( $( this ).is( ":visible" ), "Check that each label is visible1" );
equal( "li", $( this ).parent()[0].tagName.toLowerCase(), "Check that each label is wrapped in an li" );
equal( $( this ).parent()[0].tagName.toLowerCase(), "li", "Check that each label is wrapped in an li" );
ok( $( this ).parent( "li" ).is( ":visible" ), "Check that each parent li is visible" );
});
});
Expand All @@ -151,13 +151,13 @@ test( "errorcontainer, show/hide only on submit", function() {
}
});

equal( "", container.html(), "must be empty" );
equal( "", labelContainer.html(), "must be empty" );
equal( container.html(), "", "must be empty" );
equal( labelContainer.html(), "", "must be empty" );
// validate whole form, both showErrors and invalidHandler must be called once
// preferably invalidHandler first, showErrors second
ok( !v.form(), "invalid form" );
equal( 2, labelContainer.find( ".error:not(input)" ).length );
equal( "There are 2 errors in your form.", container.html() );
equal( labelContainer.find( ".error:not(input)" ).length, 2 );
equal( container.html(), "There are 2 errors in your form." );
ok( labelContainer.is( ":visible" ), "must be visible" );
ok( container.is( ":visible" ), "must be visible" );

Expand All @@ -168,8 +168,8 @@ test( "errorcontainer, show/hide only on submit", function() {
target: $( "#firstname" )[ 0 ]
})
]);
equal( 1, labelContainer.find( ".error:visible" ).length );
equal( "There are 1 errors in your form.", container.html() );
equal( labelContainer.find( ".error:visible" ).length, 1 );
equal( container.html(), "There are 1 errors in your form." );

$( "#lastname" ).val( "abc" );
ok( v.form(), "Form now valid, trigger showErrors but not invalid-form" );
Expand All @@ -189,13 +189,13 @@ test( "test label used as error container", function(assert) {
});

ok( !field.valid() );
equal( "Field Label", field.next( "label" ).contents().first().text(), "container label isn't disrupted" );
equal( field.next( "label" ).contents().first().text(), "Field Label", "container label isn't disrupted" );
assert.hasError(field, "missing");
ok( !field.attr( "aria-describedby" ), "field does not require aria-describedby attribute" );

field.val( "foo" );
ok( field.valid() );
equal( "Field Label", field.next( "label" ).contents().first().text(), "container label isn't disrupted" );
equal( field.next( "label" ).contents().first().text(), "Field Label", "container label isn't disrupted" );
ok( !field.attr( "aria-describedby" ), "field does not require aria-describedby attribute" );
assert.noErrorFor(field);
});
Expand All @@ -210,14 +210,14 @@ test( "test error placed adjacent to descriptive label", function(assert) {
});

ok( !field.valid() );
equal( 1, form.find( "label" ).length );
equal( "Field Label", form.find( "label" ).text(), "container label isn't disrupted" );
equal( form.find( "label" ).length, 1 );
equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" );
assert.hasError( field, "missing" );

field.val( "foo" );
ok( field.valid() );
equal( 1, form.find( "label" ).length );
equal( "Field Label", form.find( "label" ).text(), "container label isn't disrupted" );
equal( form.find( "label" ).length, 1 );
equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" );
assert.noErrorFor( field );
});

Expand All @@ -231,14 +231,14 @@ test( "test descriptive label used alongside error label", function(assert) {
});

ok( !field.valid() );
equal( 1, form.find( "label.title" ).length );
equal( "Field Label", form.find( "label.title" ).text(), "container label isn't disrupted" );
equal( form.find( "label.title" ).length, 1 );
equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" );
assert.hasError( field, "missing" );

field.val( "foo" );
ok( field.valid() );
equal( 1, form.find( "label.title" ).length );
equal( "Field Label", form.find( "label.title" ).text(), "container label isn't disrupted" );
equal( form.find( "label.title" ).length, 1 );
equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" );
assert.noErrorFor( field );
});

Expand Down Expand Up @@ -307,8 +307,8 @@ test( "test existing non-error aria-describedby", function( assert ) {
ok( field.valid() );
assert.noErrorFor( field );

strictEqual( "This is where you enter your data", $("#testForm17text-description").text() );
strictEqual( "", $("#testForm17text-error").text(), "Error label is empty for valid field" );
strictEqual( $("#testForm17text-description").text(), "This is where you enter your data" );
strictEqual( $("#testForm17text-error").text(), "", "Error label is empty for valid field" );
});

test( "test pre-assigned non-error aria-describedby", function( assert ) {
Expand All @@ -328,8 +328,8 @@ test( "test pre-assigned non-error aria-describedby", function( assert ) {
ok( field.valid() );
assert.noErrorFor( field );

strictEqual( "This is where you enter your data", $("#testForm17text-description").text() );
strictEqual( "", $("#testForm17text-error").text(), "Error label is empty for valid field" );
strictEqual( $("#testForm17text-description").text(), "This is where you enter your data" );
strictEqual( $("#testForm17text-error").text(), "", "Error label is empty for valid field" );
});

test( "test id/name containing brackets", function( assert ) {
Expand Down
Loading

0 comments on commit 842e7ff

Please sign in to comment.