customize-widgets.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* global wp */
  2. jQuery( 'body' ).on( 'load', function() {
  3. var api = wp.customize, $ = jQuery;
  4. QUnit.module( 'Customize Widgets' );
  5. QUnit.test( 'fixtures should be present', function( assert ) {
  6. var widgetControl;
  7. assert.ok( api.panel( 'widgets' ) );
  8. assert.ok( api.section( 'sidebar-widgets-sidebar-1' ) );
  9. widgetControl = api.control( 'widget_search[2]' );
  10. assert.ok( widgetControl );
  11. assert.ok( api.control( 'sidebars_widgets[sidebar-1]' ) );
  12. assert.ok( api( 'widget_search[2]' ) );
  13. assert.ok( api( 'sidebars_widgets[sidebar-1]' ) );
  14. assert.ok( widgetControl.params.content );
  15. assert.ok( widgetControl.params.widget_control );
  16. assert.ok( widgetControl.params.widget_content );
  17. assert.ok( widgetControl.params.widget_id );
  18. assert.ok( widgetControl.params.widget_id_base );
  19. });
  20. QUnit.test( 'widget contents should embed (with widget-added event) when section and control expand', function( assert ) {
  21. var control, section, widgetAddedEvent = null, widgetControlRootElement = null;
  22. control = api.control( 'widget_search[2]' );
  23. section = api.section( 'sidebar-widgets-sidebar-1' );
  24. $( document ).on( 'widget-added', function( event, widgetElement ) {
  25. widgetAddedEvent = event;
  26. widgetControlRootElement = widgetElement;
  27. });
  28. assert.ok( ! section.expanded() );
  29. assert.ok( 0 === control.container.find( '> .widget' ).length );
  30. // Preview sets the active state.
  31. section.active.set( true );
  32. control.active.set( true );
  33. api.control( 'sidebars_widgets[sidebar-1]' ).active.set( true );
  34. section.expand();
  35. assert.ok( ! widgetAddedEvent, 'expected widget added event not fired' );
  36. assert.ok( 1 === control.container.find( '> .widget' ).length, 'expected there to be one .widget element in the container' );
  37. assert.ok( 0 === control.container.find( '.widget-content' ).children().length );
  38. control.expand();
  39. assert.ok( 1 === control.container.find( '.widget-content' ).children().length );
  40. assert.ok( widgetAddedEvent );
  41. assert.ok( widgetControlRootElement.is( control.container.find( '> .widget' ) ) );
  42. assert.ok( 1 === control.container.find( '.widget-content #widget-search-2-title' ).length );
  43. $( document ).off( 'widget-added' );
  44. });
  45. QUnit.test( 'widgets panel should have notice', function( assert ) {
  46. var panel = api.panel( 'widgets' );
  47. assert.ok( panel.extended( api.Widgets.WidgetsPanel ) );
  48. panel.deferred.embedded.done( function() {
  49. assert.ok( 1 === panel.contentContainer.find( '.no-widget-areas-rendered-notice' ).length );
  50. assert.ok( panel.contentContainer.find( '.no-widget-areas-rendered-notice' ).is( ':visible' ) );
  51. api.section( 'sidebar-widgets-sidebar-1' ).active( true );
  52. api.control( 'sidebars_widgets[sidebar-1]' ).active( true );
  53. api.trigger( 'pane-contents-reflowed' );
  54. assert.ok( ! panel.contentContainer.find( '.no-widget-areas-rendered-notice' ).is( ':visible' ) );
  55. } );
  56. assert.expect( 4 );
  57. });
  58. });