2015-07-28 00:07:27 +02:00
|
|
|
/* global wp */
|
2015-08-03 21:27:27 +02:00
|
|
|
jQuery( window ).load( function (){
|
2015-07-28 00:07:27 +02:00
|
|
|
|
|
|
|
var api = wp.customize,
|
2015-08-03 21:27:27 +02:00
|
|
|
primaryMenuId = 3,
|
|
|
|
socialMenuId = 2;
|
2015-07-28 00:07:27 +02:00
|
|
|
|
2015-08-03 21:27:27 +02:00
|
|
|
module( 'Customize Nav Menus' );
|
2015-07-28 00:07:27 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-29 01:43:23 +01:00
|
|
|
* Generate 20 IDs and verify they are all unique.
|
2015-07-28 00:07:27 +02:00
|
|
|
*/
|
|
|
|
test( 'generatePlaceholderAutoIncrementId generates unique IDs', function() {
|
|
|
|
var testIterations = 20,
|
|
|
|
ids = [ api.Menus.generatePlaceholderAutoIncrementId() ];
|
|
|
|
|
2015-08-03 21:27:27 +02:00
|
|
|
while ( testIterations ) {
|
2015-07-28 00:07:27 +02:00
|
|
|
var placeholderID = api.Menus.generatePlaceholderAutoIncrementId();
|
|
|
|
|
|
|
|
ok( -1 === ids.indexOf( placeholderID ) );
|
|
|
|
ids.push( placeholderID );
|
2015-08-03 21:27:27 +02:00
|
|
|
testIterations -= 1;
|
2015-07-28 00:07:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'it should parse _wpCustomizeMenusSettings.defaults into itself', function() {
|
|
|
|
deepEqual( window._wpCustomizeNavMenusSettings, api.Menus.data );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'empty menus should have no Menu Item Controls', function() {
|
|
|
|
ok( 0 === wp.customize.Menus.getMenuControl( socialMenuId ).getMenuItemControls().length, 'empty menus' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'populated menus should have no Menu Item Controls', function() {
|
|
|
|
ok( 0 !== wp.customize.Menus.getMenuControl( primaryMenuId ).getMenuItemControls().length, 'non-empty menus' );
|
|
|
|
} );
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// @todo Add tests for api.Menus.AvailableMenuItemsPanelView
|
|
|
|
// (and api.Menus.AvailableItemCollection, api.Menus.AvailableItemModel).
|
2015-07-28 00:07:27 +02:00
|
|
|
|
2015-08-03 21:27:27 +02:00
|
|
|
test( 'there is a properly configured MenusPanel', function() {
|
|
|
|
var panel, sections;
|
|
|
|
|
|
|
|
panel = api.panel( 'nav_menus' );
|
|
|
|
ok( panel );
|
|
|
|
ok( panel.extended( api.Menus.MenusPanel ) );
|
|
|
|
|
|
|
|
sections = panel.sections();
|
|
|
|
ok( 'menu_locations' === sections[0].id, 'first section is menu_locations' );
|
|
|
|
ok( sections[1].extended( api.Menus.MenuSection ), 'second section is MenuSection' );
|
|
|
|
ok( sections[ sections.length - 1 ].extended( api.Menus.NewMenuSection ), 'last section is NewMenuSection' );
|
|
|
|
} );
|
2020-01-29 01:43:23 +01:00
|
|
|
// @todo Add more tests for api.Menus.MenusPanel behaviors.
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
test( 'there an expected MenuSection for the primary menu', function() {
|
2017-10-05 06:22:09 +02:00
|
|
|
var section, controls, lastControl;
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
section = api.section( 'nav_menu[' + primaryMenuId + ']' );
|
|
|
|
ok( section, 'section exists' );
|
|
|
|
ok( section.extended( api.Menus.MenuSection ), 'section is a api.Menus.MenuSection' );
|
|
|
|
ok( section.deferred.initSortables, 'has section.deferred.initSortables' );
|
|
|
|
ok( section.active(), 'section active() is true' );
|
|
|
|
ok( section.active.set( false ).get(), 'section active() cannot be set false' );
|
|
|
|
|
|
|
|
controls = section.controls();
|
|
|
|
ok( controls[0].extended( api.Menus.MenuNameControl ), 'first control in menu section is MenuNameControl' );
|
|
|
|
ok( controls[1].extended( api.Menus.MenuItemControl ), 'second control in menu section is MenuItemControl' );
|
2017-10-05 06:22:09 +02:00
|
|
|
|
|
|
|
lastControl = controls[ controls.length - 1 ];
|
|
|
|
ok( lastControl.extended( api.Control ), 'last control in menu section is a base Control' );
|
|
|
|
ok( lastControl.params.templateId === 'nav-menu-delete-button', 'last control in menu section has a delete-button template' );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
2020-01-29 01:43:23 +01:00
|
|
|
// @todo Add more tests for api.Menus.MenuSection behaviors.
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
test( 'changing a MenuNameControl change the corresponding menu value', function() {
|
|
|
|
var section, control;
|
|
|
|
|
|
|
|
section = api.section( 'nav_menu[' + primaryMenuId + ']' );
|
|
|
|
control = section.controls()[0];
|
|
|
|
ok( control.extended( api.Menus.MenuNameControl ), 'control is a MenuNameControl' );
|
|
|
|
equal( control.setting().name, 'Primary menu' );
|
|
|
|
ok( ! control.setting._dirty );
|
|
|
|
control.container.find( 'input[type=text]:first' ).val( 'Main menu' ).trigger( 'change' );
|
|
|
|
equal( control.setting().name, 'Main menu' );
|
|
|
|
ok( control.setting._dirty );
|
|
|
|
} );
|
|
|
|
// @todo Add more tests for api.Menus.MenuNameControl
|
|
|
|
|
|
|
|
test( 'manipulating a MenuItemControl works', function() {
|
|
|
|
var section, control, value;
|
|
|
|
section = api.section( 'nav_menu[' + primaryMenuId + ']' );
|
|
|
|
ok( section );
|
|
|
|
|
|
|
|
control = section.controls()[1];
|
|
|
|
ok( control.extended( api.Menus.MenuItemControl ), 'control is a MenuItemControl' );
|
|
|
|
|
|
|
|
control.actuallyEmbed();
|
|
|
|
|
|
|
|
control.container.find( '.edit-menu-item-title' ).val( 'Hello World' ).trigger( 'change' );
|
|
|
|
equal( control.setting().title, 'Hello World' );
|
|
|
|
value = _.clone( control.setting() );
|
|
|
|
value.title = 'Hola Mundo';
|
|
|
|
equal( control.container.find( '.edit-menu-item-title' ).val(), 'Hello World' );
|
|
|
|
equal( value.position, 1 );
|
|
|
|
equal( control.priority(), 1 );
|
|
|
|
|
2020-01-29 01:43:23 +01:00
|
|
|
// @todo Test control.moveDown().
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
2020-01-29 01:43:23 +01:00
|
|
|
// @todo Add more tests for api.Menus.MenuItemControl.
|
|
|
|
|
|
|
|
// @todo Add tests for api.Menus.NewMenuSection.
|
|
|
|
// @todo Add tests for api.Menus.MenuLocationControl.
|
|
|
|
// @todo Add tests for api.Menus.MenuLocationsControl.
|
|
|
|
// @todo Add tests for api.Menus.MenuAutoAddControl.
|
|
|
|
// @todo Add tests for api.Menus.MenuControl.
|
|
|
|
// @todo Add tests for api.Menus.applySavedData.
|
|
|
|
// @todo Add tests for api.Menus.focusMenuItemControl.
|
|
|
|
// @todo Add tests for api.Menus.createNavMenu.
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
test( 'api.Menus.getMenuControl() should return the expected control', function() {
|
|
|
|
var control = api.Menus.getMenuControl( primaryMenuId );
|
|
|
|
ok( !! control, 'control is returned' );
|
|
|
|
ok( control.extended( api.Menus.MenuControl ), 'control is a MenuControl' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'api.Menus.getMenuItemControl() should return the expected control', function() {
|
|
|
|
var control = api.Menus.getMenuItemControl( 2000 );
|
|
|
|
ok( !! control, 'control is returned' );
|
|
|
|
ok( control.extended( api.Menus.MenuItemControl ), 'control is a MenuItemControl' );
|
|
|
|
} );
|
2015-07-28 00:07:27 +02:00
|
|
|
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|