mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
Add Initial JS Unit Tests for Menu Customizer
While these two tests will help ensure we don't repeat our mistakes, they mostly help lay the foundation for more tests that still need to be written. See #32688 Props adamsilverstein, jorbin git-svn-id: https://develop.svn.wordpress.org/trunk@33451 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
68ff8b1a80
commit
b5f505d3dd
123
tests/qunit/fixtures/customize-menus.js
Executable file
123
tests/qunit/fixtures/customize-menus.js
Executable file
@ -0,0 +1,123 @@
|
||||
window._wpCustomizeNavMenusSettings = {
|
||||
'nonce': 'yo',
|
||||
'phpIntMax': '2147483647',
|
||||
'menuItemTransport': 'postMessage',
|
||||
'allMenus': [{
|
||||
'term_id': '2',
|
||||
'name': 'Awesome menu',
|
||||
'slug': 'awesome-menu',
|
||||
'term_group': '0',
|
||||
'term_taxonomy_id': '2',
|
||||
'taxonomy': 'nav_menu',
|
||||
'description': '',
|
||||
'parent': '0',
|
||||
'count': '0'
|
||||
}, {
|
||||
'term_id': '3',
|
||||
'name': 'Cool Menu',
|
||||
'slug': 'cool-menu',
|
||||
'term_group': '0',
|
||||
'term_taxonomy_id': '3',
|
||||
'taxonomy': 'nav_menu',
|
||||
'description': '',
|
||||
'parent': '0',
|
||||
'count': '0'
|
||||
}],
|
||||
'defaultSettingValues': {
|
||||
'nav_menu': {
|
||||
'name': '',
|
||||
'description': '',
|
||||
'parent': 0,
|
||||
'auto_add': false
|
||||
},
|
||||
'nav_menu_item': {
|
||||
'object_id': 0,
|
||||
'object': '',
|
||||
'menu_item_parent': 0,
|
||||
'position': 0,
|
||||
'type': 'custom',
|
||||
'title': '',
|
||||
'url': '',
|
||||
'target': '',
|
||||
'attr_title': '',
|
||||
'description': '',
|
||||
'classes': '',
|
||||
'xfn': '',
|
||||
'status': 'publish',
|
||||
'original_title': '',
|
||||
'nav_menu_term_id': 0
|
||||
}
|
||||
},
|
||||
'itemTypes': {
|
||||
'postTypes': {
|
||||
'page': {
|
||||
'label': 'Page'
|
||||
},
|
||||
'post': {
|
||||
'label': 'Post'
|
||||
}
|
||||
},
|
||||
'taxonomies': {
|
||||
'post_tag': {
|
||||
'label': 'Tag'
|
||||
},
|
||||
'post_format': {
|
||||
'label': 'Format'
|
||||
},
|
||||
'category': {
|
||||
'label': 'Category'
|
||||
}
|
||||
}
|
||||
},
|
||||
'l10n': {
|
||||
'custom_label': 'Custom Link',
|
||||
'customizingMenus': 'Customizing ▸ Menus',
|
||||
'invalidTitleTpl': '%s (Invalid)',
|
||||
'itemAdded': 'Menu item added',
|
||||
'itemDeleted': 'Menu item deleted',
|
||||
'itemsFound': 'Number of items found: %d',
|
||||
'itemsFoundMore': 'Additional items found: %d',
|
||||
'itemsLoadingMore': 'Loading more results... please wait.',
|
||||
'menuAdded': 'Menu created',
|
||||
'menuDeleted': 'Menu deleted',
|
||||
'menuLocation': '(Currently set to: %s)',
|
||||
'menuNameLabel': 'Menu Name',
|
||||
'movedDown': 'Menu item moved down',
|
||||
'movedLeft': 'Menu item moved out of submenu',
|
||||
'movedRight': 'Menu item is now a sub-item',
|
||||
'movedUp': 'Menu item moved up',
|
||||
'pendingTitleTpl': '%s (Pending)',
|
||||
'postTypeLabel': 'Post Type',
|
||||
'reorderLabelOff': 'Close reorder mode',
|
||||
'reorderLabelOn': 'Reorder menu items',
|
||||
'reorderModeOff': 'Reorder mode closed',
|
||||
'reorderModeOn': 'Reorder mode enabled',
|
||||
'taxonomyTermLabel': 'Taxonomy',
|
||||
'unnamed': '(unnamed)',
|
||||
'untitled': '(no label)'
|
||||
}
|
||||
};
|
||||
|
||||
window._wpCustomizeSettings.panels.nav_menus = {
|
||||
'id': 'nav_menus',
|
||||
'description': '<p>This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.</p><p>Menus can be displayed in locations defined by your theme or in <a href="javascript:wp.customize.panel( "widgets" ).focus();">widget areas</a> by adding a “Custom Menu” widget.</p>',
|
||||
'priority': 100,
|
||||
'type': 'nav_menus',
|
||||
'title': 'Menus',
|
||||
'content': '',
|
||||
'active': true,
|
||||
'instanceNumber': 2
|
||||
};
|
||||
|
||||
window.wpNavMenu = {
|
||||
'options': {
|
||||
'menuItemDepthPerLevel': 30,
|
||||
'globalMaxDepth': 11,
|
||||
'sortableItems': '> *',
|
||||
'targetTolerance': 0
|
||||
},
|
||||
'menusChanged': false,
|
||||
'isRTL': false,
|
||||
'negateIfRTL': 1
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
<script src="../../src/wp-includes/js/jquery/ui/core.js"></script>
|
||||
<script src="../../src/wp-includes/js/underscore.min.js"></script>
|
||||
<script src="../../src/wp-includes/js/backbone.min.js"></script>
|
||||
<script src="../../src/wp-includes/js/wp-backbone.js"></script>
|
||||
<script src="../../src/wp-includes/js/zxcvbn.min.js"></script>
|
||||
<script src="../../src/wp-includes/js/wp-util.js"></script>
|
||||
|
||||
@ -23,6 +24,7 @@
|
||||
<div id="qunit-fixture">
|
||||
<script src="fixtures/customize-header.js"></script>
|
||||
<script src="fixtures/customize-settings.js"></script>
|
||||
<script src="fixtures/customize-menus.js"></script>
|
||||
</div>
|
||||
<p><a href="editor">TinyMCE tests</a></p>
|
||||
|
||||
@ -32,6 +34,7 @@
|
||||
<script src="../../src/wp-includes/js/customize-models.js"></script>
|
||||
<script src="../../src/wp-includes/js/shortcode.js"></script>
|
||||
<script src="../../src/wp-admin/js/customize-controls.js"></script>
|
||||
<script src="../../src/wp-admin/js/customize-nav-menus.js"></script>
|
||||
<script src="../../src/wp-admin/js/word-count.js"></script>
|
||||
|
||||
<!-- Unit tests -->
|
||||
@ -41,6 +44,7 @@
|
||||
<script src="wp-includes/js/shortcode.js"></script>
|
||||
<script src="wp-admin/js/customize-controls.js"></script>
|
||||
<script src="wp-admin/js/customize-controls-utils.js"></script>
|
||||
<script src="wp-admin/js/customize-nav-menus.js"></script>
|
||||
<script src="wp-admin/js/word-count.js"></script>
|
||||
|
||||
<!-- Customizer templates for sections -->
|
||||
|
43
tests/qunit/wp-admin/js/customize-nav-menus.js
Executable file
43
tests/qunit/wp-admin/js/customize-nav-menus.js
Executable file
@ -0,0 +1,43 @@
|
||||
/* global wp */
|
||||
jQuery( function( ) {
|
||||
|
||||
var api = wp.customize,
|
||||
settings = window._wpCustomizeNavMenusSettings,
|
||||
navMenu = window.wpNavMenu;
|
||||
|
||||
module( 'Customize Nav Menus', {
|
||||
setup: function() {
|
||||
window._wpCustomizeNavMenusSettings = settings;
|
||||
window.wpNavMenu = navMenu;
|
||||
},
|
||||
teardown: function() {
|
||||
// restore defaults
|
||||
window._wpCustomizeNavMenusSettings = settings;
|
||||
window.wpNavMenu = navMenu;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Generate 20 ids and verify they are all unique.
|
||||
*/
|
||||
test( 'generatePlaceholderAutoIncrementId generates unique IDs', function() {
|
||||
var testIterations = 20,
|
||||
ids = [ api.Menus.generatePlaceholderAutoIncrementId() ];
|
||||
|
||||
while( testIterations-- > 0 ) {
|
||||
var placeholderID = api.Menus.generatePlaceholderAutoIncrementId();
|
||||
|
||||
ok( -1 === ids.indexOf( placeholderID ) );
|
||||
ids.push( placeholderID );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
test( 'it should parse _wpCustomizeMenusSettings.defaults into itself', function() {
|
||||
deepEqual( window._wpCustomizeNavMenusSettings, api.Menus.data );
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user