2015-07-28 00:07:27 +02:00
|
|
|
/* global wp */
|
2020-10-07 18:31:53 +02:00
|
|
|
jQuery( 'body' ).on( '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
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.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
|
|
|
*/
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'generatePlaceholderAutoIncrementId generates unique IDs', function( assert ) {
|
2015-07-28 00:07:27 +02:00
|
|
|
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();
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( -1 === ids.indexOf( placeholderID ) );
|
2015-07-28 00:07:27 +02:00
|
|
|
ids.push( placeholderID );
|
2015-08-03 21:27:27 +02:00
|
|
|
testIterations -= 1;
|
2015-07-28 00:07:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'it should parse _wpCustomizeMenusSettings.defaults into itself', function( assert ) {
|
|
|
|
assert.deepEqual( window._wpCustomizeNavMenusSettings, api.Menus.data );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'empty menus should have no Menu Item Controls', function( assert ) {
|
|
|
|
assert.ok( 0 === wp.customize.Menus.getMenuControl( socialMenuId ).getMenuItemControls().length, 'empty menus' );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'populated menus should have no Menu Item Controls', function( assert ) {
|
|
|
|
assert.ok( 0 !== wp.customize.Menus.getMenuControl( primaryMenuId ).getMenuItemControls().length, 'non-empty menus' );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
|
|
|
|
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
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'there is a properly configured MenusPanel', function( assert ) {
|
2015-08-03 21:27:27 +02:00
|
|
|
var panel, sections;
|
|
|
|
|
|
|
|
panel = api.panel( 'nav_menus' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( panel );
|
|
|
|
assert.ok( panel.extended( api.Menus.MenusPanel ) );
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
sections = panel.sections();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( 'menu_locations' === sections[0].id, 'first section is menu_locations' );
|
|
|
|
assert.ok( sections[1].extended( api.Menus.MenuSection ), 'second section is MenuSection' );
|
|
|
|
assert.ok( sections[ sections.length - 1 ].extended( api.Menus.NewMenuSection ), 'last section is NewMenuSection' );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
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
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'there an expected MenuSection for the primary menu', function( assert ) {
|
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 + ']' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( section, 'section exists' );
|
|
|
|
assert.ok( section.extended( api.Menus.MenuSection ), 'section is a api.Menus.MenuSection' );
|
|
|
|
assert.ok( section.deferred.initSortables, 'has section.deferred.initSortables' );
|
|
|
|
assert.ok( section.active(), 'section active() is true' );
|
|
|
|
assert.ok( section.active.set( false ).get(), 'section active() cannot be set false' );
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
controls = section.controls();
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( controls[0].extended( api.Menus.MenuNameControl ), 'first control in menu section is MenuNameControl' );
|
|
|
|
assert.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 ];
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( lastControl.extended( api.Control ), 'last control in menu section is a base Control' );
|
|
|
|
assert.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
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'changing a MenuNameControl change the corresponding menu value', function( assert ) {
|
2015-08-03 21:27:27 +02:00
|
|
|
var section, control;
|
|
|
|
|
|
|
|
section = api.section( 'nav_menu[' + primaryMenuId + ']' );
|
|
|
|
control = section.controls()[0];
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( control.extended( api.Menus.MenuNameControl ), 'control is a MenuNameControl' );
|
|
|
|
assert.equal( control.setting().name, 'Primary menu' );
|
|
|
|
assert.ok( ! control.setting._dirty );
|
2015-08-03 21:27:27 +02:00
|
|
|
control.container.find( 'input[type=text]:first' ).val( 'Main menu' ).trigger( 'change' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( control.setting().name, 'Main menu' );
|
|
|
|
assert.ok( control.setting._dirty );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
|
|
|
// @todo Add more tests for api.Menus.MenuNameControl
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'manipulating a MenuItemControl works', function( assert ) {
|
2015-08-03 21:27:27 +02:00
|
|
|
var section, control, value;
|
|
|
|
section = api.section( 'nav_menu[' + primaryMenuId + ']' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( section );
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
control = section.controls()[1];
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( control.extended( api.Menus.MenuItemControl ), 'control is a MenuItemControl' );
|
2015-08-03 21:27:27 +02:00
|
|
|
|
|
|
|
control.actuallyEmbed();
|
|
|
|
|
|
|
|
control.container.find( '.edit-menu-item-title' ).val( 'Hello World' ).trigger( 'change' );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( control.setting().title, 'Hello World' );
|
2015-08-03 21:27:27 +02:00
|
|
|
value = _.clone( control.setting() );
|
|
|
|
value.title = 'Hola Mundo';
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.equal( control.container.find( '.edit-menu-item-title' ).val(), 'Hello World' );
|
|
|
|
assert.equal( value.position, 1 );
|
|
|
|
assert.equal( control.priority(), 1 );
|
2015-08-03 21:27:27 +02:00
|
|
|
|
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
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'api.Menus.getMenuControl() should return the expected control', function( assert ) {
|
2015-08-03 21:27:27 +02:00
|
|
|
var control = api.Menus.getMenuControl( primaryMenuId );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( !! control, 'control is returned' );
|
|
|
|
assert.ok( control.extended( api.Menus.MenuControl ), 'control is a MenuControl' );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
|
|
|
|
2020-03-27 01:16:58 +01:00
|
|
|
QUnit.test( 'api.Menus.getMenuItemControl() should return the expected control', function( assert ) {
|
2015-08-03 21:27:27 +02:00
|
|
|
var control = api.Menus.getMenuItemControl( 2000 );
|
2020-03-27 01:16:58 +01:00
|
|
|
assert.ok( !! control, 'control is returned' );
|
|
|
|
assert.ok( control.extended( api.Menus.MenuItemControl ), 'control is a MenuItemControl' );
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|
2015-07-28 00:07:27 +02:00
|
|
|
|
2015-08-03 21:27:27 +02:00
|
|
|
} );
|