Wordpress/tests/qunit/wp-admin/js/customize-nav-menus.js
Weston Ruter 01bb1fd6cb Customize: Deprecate nav menu classes that are no longer used, instead of removing them immediately.
* Deprecate PHP classes `WP_Customize_New_Menu_Section` and `WP_Customize_New_Menu_Control`.
* Deprecate JS class `wp.customize.Menus.NewMenuControl`.
* Also introduce `wp.customize.Menus.createNavMenu()` for logic to create nav menus separately from the logic for handling UI interactions.

Amends [41768].
See #40104, #42364.
Fixes #42357.


git-svn-id: https://develop.svn.wordpress.org/trunk@42034 602fd350-edb4-49c9-b593-d223f7449a82
2017-10-28 05:47:06 +00:00

133 lines
5.2 KiB
JavaScript

/* global wp */
jQuery( window ).load( function (){
var api = wp.customize,
primaryMenuId = 3,
socialMenuId = 2;
module( 'Customize Nav Menus' );
/**
* Generate 20 ids and verify they are all unique.
*/
test( 'generatePlaceholderAutoIncrementId generates unique IDs', function() {
var testIterations = 20,
ids = [ api.Menus.generatePlaceholderAutoIncrementId() ];
while ( testIterations ) {
var placeholderID = api.Menus.generatePlaceholderAutoIncrementId();
ok( -1 === ids.indexOf( placeholderID ) );
ids.push( placeholderID );
testIterations -= 1;
}
} );
test( 'it should parse _wpCustomizeMenusSettings.defaults into itself', function() {
deepEqual( window._wpCustomizeNavMenusSettings, api.Menus.data );
} );
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' );
} );
// @todo Add tests for api.Menus.AvailableMenuItemsPanelView (and api.Menus.AvailableItemCollection, api.Menus.AvailableItemCollection, api.Menus.AvailableItemModel)
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' );
} );
// @todo Add more tests for api.Menus.MenusPanel behaviors
test( 'there an expected MenuSection for the primary menu', function() {
var section, controls, lastControl;
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' );
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' );
} );
// @todo Add more tests for api.Menus.MenuSection behaviors
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 );
// @todo test control.moveDown();
} );
// @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
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' );
} );
} );