2017-01-20 17:14:23 +01:00
|
|
|
/*global wpNavMenu */
|
|
|
|
( function( QUnit, $ ) {
|
|
|
|
QUnit.module( 'nav-menu' );
|
|
|
|
var assert,
|
|
|
|
eventsExpected = 3,
|
|
|
|
eventsFired = 0;
|
|
|
|
|
2017-10-02 20:34:53 +02:00
|
|
|
// Fail if we don't see the expected number of events triggered in 3 seconds.
|
2020-03-27 01:16:58 +01:00
|
|
|
setTimeout( function( assert ) {
|
2017-02-24 19:39:39 +01:00
|
|
|
// QUnit may load this file without running it, in which case `assert`
|
|
|
|
// will never be set to `assertPassed` below.
|
|
|
|
assert && assert.equal(
|
2017-01-20 17:14:23 +01:00
|
|
|
eventsFired,
|
|
|
|
eventsExpected,
|
|
|
|
eventsExpected + ' wpNavMenu events should fire.'
|
|
|
|
);
|
2017-10-02 20:34:53 +02:00
|
|
|
}, 3000 );
|
2017-01-20 17:14:23 +01:00
|
|
|
|
|
|
|
QUnit.test( 'Testing wpNavMenu event triggers.', function( assertPassed ) {
|
|
|
|
assert = assertPassed;
|
|
|
|
|
|
|
|
assert.expect( 3 );
|
|
|
|
|
|
|
|
var testString = '<div>Hello World</div>';
|
|
|
|
|
|
|
|
// Mock the internal function calls so the don't fail.
|
|
|
|
$.fn.hideAdvancedMenuItemFields = function() {
|
|
|
|
return {
|
|
|
|
'appendTo': function() { return true; },
|
|
|
|
'prependTo': function() { return true; }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.extend( {
|
|
|
|
'childMenuItems': function() { return $(); },
|
|
|
|
'shiftDepthClass': function() { return $(); }
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Set up the events we should test.
|
|
|
|
var eventsToTest = [
|
|
|
|
{
|
|
|
|
'event': 'addMenuItemToBottom',
|
|
|
|
'data': testString,
|
|
|
|
'expect': $( testString ),
|
|
|
|
'shouldTrigger': 'menu-item-added'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'event': 'addMenuItemToTop',
|
|
|
|
'data': testString,
|
|
|
|
'expect': $( testString ),
|
|
|
|
'shouldTrigger': 'menu-item-added'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'event': 'removeMenuItem',
|
|
|
|
'data': $( testString ),
|
|
|
|
'expect': $( testString ),
|
|
|
|
'shouldTrigger': 'menu-removing-item'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
// Test each of the events.
|
|
|
|
_.each( eventsToTest, function( theEvent ) {
|
|
|
|
|
|
|
|
var done = assert.async();
|
|
|
|
|
|
|
|
$( document ).on( theEvent.shouldTrigger, function( evt, passed ) {
|
|
|
|
assert.equal(
|
|
|
|
passed.html(),
|
|
|
|
theEvent.expect.html(),
|
|
|
|
'The ' + theEvent.event + ' should trigger ' + theEvent.shouldTrigger + '.'
|
|
|
|
);
|
|
|
|
eventsFired++;
|
|
|
|
done();
|
|
|
|
} );
|
|
|
|
wpNavMenu[ theEvent.event ]( theEvent.data );
|
|
|
|
$( document ).off( theEvent.shouldTrigger );
|
|
|
|
} );
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
} )( window.QUnit, jQuery );
|