Skip to content

Commit b070b64

Browse files
author
Gabriel Schulhof
committed
Tests: Integration: Custom select: Ensure dialog is removed after destroying dialog-sized select menu.
1 parent afabf5b commit b070b64

File tree

1 file changed

+85
-14
lines changed

1 file changed

+85
-14
lines changed

tests/integration/select/select_core.js

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -509,32 +509,103 @@
509509
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );
510510
},
511511
function() { $.mobile.back(); },
512-
function() { start(); }
512+
513+
start
513514
]);
514515
});
515516

516517
asyncTest( "destroying a custom select menu leaves no traces", function() {
517-
$.testHelper.pageSequence( [
518-
function() { $.mobile.changePage( "#destroyTestCustom" ); },
518+
expect( 7 );
519+
520+
var unenhancedSelectClone,
521+
prefix = ".destroyingASelectMenuLeavesNoTraces",
522+
id = "select-" + Math.round( Math.random() * 1177 ),
523+
unenhancedSelect = $(
524+
"<select id='" + id + "' data-" + ( $.mobile.ns || "" ) + "native-menu='false'>" +
525+
"<option>Title</option>" +
526+
"<option value='option1'>Option 1</option>" +
527+
"<option value='option2'>Option 2</option>" +
528+
"</select>");
529+
$.testHelper.detailedEventCascade( [
519530
function() {
520-
var unenhancedSelect = $(
521-
"<select data-" + ( $.mobile.ns || "" ) + "native-menu='false'>" +
522-
"<option>Title</option>" +
523-
"<option value='option1'>Option 1</option>" +
524-
"<option value='option2'>Option 2</option>" +
525-
"</select>"),
526-
unenhancedSelectClone = unenhancedSelect.clone();
531+
$.mobile.changePage( "#destroyTest" );
532+
},
533+
534+
{
535+
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "0" }
536+
},
537+
538+
function() {
539+
unenhancedSelectClone = unenhancedSelect.clone();
540+
541+
$( "#destroyTest" ).append( unenhancedSelectClone );
542+
unenhancedSelectClone.selectmenu();
543+
$( "#" + id + "-button" ).click();
544+
},
545+
546+
{
547+
popupafteropen: { src: $.mobile.document, event: "popupafteropen" + prefix + "1" }
548+
},
549+
550+
function( result ) {
551+
deepEqual( result.popupafteropen.timedOut, false, "Popup did open" );
552+
$( "#" + id + "-listbox" ).popup( "close" );
553+
},
554+
555+
{
556+
popupafterclose: { src: $.mobile.document, event: "popupafterclose" + prefix + "2" }
557+
},
527558

528-
$( "#destroyTestCustom" ).append( unenhancedSelectClone );
559+
function( result ) {
560+
var idx;
561+
562+
deepEqual( result.popupafterclose.timedOut, false, "Popup did close" );
563+
564+
unenhancedSelectClone.selectmenu( "destroy" );
565+
unenhancedSelectClone.remove();
566+
567+
deepEqual( $( "#destroyTest" ).children().length, 0, "After adding, enhancing, opening, destroying, and removing the popup-sized select menu, the page is empty" );
568+
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );
569+
570+
// Add a bunch of options to make sure the menu ends up larger than
571+
// the screen, thus requiring a dialog
572+
for ( idx = 3 ; idx < 60 ; idx++ ) {
573+
unenhancedSelect.append( "<option value='option" + idx + "'>Option " + idx + "</option>" );
574+
}
575+
unenhancedSelectClone = unenhancedSelect.clone();
576+
$( "#destroyTest" ).append( unenhancedSelectClone );
529577
unenhancedSelectClone.selectmenu();
578+
$( "#" + id + "-button" ).click();
579+
},
580+
581+
{
582+
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "3" }
583+
},
584+
585+
function() {
586+
// Close the dialog
587+
$.mobile.activePage.find( "a:first" ).click();
588+
},
589+
590+
{
591+
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "4" }
592+
},
593+
594+
function() {
530595
unenhancedSelectClone.selectmenu( "destroy" );
531596
unenhancedSelectClone.remove();
532597

533-
deepEqual( $( "#destroyTestCustom" ).children().length, 0, "After adding, enhancing, destroying, and removing the select menu, the page is empty" );
598+
deepEqual( $( "#destroyTest" ).children().length, 0, "After adding, enhancing, opening, destroying, and removing the dialog-sized select menu, the page is empty" );
534599
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );
600+
deepEqual( $( "#" + id + "-dialog" ).length, 0, "After adding, enhancing, opening, destroying, and removing the dialog-sized select menu, no dialog page is left behind" );
601+
$.mobile.back();
535602
},
536-
function() { $.mobile.back(); },
537-
function() { start(); }
603+
604+
{
605+
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "5" }
606+
},
607+
608+
start
538609
]);
539610
});
540611

0 commit comments

Comments
 (0)