Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Tests: Integration: Custom select: Ensure dialog is removed after des…
Browse files Browse the repository at this point in the history
…troying dialog-sized select menu.

Applied manually from b070b64
  • Loading branch information
Gabriel Schulhof committed May 2, 2013
1 parent 2e55b22 commit b6cfd58
Showing 1 changed file with 83 additions and 13 deletions.
96 changes: 83 additions & 13 deletions tests/unit/select/select_core.js
Expand Up @@ -501,27 +501,97 @@
});

asyncTest( "destroying a custom select menu leaves no traces", function() {
$.testHelper.pageSequence( [
function() { $.mobile.changePage( "#destroyTestCustom" ); },
expect( 7 );

var unenhancedSelectClone,
prefix = ".destroyingASelectMenuLeavesNoTraces",
id = "select-" + Math.round( Math.random() * 1177 ),
unenhancedSelect = $(
"<select id='" + id + "' data-" + ( $.mobile.ns || "" ) + "native-menu='false'>" +
"<option>Title</option>" +
"<option value='option1'>Option 1</option>" +
"<option value='option2'>Option 2</option>" +
"</select>");
$.testHelper.detailedEventCascade( [
function() {
var unenhancedSelect = $(
"<select data-" + ( $.mobile.ns || "" ) + "native-menu='false'>" +
"<option>Title</option>" +
"<option value='option1'>Option 1</option>" +
"<option value='option2'>Option 2</option>" +
"</select>"),
unenhancedSelectClone = unenhancedSelect.clone();
$.mobile.changePage( "#destroyTest" );
},

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "0" }
},

function() {
unenhancedSelectClone = unenhancedSelect.clone();

$( "#destroyTestCustom" ).append( unenhancedSelectClone );
$( "#destroyTest" ).append( unenhancedSelectClone );
unenhancedSelectClone.selectmenu();
$( "#" + id + "-button" ).click();
},

{
popupafteropen: { src: $.mobile.document, event: "popupafteropen" + prefix + "1" }
},

function( result ) {
deepEqual( result.popupafteropen.timedOut, false, "Popup did open" );
$( "#" + id + "-listbox" ).popup( "close" );
},

{
popupafterclose: { src: $.mobile.document, event: "popupafterclose" + prefix + "2" }
},

function( result ) {
var idx;

deepEqual( result.popupafterclose.timedOut, false, "Popup did close" );

unenhancedSelectClone.selectmenu( "destroy" );
unenhancedSelectClone.remove();

deepEqual( $( "#destroyTestCustom" ).children().length, 0, "After adding, enhancing, destroying, and removing the select menu, the page is empty" );
deepEqual( $( "#destroyTest" ).children().length, 0, "After adding, enhancing, opening, destroying, and removing the popup-sized select menu, the page is empty" );
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );

// Add a bunch of options to make sure the menu ends up larger than
// the screen, thus requiring a dialog
for ( idx = 3 ; idx < 60 ; idx++ ) {
unenhancedSelect.append( "<option value='option" + idx + "'>Option " + idx + "</option>" );
}
unenhancedSelectClone = unenhancedSelect.clone();
$( "#destroyTest" ).append( unenhancedSelectClone );
unenhancedSelectClone.selectmenu();
$( "#" + id + "-button" ).click();
},
function() { $.mobile.back(); },
function() { start(); }

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "3" }
},

function() {
// Close the dialog
$.mobile.activePage.find( "a:first" ).click();
},

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "4" }
},

function() {
unenhancedSelectClone.selectmenu( "destroy" );
unenhancedSelectClone.remove();

deepEqual( $( "#destroyTest" ).children().length, 0, "After adding, enhancing, opening, destroying, and removing the dialog-sized select menu, the page is empty" );
ok( domEqual( unenhancedSelect, unenhancedSelectClone ), "DOM for select after enhancement/destruction is equal to DOM for unenhanced select" );
deepEqual( $( "#" + id + "-dialog" ).length, 0, "After adding, enhancing, opening, destroying, and removing the dialog-sized select menu, no dialog page is left behind" );
$.mobile.back();
},

{
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + prefix + "5" }
},

start
]);
});

Expand Down

0 comments on commit b6cfd58

Please sign in to comment.