Tests: Upgrade QUnit to 2.0.

Closes #1777. #1681.
This commit is contained in:
Brahim Arkni
2016-05-05 14:29:37 +01:00
committed by Markus Staab
parent 0d3ede1398
commit 8fe4a90185
13 changed files with 1583 additions and 5708 deletions

View File

@@ -1,13 +1,13 @@
module( "placement" );
QUnit.module( "placement" );
test( "elements() order", function() {
QUnit.test( "elements() order", function( assert ) {
var container = $( "#orderContainer" ),
v = $( "#elementsOrder" ).validate( {
errorLabelContainer: container,
wrap: "li"
} );
deepEqual(
assert.deepEqual(
v.elements().map( function() {
return $( this ).attr( "id" );
} ).get(),
@@ -23,7 +23,7 @@ test( "elements() order", function() {
);
v.form();
deepEqual(
assert.deepEqual(
container.children().map( function() {
return $( this ).attr( "id" );
} ).get(),
@@ -39,8 +39,8 @@ test( "elements() order", function() {
);
} );
test( "error containers, simple", function() {
expect( 14 );
QUnit.test( "error containers, simple", function( assert ) {
assert.expect( 14 );
var container = $( "#simplecontainer" ),
v = $( "#form" ).validate( {
errorLabelContainer: container,
@@ -51,9 +51,9 @@ test( "error containers, simple", function() {
} );
v.prepareForm();
ok( v.valid(), "form is valid" );
equal( container.find( ".error:not(input)" ).length, 0, "There should be no error labels" );
equal( container.find( "h3" ).html(), "" );
assert.ok( v.valid(), "form is valid" );
assert.equal( container.find( ".error:not(input)" ).length, 0, "There should be no error labels" );
assert.equal( container.find( "h3" ).html(), "" );
v.prepareForm();
v.errorList = [
@@ -71,27 +71,27 @@ test( "error containers, simple", function() {
}
];
ok( !v.valid(), "form is not valid after adding errors manually" );
assert.ok( !v.valid(), "form is not valid after adding errors manually" );
v.showErrors();
equal( container.find( ".error:not(input)" ).length, 2, "There should be two error labels" );
ok( container.is( ":visible" ), "Check that the container is visible" );
assert.equal( container.find( ".error:not(input)" ).length, 2, "There should be two error labels" );
assert.ok( container.is( ":visible" ), "Check that the container is visible" );
container.find( ".error:not(input)" ).each( function() {
ok( $( this ).is( ":visible" ), "Check that each label is visible" );
assert.ok( $( this ).is( ":visible" ), "Check that each label is visible" );
} );
equal( container.find( "h3" ).html(), "There are 2 errors in your form." );
assert.equal( container.find( "h3" ).html(), "There are 2 errors in your form." );
v.prepareForm();
ok( v.valid(), "form is valid after a reset" );
assert.ok( v.valid(), "form is valid after a reset" );
v.showErrors();
equal( container.find( ".error:not(input)" ).length, 2, "There should still be two error labels" );
ok( container.is( ":hidden" ), "Check that the container is hidden" );
assert.equal( container.find( ".error:not(input)" ).length, 2, "There should still be two error labels" );
assert.ok( container.is( ":hidden" ), "Check that the container is hidden" );
container.find( ".error:not(input)" ).each( function() {
ok( $( this ).is( ":hidden" ), "Check that each label is hidden" );
assert.ok( $( this ).is( ":hidden" ), "Check that each label is hidden" );
} );
} );
test( "error containers, with labelcontainer I", function() {
expect( 16 );
QUnit.test( "error containers, with labelcontainer I", function( assert ) {
assert.expect( 16 );
var container = $( "#container" ),
labelcontainer = $( "#labelcontainer" ),
v = $( "#form" ).validate( {
@@ -100,10 +100,10 @@ test( "error containers, with labelcontainer I", function() {
wrapper: "li"
} );
ok( v.valid(), "form is valid" );
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" );
assert.ok( v.valid(), "form is valid" );
assert.equal( container.find( ".error:not(input)" ).length, 0, "There should be no error labels in the container" );
assert.equal( labelcontainer.find( ".error:not(input)" ).length, 0, "There should be no error labels in the labelcontainer" );
assert.equal( labelcontainer.find( "li" ).length, 0, "There should be no lis labels in the labelcontainer" );
v.errorList = [
{
@@ -121,46 +121,46 @@ test( "error containers, with labelcontainer I", function() {
}
];
ok( !v.valid(), "form is not valid after adding errors manually" );
assert.ok( !v.valid(), "form is not valid after adding errors manually" );
v.showErrors();
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" );
assert.equal( container.find( ".error:not(input)" ).length, 0, "There should be no error label in the container" );
assert.equal( labelcontainer.find( ".error:not(input)" ).length, 2, "There should be two error labels in the labelcontainer" );
assert.equal( labelcontainer.find( "li" ).length, 2, "There should be two error lis in the labelcontainer" );
assert.ok( container.is( ":visible" ), "Check that the container is visible" );
assert.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( $( 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" );
assert.ok( $( this ).is( ":visible" ), "Check that each label is visible1" );
assert.equal( $( this ).parent()[ 0 ].tagName.toLowerCase(), "li", "Check that each label is wrapped in an li" );
assert.ok( $( this ).parent( "li" ).is( ":visible" ), "Check that each parent li is visible" );
} );
} );
test( "errorcontainer, show/hide only on submit", function() {
expect( 14 );
QUnit.test( "errorcontainer, show/hide only on submit", function( assert ) {
assert.expect( 14 );
var container = $( "#container" ),
labelContainer = $( "#labelcontainer" ),
v = $( "#testForm1" ).bind( "invalid-form.validate", function() {
ok( true, "invalid-form event triggered called" );
assert.ok( true, "invalid-form event triggered called" );
} ).validate( {
errorContainer: container,
errorLabelContainer: labelContainer,
showErrors: function() {
container.html( jQuery.validator.format( "There are {0} errors in your form.", this.numberOfInvalids() ) );
ok( true, "showErrors called" );
assert.ok( true, "showErrors called" );
this.defaultShowErrors();
}
} );
equal( container.html(), "", "must be empty" );
equal( labelContainer.html(), "", "must be empty" );
assert.equal( container.html(), "", "must be empty" );
assert.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( 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" );
assert.ok( !v.form(), "invalid form" );
assert.equal( labelContainer.find( ".error:not(input)" ).length, 2 );
assert.equal( container.html(), "There are 2 errors in your form." );
assert.ok( labelContainer.is( ":visible" ), "must be visible" );
assert.ok( container.is( ":visible" ), "must be visible" );
$( "#firstname" ).val( "hix" ).keyup();
$( "#testForm1" ).triggerHandler( "keyup", [
@@ -169,15 +169,15 @@ test( "errorcontainer, show/hide only on submit", function() {
target: $( "#firstname" )[ 0 ]
} )
] );
equal( labelContainer.find( ".error:visible" ).length, 1 );
equal( container.html(), "There are 1 errors in your form." );
assert.equal( labelContainer.find( ".error:visible" ).length, 1 );
assert.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" );
assert.ok( v.form(), "Form now valid, trigger showErrors but not invalid-form" );
} );
test( "test label used as error container", function( assert ) {
expect( 8 );
QUnit.test( "test label used as error container", function( assert ) {
assert.expect( 8 );
var form = $( "#testForm16" ),
field = $( "#testForm16text" );
@@ -190,20 +190,20 @@ test( "test label used as error container", function( assert ) {
errorElement: "span"
} );
ok( !field.valid() );
equal( field.next( "label" ).contents().first().text(), "Field Label", "container label isn't disrupted" );
assert.ok( !field.valid() );
assert.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" );
assert.ok( !field.attr( "aria-describedby" ), "field does not require aria-describedby attribute" );
field.val( "foo" );
ok( field.valid() );
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.ok( field.valid() );
assert.equal( field.next( "label" ).contents().first().text(), "Field Label", "container label isn't disrupted" );
assert.ok( !field.attr( "aria-describedby" ), "field does not require aria-describedby attribute" );
assert.noErrorFor( field );
} );
test( "test error placed adjacent to descriptive label", function( assert ) {
expect( 8 );
QUnit.test( "test error placed adjacent to descriptive label", function( assert ) {
assert.expect( 8 );
var form = $( "#testForm16" ),
field = $( "#testForm16text" );
@@ -211,20 +211,20 @@ test( "test error placed adjacent to descriptive label", function( assert ) {
errorElement: "span"
} );
ok( !field.valid() );
equal( form.find( "label" ).length, 1 );
equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" );
assert.ok( !field.valid() );
assert.equal( form.find( "label" ).length, 1 );
assert.equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" );
assert.hasError( field, "missing" );
field.val( "foo" );
ok( field.valid() );
equal( form.find( "label" ).length, 1 );
equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" );
assert.ok( field.valid() );
assert.equal( form.find( "label" ).length, 1 );
assert.equal( form.find( "label" ).text(), "Field Label", "container label isn't disrupted" );
assert.noErrorFor( field );
} );
test( "test descriptive label used alongside error label", function( assert ) {
expect( 8 );
QUnit.test( "test descriptive label used alongside error label", function( assert ) {
assert.expect( 8 );
var form = $( "#testForm16" ),
field = $( "#testForm16text" );
@@ -232,20 +232,20 @@ test( "test descriptive label used alongside error label", function( assert ) {
errorElement: "label"
} );
ok( !field.valid() );
equal( form.find( "label.title" ).length, 1 );
equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" );
assert.ok( !field.valid() );
assert.equal( form.find( "label.title" ).length, 1 );
assert.equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" );
assert.hasError( field, "missing" );
field.val( "foo" );
ok( field.valid() );
equal( form.find( "label.title" ).length, 1 );
equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" );
assert.ok( field.valid() );
assert.equal( form.find( "label.title" ).length, 1 );
assert.equal( form.find( "label.title" ).text(), "Field Label", "container label isn't disrupted" );
assert.noErrorFor( field );
} );
test( "test custom errorElement", function( assert ) {
expect( 4 );
QUnit.test( "test custom errorElement", function( assert ) {
assert.expect( 4 );
var form = $( "#userForm" ),
field = $( "#username" );
@@ -256,48 +256,48 @@ test( "test custom errorElement", function( assert ) {
errorElement: "label"
} );
ok( !field.valid() );
assert.ok( !field.valid() );
assert.hasError( field, "missing", "Field should have error 'missing'" );
field.val( "foo" );
ok( field.valid() );
assert.ok( field.valid() );
assert.noErrorFor( field, "Field should not have a visible error" );
} );
test( "test existing label used as error element", function( assert ) {
expect( 4 );
QUnit.test( "test existing label used as error element", function( assert ) {
assert.expect( 4 );
var form = $( "#testForm14" ),
field = $( "#testForm14text" );
form.validate( { errorElement: "label" } );
ok( !field.valid() );
assert.ok( !field.valid() );
assert.hasError( field, "required" );
field.val( "foo" );
ok( field.valid() );
assert.ok( field.valid() );
assert.noErrorFor( field );
} );
test( "test existing non-label used as error element", function( assert ) {
expect( 4 );
QUnit.test( "test existing non-label used as error element", function( assert ) {
assert.expect( 4 );
var form = $( "#testForm15" ),
field = $( "#testForm15text" );
form.validate( { errorElement: "span" } );
ok( !field.valid() );
assert.ok( !field.valid() );
assert.hasError( field, "required" );
field.val( "foo" );
ok( field.valid() );
assert.ok( field.valid() );
assert.noErrorFor( field );
} );
test( "test aria-describedby with input names contains CSS-selector meta-characters", function() {
QUnit.test( "test aria-describedby with input names contains CSS-selector meta-characters", function( assert ) {
var form = $( "#testForm21" ),
field = $( "#testForm21\\!\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\`\\{\\|\\}\\~" );
equal( field.attr( "aria-describedby" ), undefined );
assert.equal( field.attr( "aria-describedby" ), undefined );
form.validate( {
errorElement: "span",
@@ -308,8 +308,8 @@ test( "test aria-describedby with input names contains CSS-selector meta-charact
} );
// Validate the element
ok( !field.valid() );
equal( field.attr( "aria-describedby" ), "testForm21!#$%&'()*+,./:;<=>?@[\\]^`{|}~-error" );
assert.ok( !field.valid() );
assert.equal( field.attr( "aria-describedby" ), "testForm21!#$%&'()*+,./:;<=>?@[\\]^`{|}~-error" );
// Re-run validation
field.val( "some" );
@@ -318,38 +318,38 @@ test( "test aria-describedby with input names contains CSS-selector meta-charact
field.val( "something" );
field.trigger( "keyup" );
equal( field.attr( "aria-describedby" ), "testForm21!#$%&'()*+,./:;<=>?@[\\]^`{|}~-error", "`aria-describedby` should remain the same as before." );
assert.equal( field.attr( "aria-describedby" ), "testForm21!#$%&'()*+,./:;<=>?@[\\]^`{|}~-error", "`aria-describedby` should remain the same as before." );
// Re-run validation
field.val( "something something" );
field.trigger( "keyup" );
ok( field.valid() );
equal( field.attr( "aria-describedby" ), "testForm21!#$%&'()*+,./:;<=>?@[\\]^`{|}~-error", "`aria-describedby` should remain the same as before." );
assert.ok( field.valid() );
assert.equal( field.attr( "aria-describedby" ), "testForm21!#$%&'()*+,./:;<=>?@[\\]^`{|}~-error", "`aria-describedby` should remain the same as before." );
} );
test( "test existing non-error aria-describedby", function( assert ) {
expect( 8 );
QUnit.test( "test existing non-error aria-describedby", function( assert ) {
assert.expect( 8 );
var form = $( "#testForm17" ),
field = $( "#testForm17text" );
equal( field.attr( "aria-describedby" ), "testForm17text-description" );
assert.equal( field.attr( "aria-describedby" ), "testForm17text-description" );
form.validate( { errorElement: "span" } );
ok( !field.valid() );
equal( field.attr( "aria-describedby" ), "testForm17text-description testForm17text-error" );
assert.ok( !field.valid() );
assert.equal( field.attr( "aria-describedby" ), "testForm17text-description testForm17text-error" );
assert.hasError( field, "required" );
field.val( "foo" );
ok( field.valid() );
assert.ok( field.valid() );
assert.noErrorFor( field );
strictEqual( $( "#testForm17text-description" ).text(), "This is where you enter your data" );
strictEqual( $( "#testForm17text-error" ).text(), "", "Error label is empty for valid field" );
assert.strictEqual( $( "#testForm17text-description" ).text(), "This is where you enter your data" );
assert.strictEqual( $( "#testForm17text-error" ).text(), "", "Error label is empty for valid field" );
} );
test( "test pre-assigned non-error aria-describedby", function( assert ) {
expect( 7 );
QUnit.test( "test pre-assigned non-error aria-describedby", function( assert ) {
assert.expect( 7 );
var form = $( "#testForm17" ),
field = $( "#testForm17text" );
@@ -357,19 +357,19 @@ test( "test pre-assigned non-error aria-describedby", function( assert ) {
field.attr( "aria-describedby", "testForm17text-description testForm17text-error" );
form.validate( { errorElement: "span" } );
ok( !field.valid() );
equal( field.attr( "aria-describedby" ), "testForm17text-description testForm17text-error" );
assert.ok( !field.valid() );
assert.equal( field.attr( "aria-describedby" ), "testForm17text-description testForm17text-error" );
assert.hasError( field, "required" );
field.val( "foo" );
ok( field.valid() );
assert.ok( field.valid() );
assert.noErrorFor( field );
strictEqual( $( "#testForm17text-description" ).text(), "This is where you enter your data" );
strictEqual( $( "#testForm17text-error" ).text(), "", "Error label is empty for valid field" );
assert.strictEqual( $( "#testForm17text-description" ).text(), "This is where you enter your data" );
assert.strictEqual( $( "#testForm17text-error" ).text(), "", "Error label is empty for valid field" );
} );
test( "test id/name containing brackets", function( assert ) {
QUnit.test( "test id/name containing brackets", function( assert ) {
var form = $( "#testForm18" ),
field = $( "#testForm18\\[text\\]" );
@@ -382,7 +382,7 @@ test( "test id/name containing brackets", function( assert ) {
assert.hasError( field, "required" );
} );
test( "test id/name containing $", function( assert ) {
QUnit.test( "test id/name containing $", function( assert ) {
var form = $( "#testForm19" ),
field = $( "#testForm19\\$text" );
@@ -394,7 +394,7 @@ test( "test id/name containing $", function( assert ) {
assert.hasError( field, "required" );
} );
test( "test id/name containing single quotes", function() {
QUnit.test( "test id/name containing single quotes", function( assert ) {
var v = $( "#testForm20" ).validate(),
textElement = $( "#testForm20\\[\\'textinput\\'\\]" ),
checkboxElement = $( "#testForm20\\[\\'checkboxinput\\'\\]" ),
@@ -402,13 +402,13 @@ test( "test id/name containing single quotes", function() {
v.form();
equal( v.numberOfInvalids(), 3, "There is three invalid elements" );
equal( v.invalidElements()[ 0 ], textElement[ 0 ], "The element should be invalid" );
equal( v.invalidElements()[ 1 ], checkboxElement[ 0 ], "The text element should be invalid" );
equal( v.invalidElements()[ 2 ], radioElement[ 0 ], "The text element should be invalid" );
assert.equal( v.numberOfInvalids(), 3, "There is three invalid elements" );
assert.equal( v.invalidElements()[ 0 ], textElement[ 0 ], "The element should be invalid" );
assert.equal( v.invalidElements()[ 1 ], checkboxElement[ 0 ], "The text element should be invalid" );
assert.equal( v.invalidElements()[ 2 ], radioElement[ 0 ], "The text element should be invalid" );
} );
test( "#1632: Error hidden, but input error class not removed", function() {
QUnit.test( "#1632: Error hidden, but input error class not removed", function( assert ) {
var v = $( "#testForm23" ).validate( {
rules: {
box1: {
@@ -432,11 +432,11 @@ test( "#1632: Error hidden, but input error class not removed", function() {
box1.val( "something" );
v.form();
equal( v.numberOfInvalids(), 1, "There is only one invlid element" );
equal( v.invalidElements()[ 0 ], box2[ 0 ], "The box2 element should be invalid" );
assert.equal( v.numberOfInvalids(), 1, "There is only one invlid element" );
assert.equal( v.invalidElements()[ 0 ], box2[ 0 ], "The box2 element should be invalid" );
box1.val( "" );
v.form();
equal( v.numberOfInvalids(), 0, "There is no error" );
equal( box2.hasClass( "error" ), false, "Box2 should not have an error class" );
assert.equal( v.numberOfInvalids(), 0, "There is no error" );
assert.equal( box2.hasClass( "error" ), false, "Box2 should not have an error class" );
} );