Tests: Lint

This commit is contained in:
Scott González 2012-04-19 09:39:21 -04:00
parent 4f19289c10
commit aa187f57d1
7 changed files with 114 additions and 118 deletions

View File

@ -361,6 +361,7 @@ grunt.initConfig({
menu_click: true, menu_click: true,
menu_log: true, menu_log: true,
module: true, module: true,
notEqual: true,
ok: true, ok: true,
QUnit: true, QUnit: true,
spinner_simulateKeyDownUp: true, spinner_simulateKeyDownUp: true,

View File

@ -99,7 +99,7 @@ asyncTest( "animateClass clears style properties when stopped", function() {
var test = $("div.animateClass"), var test = $("div.animateClass"),
style = test[0].style, style = test[0].style,
orig = style.cssText; orig = style.cssText;
expect( 2 ); expect( 2 );
test.addClass( "testChangeBackground", duration ); test.addClass( "testChangeBackground", duration );
@ -113,17 +113,17 @@ asyncTest( "animateClass clears style properties when stopped", function() {
asyncTest( "animateClass: css and class changes during animation are not lost (#7106)", function() { asyncTest( "animateClass: css and class changes during animation are not lost (#7106)", function() {
var test = $( "div.ticket7106" ); var test = $( "div.ticket7106" );
// add a class and change a style property after starting an animated class
test.addClass( "animate", minDuration, animationComplete )
.addClass( "testClass" )
.height( 100 );
// ensure the class stays and that the css property stays // ensure the class stays and that the css property stays
function animationComplete() { function animationComplete() {
ok( test.hasClass( "testClass" ), "class change during animateClass was not lost" ); ok( test.hasClass( "testClass" ), "class change during animateClass was not lost" );
equal( test.height(), 100, "css change during animateClass was not lost" ); equal( test.height(), 100, "css change during animateClass was not lost" );
start(); start();
} }
// add a class and change a style property after starting an animated class
test.addClass( "animate", minDuration, animationComplete )
.addClass( "testClass" )
.height( 100 );
}); });
@ -133,10 +133,9 @@ $.each( $.effects.effect, function( effect ) {
} }
module( "effect."+effect ); module( "effect."+effect );
asyncTest( "show/hide", function() { asyncTest( "show/hide", function() {
var hidden = $( "div.hidden" );
expect( 8 ); expect( 8 );
var hidden = $( "div.hidden" ),
var count = 0, count = 0,
test = 0; test = 0;
function queueTest( fn ) { function queueTest( fn ) {

View File

@ -4,6 +4,11 @@ module( "effect.scale: Scale" );
function run( position, v, h, vo, ho ) { function run( position, v, h, vo, ho ) {
var desc = "End Position Correct: " + position + " (" + v + "," + h + ") - origin: (" + vo + "," + ho + ")"; var desc = "End Position Correct: " + position + " (" + v + "," + h + ") - origin: (" + vo + "," + ho + ")";
asyncTest( desc, function() { asyncTest( desc, function() {
function complete() {
equal( parseInt( test.css( h ), 10 ), target[ h ], "Horizontal Position Correct " + desc );
equal( parseInt( test.css( v ), 10 ), target[ v ], "Vertical Position Correct " + desc );
start();
}
var test = $( ".testScale" ), var test = $( ".testScale" ),
css = { css = {
position: position position: position
@ -21,22 +26,16 @@ function run( position, v, h, vo, ho ) {
css[ h ] = 33; css[ h ] = 33;
css[ v ] = 33; css[ v ] = 33;
target[ h ] = h === ho ? css[ h ] : ho == "center" ? css[ h ] - 35 : css[ h ] - 70; target[ h ] = h === ho ? css[ h ] : ho === "center" ? css[ h ] - 35 : css[ h ] - 70;
target[ v ] = v === vo ? css[ v ] : vo == "middle" ? css[ v ] - 35 : css[ v ] - 70; target[ v ] = v === vo ? css[ v ] : vo === "middle" ? css[ v ] - 35 : css[ v ] - 70;
if ( relative && h == "right" ) { if ( relative && h === "right" ) {
target[ h ] += 70; target[ h ] += 70;
} }
if ( relative && v == "bottom" ) { if ( relative && v === "bottom" ) {
target[ v ] += 70; target[ v ] += 70;
} }
test.css( css ); test.css( css );
test.effect( effect ); test.effect( effect );
function complete() {
equal( parseInt( test.css( h ), 10 ), target[ h ], "Horizontal Position Correct " + desc );
equal( parseInt( test.css( v ), 10 ), target[ v ], "Vertical Position Correct " + desc );
start();
}
}); });
} }

View File

@ -9,18 +9,19 @@ module("menu: core");
test("accessibility", function () { test("accessibility", function () {
expect(5); expect(5);
var menu = $('#menu1').menu(); var item,
var item0 = $("li:eq(0) a"); menu = $('#menu1').menu(),
item0 = $("li:eq(0) a");
ok( menu.hasClass("ui-menu ui-widget ui-widget-content ui-corner-all"), "menu class"); ok( menu.hasClass("ui-menu ui-widget ui-widget-content ui-corner-all"), "menu class");
equal( menu.attr("role"), "menu", "main role"); equal( menu.attr("role"), "menu", "main role");
ok( !menu.attr("aria-activedescendant"), "aria attribute not yet active"); ok( !menu.attr("aria-activedescendant"), "aria attribute not yet active");
var item = menu.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end(); item = menu.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end();
menu.menu( "focus", $.Event(), item ); menu.menu( "focus", $.Event(), item );
equal( menu.attr("aria-activedescendant"), "xid", "aria attribute, id from dom"); equal( menu.attr("aria-activedescendant"), "xid", "aria attribute, id from dom");
var item = menu.find( "li:last" ); item = menu.find( "li:last" );
menu.menu( "focus", $.Event(), item ); menu.menu( "focus", $.Event(), item );
equal( menu.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id"); equal( menu.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id");
}); });

View File

@ -86,9 +86,6 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() {
expect( 4 ); expect( 4 );
var $menu = $( "#menu2" ).menu(); var $menu = $( "#menu2" ).menu();
$menu.find( "li:nth-child(7)" ).trigger( "mouseover" );
setTimeout( menumouseleave1, 350 );
function menumouseleave1() { function menumouseleave1() {
equal( $menu.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" ); equal( $menu.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" );
$menu.find( "li:nth-child(7) li:first" ).trigger( "mouseover" ); $menu.find( "li:nth-child(7) li:first" ).trigger( "mouseover" );
@ -108,15 +105,15 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() {
equal( $menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); equal( $menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
start(); start();
} }
$menu.find( "li:nth-child(7)" ).trigger( "mouseover" );
setTimeout( menumouseleave1, 350 );
}); });
asyncTest( "handle submenu auto collapse: mouseleave", function() { asyncTest( "handle submenu auto collapse: mouseleave", function() {
expect( 4 ); expect( 4 );
var $menu = $( "#menu5" ).menu( { menus: "div" } ); var $menu = $( "#menu5" ).menu( { menus: "div" } );
$menu.find( ":nth-child(7)" ).trigger( "mouseover" );
setTimeout( menumouseleave1, 350 );
function menumouseleave1() { function menumouseleave1() {
equal( $menu.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" ); equal( $menu.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" );
$menu.find( ":nth-child(7)" ).find( "div" ).eq( 0 ).children().eq( 0 ).trigger( "mouseover" ); $menu.find( ":nth-child(7)" ).find( "div" ).eq( 0 ).children().eq( 0 ).trigger( "mouseover" );
@ -136,6 +133,10 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() {
equal( $menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); equal( $menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" );
start(); start();
} }
$menu.find( ":nth-child(7)" ).trigger( "mouseover" );
setTimeout( menumouseleave1, 350 );
}); });

View File

@ -42,31 +42,32 @@ test( "my, at, of", function() {
}); });
test( "multiple elements", function() { test( "multiple elements", function() {
var elements = $( "#el1, #el2" ); var elements = $( "#el1, #el2" ),
var result = elements.position({ result = elements.position({
my: "left top", my: "left top",
at: "left bottom", at: "left bottom",
of: "#parent", of: "#parent",
collision: "none" collision: "none"
}); }),
expected = { top: 10, left: 4 };
deepEqual( result, elements ); deepEqual( result, elements );
var expected = { top: 10, left: 4 };
elements.each(function() { elements.each(function() {
deepEqual( $( this ).offset(), expected ); deepEqual( $( this ).offset(), expected );
}); });
}); });
test( "positions", function() { test( "positions", function() {
var definitions = []; var definitions = [],
var offsets = { offsets = {
left: 0, left: 0,
center: 3, center: 3,
right: 6, right: 6,
top: 0, top: 0,
bottom: 6 bottom: 6
}; },
var start = { left: 4, top: 4 }; start = { left: 4, top: 4 },
el = $( "#el1" );
$.each( [ 0, 1 ], function( my ) { $.each( [ 0, 1 ], function( my ) {
$.each( [ "top", "center", "bottom" ], function( vindex, vertical ) { $.each( [ "top", "center", "bottom" ], function( vindex, vertical ) {
$.each( [ "left", "center", "right" ], function( hindex, horizontal ) { $.each( [ "left", "center", "right" ], function( hindex, horizontal ) {
@ -81,7 +82,6 @@ test( "positions", function() {
}); });
}); });
}); });
var el = $( "#el1" );
$.each( definitions, function( index, definition ) { $.each( definitions, function( index, definition ) {
el.position({ el.position({
my: definition.my, my: definition.my,
@ -445,12 +445,12 @@ test( "addClass: flipped left", function() {
deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Has ui-flipped-left class' ); deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Has ui-flipped-left class' );
elem.position( { elem.position({
my: "right center", my: "right center",
of: window, of: window,
collision: "flip", collision: "flip",
at: "left center" at: "left center"
}) });
deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Removed ui-flipped-left class' ); deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Removed ui-flipped-left class' );
}); });

View File

@ -65,32 +65,33 @@ test( "my, at, of", function() {
}); });
test( "multiple elements", function() { test( "multiple elements", function() {
var elements = $( "#el1, #el2" ); var elements = $( "#el1, #el2" ),
var result = elements.position({ result = elements.position({
my: "left top", my: "left top",
at: "left bottom", at: "left bottom",
of: "#parent", of: "#parent",
collision: "none", collision: "none",
within: $("#within-container") within: $("#within-container")
}); }),
expected = { top: addTop + 10, left: addLeft + 4 };
deepEqual( result, elements ); deepEqual( result, elements );
var expected = { top: addTop + 10, left: addLeft + 4 };
elements.each(function() { elements.each(function() {
deepEqual( $( this ).addOffsets(), expected ); deepEqual( $( this ).addOffsets(), expected );
}); });
}); });
test( "positions", function() { test( "positions", function() {
var definitions = []; var definitions = [],
var offsets = { offsets = {
left: 0, left: 0,
center: 3, center: 3,
right: 6, right: 6,
top: 0, top: 0,
bottom: 6 bottom: 6
}; },
var start = { left: 4, top: 4 }; start = { left: 4, top: 4 },
el = $( "#el1" );
$.each( [ 0, 1 ], function( my ) { $.each( [ 0, 1 ], function( my ) {
$.each( [ "top", "center", "bottom" ], function( vindex, vertical ) { $.each( [ "top", "center", "bottom" ], function( vindex, vertical ) {
$.each( [ "left", "center", "right" ], function( hindex, horizontal ) { $.each( [ "left", "center", "right" ], function( hindex, horizontal ) {
@ -105,7 +106,6 @@ test( "positions", function() {
}); });
}); });
}); });
var el = $( "#el1" );
$.each( definitions, function( index, definition ) { $.each( definitions, function( index, definition ) {
el.position({ el.position({
my: definition.my, my: definition.my,
@ -120,7 +120,8 @@ test( "positions", function() {
}); });
test( "of", function() { test( "of", function() {
var within = $("#within-container"); var event,
within = $( "#within-container" );
$( "#elx" ).position({ $( "#elx" ).position({
my: "left top", my: "left top",
@ -149,7 +150,7 @@ test( "of", function() {
}); });
deepEqual( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "DOM element" ); deepEqual( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "DOM element" );
var event = $.extend( $.Event( "someEvent" ), { pageX: 200, pageY: 300 } ); event = $.extend( $.Event( "someEvent" ), { pageX: 200, pageY: 300 } );
$( "#elx" ).position({ $( "#elx" ).position({
my: "left top", my: "left top",
at: "left top", at: "left top",
@ -219,9 +220,8 @@ test( "within:offsets", function() {
test( "using", function() { test( "using", function() {
expect( 6 ); expect( 6 );
var within = $("#within-container"); var within = $( "#within-container" ),
count = 0,
var count = 0,
elems = $( "#el1, #el2" ), elems = $( "#el1, #el2" ),
expectedPosition = { top: addTop + 40, left: addLeft + 40 }, expectedPosition = { top: addTop + 40, left: addLeft + 40 },
originalPosition = elems.position({ originalPosition = elems.position({
@ -252,14 +252,13 @@ test( "using", function() {
}); });
function collisionTest( config, result, msg ) { function collisionTest( config, result, msg ) {
var within = $("#within-container"); var within = $( "#within-container" ),
elem = $( "#elx" ).position( $.extend({
var elem = $( "#elx" ).position( $.extend({ my: "left top",
my: "left top", at: "right bottom",
at: "right bottom", of: "#parentx",
of: "#parentx", within: within
within: within }, config ) );
}, config ) );
deepEqual( elem.addOffsets(), result, msg ); deepEqual( elem.addOffsets(), result, msg );
} }
@ -448,39 +447,37 @@ test( "collision: flip, with margin", function() {
}); });
test( "addClass: flipped left", function() { test( "addClass: flipped left", function() {
var within = $("#within-container"); var within = $("#within-container"),
elem = $( "#elx" ).position( {
var elem = $( "#elx" ).position( { my: "left center",
my: "left center", of: within[0],
of: within[0], within: within,
within: within, collision: "flip",
collision: "flip", at: "right center"
at: "right center" });
});
deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Has ui-flipped-left class' ); deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Has ui-flipped-left class' );
elem.position( { elem.position({
my: "right center", my: "right center",
of: within[0], of: within[0],
within: within, within: within,
collision: "flip", collision: "flip",
at: "left center" at: "left center"
}) });
deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Removed ui-flipped-left class' ); deepEqual( elem.hasClass( 'ui-flipped-left' ), false, 'Removed ui-flipped-left class' );
}); });
test( "addClass: flipped top", function() { test( "addClass: flipped top", function() {
var within = $("#within-container"); var within = $("#within-container"),
elem = $( "#elx" ).position( {
var elem = $( "#elx" ).position( { my: "left top",
my: "left top", of: within[0],
of: within[0], within: within,
within: within, collision: "flip",
collision: "flip", at: "right bottom"
at: "right bottom" });
});
deepEqual( elem.hasClass( 'ui-flipped-top' ), false, 'Has ui-flipped-top class' ); deepEqual( elem.hasClass( 'ui-flipped-top' ), false, 'Has ui-flipped-top class' );
@ -496,15 +493,14 @@ test( "addClass: flipped top", function() {
}); });
test( "addClass: flipped right", function() { test( "addClass: flipped right", function() {
var within = $("#within-container"); var within = $("#within-container"),
elem = $( "#elx" ).position( {
var elem = $( "#elx" ).position( { my: "right center",
my: "right center", of: within[0],
of: within[0], within: within,
within: within, collision: "flip",
collision: "flip", at: "left center"
at: "left center" });
});
deepEqual( elem.hasClass( 'ui-flipped-right' ), false, 'Has ui-flipped-right class' ); deepEqual( elem.hasClass( 'ui-flipped-right' ), false, 'Has ui-flipped-right class' );
@ -521,14 +517,13 @@ test( "addClass: flipped right", function() {
}); });
test( "addClass: flipped bottom", function() { test( "addClass: flipped bottom", function() {
var within = $("#within-container"); var within = $("#within-container"),
elem = $( "#elx" ).position( {
var elem = $( "#elx" ).position( { my: "left bottom",
my: "left bottom", of: window,
of: window, collision: "flip",
collision: "flip", at: "right top"
at: "right top" });
});
deepEqual( elem.hasClass( 'ui-flipped-bottom' ), false, 'Has ui-flipped-bottom class' ); deepEqual( elem.hasClass( 'ui-flipped-bottom' ), false, 'Has ui-flipped-bottom class' );