From b75e4f7d27eff1c5a40fe101cb34a0f806efaede Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Sun, 14 Apr 2013 17:07:24 -0400 Subject: [PATCH] Datepicker Tests: fix failing oldIE tests by creating new inputs to focus when necessary for focus tests. --- tests/unit/datepicker/datepicker_core.js | 358 ++++++++++-------- tests/unit/datepicker/datepicker_options.js | 21 +- .../datepicker/datepicker_test_helpers.js | 10 +- 3 files changed, 226 insertions(+), 163 deletions(-) diff --git a/tests/unit/datepicker/datepicker_core.js b/tests/unit/datepicker/datepicker_core.js index befda3b2a..5914db269 100644 --- a/tests/unit/datepicker/datepicker_core.js +++ b/tests/unit/datepicker/datepicker_core.js @@ -30,154 +30,173 @@ test("widget method", function() { deepEqual($("body > #ui-datepicker-div:last-child")[0], actual); }); -asyncTest("baseStructure", function() { +asyncTest( "baseStructure", function() { expect( 58 ); var header, title, table, thead, week, panel, inl, child, - inp = TestHelpers.datepicker.init("#inp"), - dp = $("#ui-datepicker-div"); + inp = TestHelpers.datepicker.initNewInput(), + dp = $( "#ui-datepicker-div" ); function step1() { - inp[0].focus(); - setTimeout(function() { - ok(dp.is(":visible"), "Structure - datepicker visible"); - ok(!dp.is(".ui-datepicker-rtl"), "Structure - not right-to-left"); - ok(!dp.is(".ui-datepicker-multi"), "Structure - not multi-month"); - equal(dp.children().length, 2, "Structure - child count"); + TestHelpers.datepicker.onFocus( inp, function() { + ok( dp.is( ":visible" ), "Structure - datepicker visible" ); + ok( !dp.is( ".ui-datepicker-rtl" ), "Structure - not right-to-left" ); + ok( !dp.is( ".ui-datepicker-multi" ), "Structure - not multi-month" ); + equal( dp.children().length, 2, "Structure - child count" ); - header = dp.children(":first"); - ok(header.is("div.ui-datepicker-header"), "Structure - header division"); - equal(header.children().length, 3, "Structure - header child count"); - ok(header.children(":first").is("a.ui-datepicker-prev") && header.children(":first").html() !== "", "Structure - prev link"); - ok(header.children(":eq(1)").is("a.ui-datepicker-next") && header.children(":eq(1)").html() !== "", "Structure - next link"); + header = dp.children( ":first" ); + ok( header.is( "div.ui-datepicker-header" ), "Structure - header division" ); + equal( header.children().length, 3, "Structure - header child count" ); + ok( header.children( ":first" ).is( "a.ui-datepicker-prev" ) && header.children( ":first" ).html() !== "", "Structure - prev link" ); + ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-next" ) && header.children( ":eq(1)" ).html() !== "", "Structure - next link" ); - title = header.children(":last"); - ok(title.is("div.ui-datepicker-title") && title.html() !== "","Structure - title division"); - equal(title.children().length, 2, "Structure - title child count"); - ok(title.children(":first").is("span.ui-datepicker-month") && title.children(":first").text() !== "", "Structure - month text"); - ok(title.children(":last").is("span.ui-datepicker-year") && title.children(":last").text() !== "", "Structure - year text"); + title = header.children( ":last" ); + ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "","Structure - title division" ); + equal( title.children().length, 2, "Structure - title child count" ); + ok( title.children( ":first" ).is( "span.ui-datepicker-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" ); + ok( title.children( ":last" ).is( "span.ui-datepicker-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" ); - table = dp.children(":eq(1)"); - ok(table.is("table.ui-datepicker-calendar"), "Structure - month table"); - ok(table.children(":first").is("thead"), "Structure - month table thead"); - thead = table.children(":first").children(":first"); - ok(thead.is("tr"), "Structure - month table title row"); - equal(thead.find("th").length, 7, "Structure - month table title cells"); - ok(table.children(":eq(1)").is("tbody"), "Structure - month table body"); - ok(table.children(":eq(1)").children("tr").length >= 4, "Structure - month table week count"); - week = table.children(":eq(1)").children(":first"); - ok(week.is("tr"), "Structure - month table week row"); - equal(week.children().length, 7, "Structure - week child count"); - ok(week.children(":first").is("td.ui-datepicker-week-end"), "Structure - month table first day cell"); - ok(week.children(":last").is("td.ui-datepicker-week-end"), "Structure - month table second day cell"); - inp.datepicker("hide").datepicker("destroy"); + table = dp.children( ":eq(1)" ); + ok( table.is( "table.ui-datepicker-calendar" ), "Structure - month table" ); + ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" ); + thead = table.children( ":first" ).children( ":first" ); + ok( thead.is( "tr" ), "Structure - month table title row" ); + equal( thead.find( "th" ).length, 7, "Structure - month table title cells" ); + ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" ); + ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" ); + + week = table.children( ":eq(1)" ).children( ":first" ); + ok( week.is( "tr" ), "Structure - month table week row" ); + equal( week.children().length, 7, "Structure - week child count" ); + ok( week.children( ":first" ).is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" ); + ok( week.children( ":last" ).is( "td.ui-datepicker-week-end" ), "Structure - month table second day cell" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); step2(); }); } function step2() { // Editable month/year and button panel - inp = TestHelpers.datepicker.init("#inp", {changeMonth: true, changeYear: true, showButtonPanel: true}); - inp.focus(); - setTimeout(function() { - title = dp.find("div.ui-datepicker-title"); - ok(title.children(":first").is("select.ui-datepicker-month"), "Structure - month selector"); - ok(title.children(":last").is("select.ui-datepicker-year"), "Structure - year selector"); + inp = TestHelpers.datepicker.initNewInput({ + changeMonth: true, + changeYear: true, + showButtonPanel: true + }); + TestHelpers.datepicker.onFocus( inp, function() { + title = dp.find( "div.ui-datepicker-title" ); + ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure - month selector" ); + ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure - year selector" ); - panel = dp.children(":last"); - ok(panel.is("div.ui-datepicker-buttonpane"), "Structure - button panel division"); - equal(panel.children().length, 2, "Structure - button panel child count"); - ok(panel.children(":first").is("button.ui-datepicker-current"), "Structure - today button"); - ok(panel.children(":last").is("button.ui-datepicker-close"), "Structure - close button"); - inp.datepicker("hide").datepicker("destroy"); + panel = dp.children( ":last" ); + ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure - button panel division" ); + equal( panel.children().length, 2, "Structure - button panel child count" ); + ok( panel.children( ":first" ).is( "button.ui-datepicker-current" ), "Structure - today button" ); + ok( panel.children( ":last" ).is( "button.ui-datepicker-close" ), "Structure - close button" ); + inp.datepicker( "hide" ).datepicker( "destroy" ); step3(); }); } function step3() { // Multi-month 2 - inp = TestHelpers.datepicker.init("#inp", {numberOfMonths: 2}); - inp.focus(); - setTimeout(function() { - ok(dp.is(".ui-datepicker-multi"), "Structure multi [2] - multi-month"); - equal(dp.children().length, 3, "Structure multi [2] - child count"); - child = dp.children(":first"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-first"), "Structure multi [2] - first month division"); - child = dp.children(":eq(1)"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-last"), "Structure multi [2] - second month division"); - child = dp.children(":eq(2)"); - ok(child.is("div.ui-datepicker-row-break"), "Structure multi [2] - row break"); - ok(dp.is(".ui-datepicker-multi-2"), "Structure multi [2] - multi-2"); - inp.datepicker("hide").datepicker("destroy"); + inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 2 }); + TestHelpers.datepicker.onFocus( inp, function() { + ok( dp.is( ".ui-datepicker-multi" ), "Structure multi [2] - multi-month" ); + equal( dp.children().length, 3, "Structure multi [2] - child count" ); + child = dp.children( ":first" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2] - first month division" ); + + child = dp.children( ":eq(1)" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2] - second month division" ); + + child = dp.children( ":eq(2)" ); + ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2] - row break" ); + ok( dp.is( ".ui-datepicker-multi-2" ), "Structure multi [2] - multi-2" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); step4(); }); } function step4() { // Multi-month 3 - inp = TestHelpers.datepicker.init("#inp", {numberOfMonths: 3}); - inp.focus(); - setTimeout(function() { - ok(dp.is(".ui-datepicker-multi-3"), "Structure multi [3] - multi-3"); - ok(! dp.is(".ui-datepicker-multi-2"), "Structure multi [3] - Trac #6704"); - inp.datepicker("hide").datepicker("destroy"); + inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: 3 }); + TestHelpers.datepicker.onFocus( inp, function() { + ok( dp.is( ".ui-datepicker-multi-3" ), "Structure multi [3] - multi-3" ); + ok( !dp.is( ".ui-datepicker-multi-2" ), "Structure multi [3] - Trac #6704" ); + inp.datepicker( "hide" ).datepicker( "destroy" ); step5(); }); } function step5() { // Multi-month [2, 2] - inp = TestHelpers.datepicker.init("#inp", {numberOfMonths: [2, 2]}); - inp.focus(); - setTimeout(function() { - ok(dp.is(".ui-datepicker-multi"), "Structure multi - multi-month"); - equal(dp.children().length, 6, "Structure multi [2,2] - child count"); - child = dp.children(":first"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-first"), "Structure multi [2,2] - first month division"); - child = dp.children(":eq(1)"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-last"), "Structure multi [2,2] - second month division"); - child = dp.children(":eq(2)"); - ok(child.is("div.ui-datepicker-row-break"), "Structure multi [2,2] - row break"); - child = dp.children(":eq(3)"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-first"), "Structure multi [2,2] - third month division"); - child = dp.children(":eq(4)"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-last"), "Structure multi [2,2] - fourth month division"); - child = dp.children(":eq(5)"); - ok(child.is("div.ui-datepicker-row-break"), "Structure multi [2,2] - row break"); - inp.datepicker("hide").datepicker("destroy"); + inp = TestHelpers.datepicker.initNewInput({ numberOfMonths: [ 2, 2 ] }); + TestHelpers.datepicker.onFocus( inp, function() { + ok( dp.is( ".ui-datepicker-multi" ), "Structure multi - multi-month" ); + equal( dp.children().length, 6, "Structure multi [2,2] - child count" ); + + child = dp.children( ":first" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - first month division" ); + + child = dp.children( ":eq(1)" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - second month division" ); + + child = dp.children( ":eq(2)" ); + ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" ); + + child = dp.children( ":eq(3)" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - third month division" ); + + child = dp.children( ":eq(4)" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - fourth month division" ); + + child = dp.children( ":eq(5)" ); + ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); // Inline - inl = TestHelpers.datepicker.init("#inl"); + inl = TestHelpers.datepicker.init( "#inl" ); dp = inl.children(); - ok(dp.is(".ui-datepicker-inline"), "Structure inline - main div"); - ok(!dp.is(".ui-datepicker-rtl"), "Structure inline - not right-to-left"); - ok(!dp.is(".ui-datepicker-multi"), "Structure inline - not multi-month"); - equal(dp.children().length, 2, "Structure inline - child count"); - header = dp.children(":first"); - ok(header.is("div.ui-datepicker-header"), "Structure inline - header division"); - equal(header.children().length, 3, "Structure inline - header child count"); - table = dp.children(":eq(1)"); - ok(table.is("table.ui-datepicker-calendar"), "Structure inline - month table"); - ok(table.children(":first").is("thead"), "Structure inline - month table thead"); - ok(table.children(":eq(1)").is("tbody"), "Structure inline - month table body"); - inl.datepicker("destroy"); + + ok( dp.is( ".ui-datepicker-inline" ), "Structure inline - main div" ); + ok( !dp.is( ".ui-datepicker-rtl" ), "Structure inline - not right-to-left" ); + ok( !dp.is( ".ui-datepicker-multi" ), "Structure inline - not multi-month" ); + equal( dp.children().length, 2, "Structure inline - child count" ); + + header = dp.children( ":first" ); + ok( header.is( "div.ui-datepicker-header" ), "Structure inline - header division" ); + equal( header.children().length, 3, "Structure inline - header child count" ); + + table = dp.children( ":eq(1)" ); + ok( table.is( "table.ui-datepicker-calendar" ), "Structure inline - month table" ); + ok( table.children( ":first" ).is( "thead" ), "Structure inline - month table thead" ); + ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure inline - month table body" ); + + inl.datepicker( "destroy" ); // Inline multi-month - inl = TestHelpers.datepicker.init("#inl", {numberOfMonths: 2}); + inl = TestHelpers.datepicker.init( "#inl", { numberOfMonths: 2 } ); dp = inl.children(); - ok(dp.is(".ui-datepicker-inline") && dp.is(".ui-datepicker-multi"), "Structure inline multi - main div"); - equal(dp.children().length, 3, "Structure inline multi - child count"); - child = dp.children(":first"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-first"), "Structure inline multi - first month division"); - child = dp.children(":eq(1)"); - ok(child.is("div.ui-datepicker-group") && child.is("div.ui-datepicker-group-last"), "Structure inline multi - second month division"); - child = dp.children(":eq(2)"); - ok(child.is("div.ui-datepicker-row-break"), "Structure inline multi - row break"); - inl.datepicker("destroy"); + ok( dp.is( ".ui-datepicker-inline" ) && dp.is( ".ui-datepicker-multi" ), "Structure inline multi - main div" ); + equal( dp.children().length, 3, "Structure inline multi - child count" ); + + child = dp.children( ":first" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure inline multi - first month division" ); + + child = dp.children( ":eq(1)" ); + ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure inline multi - second month division" ); + + child = dp.children( ":eq(2)" ); + ok( child.is( "div.ui-datepicker-row-break" ), "Structure inline multi - row break" ); + + inl.datepicker( "destroy" ); start(); }); } @@ -185,61 +204,100 @@ asyncTest("baseStructure", function() { step1(); }); -test("customStructure", function() { +asyncTest( "customStructure", function() { expect( 20 ); var header, panel, title, thead, - dp = $("#ui-datepicker-div"), - // Check right-to-left localisation - inp = TestHelpers.datepicker.init("#inp", $.datepicker.regional.he); - inp.datepicker( "option", "showButtonPanel", true); - inp.focus(); - ok(dp.is(".ui-datepicker-rtl"), "Structure RTL - right-to-left"); - header = dp.children(":first"); - ok(header.is("div.ui-datepicker-header"), "Structure RTL - header division"); - equal(header.children().length, 3, "Structure RTL - header child count"); - ok(header.children(":first").is("a.ui-datepicker-next"), "Structure RTL - prev link"); - ok(header.children(":eq(1)").is("a.ui-datepicker-prev"), "Structure RTL - next link"); - panel = dp.children(":last"); - ok(panel.is("div.ui-datepicker-buttonpane"), "Structure RTL - button division"); - equal(panel.children().length, 2, "Structure RTL - button panel child count"); - ok(panel.children(":first").is("button.ui-datepicker-close"), "Structure RTL - close button"); - ok(panel.children(":last").is("button.ui-datepicker-current"), "Structure RTL - today button"); - inp.datepicker("hide").datepicker("destroy"); + inp = TestHelpers.datepicker.initNewInput( $.datepicker.regional.he ), + dp = $( "#ui-datepicker-div" ); + + function step1() { + inp.datepicker( "option", "showButtonPanel", true ); + + TestHelpers.datepicker.onFocus( inp, function() { + ok( dp.is( ".ui-datepicker-rtl" ), "Structure RTL - right-to-left" ); + + header = dp.children( ":first" ); + ok( header.is( "div.ui-datepicker-header" ), "Structure RTL - header division" ); + equal( header.children().length, 3, "Structure RTL - header child count" ); + ok( header.children( ":first" ).is( "a.ui-datepicker-next" ), "Structure RTL - prev link" ); + ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-prev" ), "Structure RTL - next link" ); + + panel = dp.children( ":last" ); + ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure RTL - button division" ); + equal( panel.children().length, 2, "Structure RTL - button panel child count" ); + ok( panel.children( ":first" ).is( "button.ui-datepicker-close" ), "Structure RTL - close button" ); + ok( panel.children( ":last" ).is( "button.ui-datepicker-current" ), "Structure RTL - today button" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); + step2(); + }); + } // Hide prev/next - inp = TestHelpers.datepicker.init("#inp", {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)}); - inp.val("02/10/2008").focus(); - header = dp.children(":first"); - ok(header.is("div.ui-datepicker-header"), "Structure hide prev/next - header division"); - equal(header.children().length, 1, "Structure hide prev/next - links child count"); - ok(header.children(":first").is("div.ui-datepicker-title"), "Structure hide prev/next - title division"); - inp.datepicker("hide").datepicker("destroy"); + function step2() { + inp = TestHelpers.datepicker.initNewInput({ + hideIfNoPrevNext: true, + minDate: new Date( 2008, 2 - 1, 4 ), + maxDate: new Date( 2008, 2 - 1, 14 ) + }); + inp.val( "02/10/2008" ); + + TestHelpers.datepicker.onFocus( inp, function() { + header = dp.children( ":first" ); + ok( header.is( "div.ui-datepicker-header" ), "Structure hide prev/next - header division" ); + equal( header.children().length, 1, "Structure hide prev/next - links child count" ); + ok( header.children( ":first" ).is( "div.ui-datepicker-title" ), "Structure hide prev/next - title division" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); + step3(); + }); + } // Changeable Month with read-only year - inp = TestHelpers.datepicker.init("#inp", {changeMonth: true}); - inp.focus(); - title = dp.children(":first").children(":last"); - equal(title.children().length, 2, "Structure changeable month - title child count"); - ok(title.children(":first").is("select.ui-datepicker-month"), "Structure changeable month - month selector"); - ok(title.children(":last").is("span.ui-datepicker-year"), "Structure changeable month - read-only year"); - inp.datepicker("hide").datepicker("destroy"); + function step3() { + inp = TestHelpers.datepicker.initNewInput({ changeMonth: true }); + + TestHelpers.datepicker.onFocus( inp, function() { + title = dp.children( ":first" ).children( ":last" ); + equal( title.children().length, 2, "Structure changeable month - title child count" ); + ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" ); + ok( title.children( ":last" ).is( "span.ui-datepicker-year" ), "Structure changeable month - read-only year" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); + step4(); + }); + } // Changeable year with read-only month - inp = TestHelpers.datepicker.init("#inp", {changeYear: true}); - inp.focus(); - title = dp.children(":first").children(":last"); - equal(title.children().length, 2, "Structure changeable year - title child count"); - ok(title.children(":first").is("span.ui-datepicker-month"), "Structure changeable year - read-only month"); - ok(title.children(":last").is("select.ui-datepicker-year"), "Structure changeable year - year selector"); - inp.datepicker("hide").datepicker("destroy"); + function step4() { + inp = TestHelpers.datepicker.initNewInput({ changeYear: true }); + + TestHelpers.datepicker.onFocus( inp, function() { + title = dp.children( ":first" ).children( ":last" ); + equal( title.children().length, 2, "Structure changeable year - title child count" ); + ok( title.children( ":first" ).is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" ); + ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure changeable year - year selector" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); + step5(); + }); + } // Read-only first day of week - inp = TestHelpers.datepicker.init("#inp", {changeFirstDay: false}); - inp.focus(); - thead = dp.find(".ui-datepicker-calendar thead tr"); - equal(thead.children().length, 7, "Structure read-only first day - thead child count"); - equal(thead.find("a").length, 0, "Structure read-only first day - thead links count"); - inp.datepicker("hide").datepicker("destroy"); + function step5() { + inp = TestHelpers.datepicker.initNewInput({ changeFirstDay: false }); + + TestHelpers.datepicker.onFocus( inp, function() { + thead = dp.find( ".ui-datepicker-calendar thead tr" ); + equal( thead.children().length, 7, "Structure read-only first day - thead child count" ); + equal( thead.find( "a" ).length, 0, "Structure read-only first day - thead links count" ); + + inp.datepicker( "hide" ).datepicker( "destroy" ); + start(); + }); + } + + step1(); }); test("keystrokes", function() { diff --git a/tests/unit/datepicker/datepicker_options.js b/tests/unit/datepicker/datepicker_options.js index a763b2fda..a775a5302 100644 --- a/tests/unit/datepicker/datepicker_options.js +++ b/tests/unit/datepicker/datepicker_options.js @@ -95,8 +95,7 @@ asyncTest( "invocation", function() { expect( isOldIE ? 25 : 29 ); function step0() { - var input = $( "" ).appendTo( "#qunit-fixture" ), - inp = TestHelpers.datepicker.init( input ), + var inp = TestHelpers.datepicker.initNewInput(), dp = $( "#ui-datepicker-div" ); button = inp.siblings( "button" ); @@ -114,8 +113,7 @@ asyncTest( "invocation", function() { function step1() { - var input = $( "" ).appendTo( "#qunit-fixture" ), - inp = TestHelpers.datepicker.init( input ), + var inp = TestHelpers.datepicker.initNewInput(), dp = $( "#ui-datepicker-div" ); TestHelpers.datepicker.onFocus( inp, function() { @@ -129,8 +127,10 @@ asyncTest( "invocation", function() { } function step2() { - var input = $( "" ).appendTo( "#qunit-fixture" ), - inp = TestHelpers.datepicker.init( input, { showOn: "button", buttonText: "Popup" } ), + var inp = TestHelpers.datepicker.initNewInput({ + showOn: "button", + buttonText: "Popup" + }), dp = $( "#ui-datepicker-div" ); ok( !dp.is( ":visible" ), "Button - initially hidden" ); @@ -153,8 +153,7 @@ asyncTest( "invocation", function() { } function step3() { - var input = $( "" ).appendTo( "#qunit-fixture" ), - inp = TestHelpers.datepicker.init( input, { + var inp = TestHelpers.datepicker.initNewInput({ showOn: "button", buttonImageOnly: true, buttonImage: "images/calendar.gif", @@ -183,8 +182,10 @@ asyncTest( "invocation", function() { } function step4() { - var input = $( "" ).appendTo( "#qunit-fixture" ), - inp = TestHelpers.datepicker.init( input, { showOn: "both", buttonImage: "images/calendar.gif"} ), + var inp = TestHelpers.datepicker.initNewInput({ + showOn: "both", + buttonImage: "images/calendar.gif" + }), dp = $( "#ui-datepicker-div" ); ok( !dp.is( ":visible" ), "Both - initially hidden" ); diff --git a/tests/unit/datepicker/datepicker_test_helpers.js b/tests/unit/datepicker/datepicker_test_helpers.js index b683f5137..9cb63c9ec 100644 --- a/tests/unit/datepicker/datepicker_test_helpers.js +++ b/tests/unit/datepicker/datepicker_test_helpers.js @@ -14,9 +14,13 @@ TestHelpers.datepicker = { d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()); equal(d1.toString(), d2.toString(), message); }, - init: function(id, options) { - $.datepicker.setDefaults($.datepicker.regional[""]); - return $(id).datepicker($.extend({showAnim: ""}, options || {})); + init: function( id, options ) { + $.datepicker.setDefaults( $.datepicker.regional[ "" ] ); + return $( id ).datepicker( $.extend( { showAnim: "" }, options || {} ) ); + }, + initNewInput: function( options ) { + var id = $( "" ).appendTo( "#qunit-fixture" ); + return TestHelpers.datepicker.init( id, options ); }, onFocus: function( element, onFocus ) { var fn = function( event ){