2014-12-02 23:55:48 +01:00
|
|
|
/* global wp */
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
jQuery( window ).load( function (){
|
|
|
|
'use strict';
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
var controlId, controlLabel, controlType, controlContent, controlDescription, controlData, mockControl,
|
|
|
|
mockControlInstance, controlExpectedValues, sectionId, sectionContent, sectionData, mockSection,
|
|
|
|
sectionInstance, sectionExpectedValues, panelId, panelTitle, panelDescription, panelContent, panelData,
|
2014-12-16 20:43:22 +01:00
|
|
|
mockPanel, panelExpectedValues, testCustomizerModel, settingId, settingValue, mockSetting;
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
testCustomizerModel = function( model, expectedValues ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
if ( ! expectedValues.type || ! wp.customize[ expectedValues.type ] ) {
|
|
|
|
throw new Error( 'Must pass value type in expectedValues.' );
|
|
|
|
}
|
|
|
|
var type = expectedValues.type;
|
|
|
|
test( 'Model extends proper type', function () {
|
|
|
|
ok( model.extended( wp.customize[ type ] ) );
|
|
|
|
} );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
if ( expectedValues.hasOwnProperty( 'id' ) ) {
|
2014-12-16 20:43:22 +01:00
|
|
|
test( type + ' instance has the right id', function () {
|
|
|
|
equal( model.id, expectedValues.id );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'title') ) {
|
|
|
|
test( type + ' instance has the right title.', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( model.params.title, expectedValues.title );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'description' ) ) {
|
|
|
|
test( type + ' instance has the right description.', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( model.params.description, expectedValues.description );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'content' ) ) {
|
|
|
|
test( type + ' instance has the right content.', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( model.params.content, expectedValues.content );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( expectedValues.hasOwnProperty( 'priority' ) ) {
|
|
|
|
test( type + ' instance has the right priority.', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( model.priority(), expectedValues.priority );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
2014-12-16 20:43:22 +01:00
|
|
|
if ( expectedValues.hasOwnProperty( 'active' ) ) {
|
|
|
|
test( type + ' instance has the right active state.', function () {
|
|
|
|
equal( model.active(), expectedValues.active );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
2014-12-16 20:43:22 +01:00
|
|
|
}
|
|
|
|
test( type + ' can be deactivated', function () {
|
|
|
|
model.activate();
|
|
|
|
model.deactivate();
|
|
|
|
equal( model.active(), false );
|
|
|
|
model.activate();
|
|
|
|
equal( model.active(), true );
|
|
|
|
ok(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( type === 'Panel' || type === 'Section' ) {
|
|
|
|
if ( expectedValues.hasOwnProperty( 'expanded' ) ) {
|
|
|
|
test( type + ' instance has the right expanded state.', function () {
|
|
|
|
equal( model.expanded(), expectedValues.expanded );
|
|
|
|
} );
|
|
|
|
}
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
test( type + ' instance is collapsed after calling .collapse()', function () {
|
|
|
|
model.collapse();
|
2014-12-16 20:43:22 +01:00
|
|
|
ok( ! model.expanded() );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( type + ' instance is expanded after calling .expand()', function () {
|
|
|
|
model.expand();
|
|
|
|
ok( model.expanded() );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
module( 'Customizer Setting in Fixture' );
|
|
|
|
test( 'Setting has fixture value', function () {
|
|
|
|
equal( wp.customize( 'fixture-setting' )(), 'Lorem Ipsum' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
module( 'Customizer Control in Fixture' );
|
|
|
|
test( 'Control exists', function () {
|
|
|
|
ok( wp.customize.control.has( 'fixture-control' ) );
|
|
|
|
} );
|
|
|
|
test( 'Control has the fixture setting', function () {
|
|
|
|
var control = wp.customize.control( 'fixture-control' );
|
|
|
|
equal( control.setting(), 'Lorem Ipsum' );
|
|
|
|
equal( control.setting.id, 'fixture-setting' );
|
|
|
|
} );
|
|
|
|
test( 'Control has the section fixture section ID', function () {
|
|
|
|
var control = wp.customize.control( 'fixture-control' );
|
|
|
|
equal( control.section(), 'fixture-section' );
|
|
|
|
} );
|
|
|
|
|
2015-05-30 02:02:13 +02:00
|
|
|
// Begin sections.
|
2014-12-16 20:43:22 +01:00
|
|
|
module( 'Customizer Section in Fixture' );
|
|
|
|
test( 'Fixture section exists', function () {
|
|
|
|
ok( wp.customize.section.has( 'fixture-section' ) );
|
|
|
|
} );
|
|
|
|
test( 'Fixture section has control among controls()', function () {
|
|
|
|
var section = wp.customize.section( 'fixture-section' );
|
2015-05-30 02:02:13 +02:00
|
|
|
ok( -1 !== _.pluck( section.controls(), 'id' ).indexOf( 'fixture-control' ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
2015-05-30 02:02:13 +02:00
|
|
|
test( 'Fixture section has has expected panel', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
var section = wp.customize.section( 'fixture-section' );
|
|
|
|
equal( section.panel(), 'fixture-panel' );
|
|
|
|
} );
|
|
|
|
|
2015-05-30 02:02:13 +02:00
|
|
|
module( 'Customizer Default Section with Template in Fixture' );
|
|
|
|
test( 'Fixture section exists', function () {
|
|
|
|
ok( wp.customize.section.has( 'fixture-section-default-templated' ) );
|
|
|
|
} );
|
|
|
|
test( 'Fixture section has expected content', function () {
|
|
|
|
var id = 'fixture-section-default-templated', section;
|
|
|
|
section = wp.customize.section( id );
|
|
|
|
ok( ! section.params.content );
|
|
|
|
ok( !! section.container );
|
|
|
|
ok( section.container.is( '.control-section.control-section-default' ) );
|
|
|
|
ok( 1 === section.container.find( '> .accordion-section-title' ).length );
|
|
|
|
ok( 1 === section.container.find( '> .accordion-section-content' ).length );
|
|
|
|
} );
|
|
|
|
|
|
|
|
module( 'Customizer Custom Type (titleless) Section with Template in Fixture' );
|
|
|
|
test( 'Fixture section exists', function () {
|
|
|
|
ok( wp.customize.section.has( 'fixture-section-titleless-templated' ) );
|
|
|
|
} );
|
|
|
|
test( 'Fixture section has expected content', function () {
|
|
|
|
var id = 'fixture-section-titleless-templated', section;
|
|
|
|
section = wp.customize.section( id );
|
|
|
|
ok( ! section.params.content );
|
|
|
|
ok( !! section.container );
|
|
|
|
ok( section.container.is( '.control-section.control-section-titleless' ) );
|
|
|
|
ok( 0 === section.container.find( '> .accordion-section-title' ).length );
|
|
|
|
ok( 1 === section.container.find( '> .accordion-section-content' ).length );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Begin panels.
|
2014-12-16 20:43:22 +01:00
|
|
|
module( 'Customizer Panel in Fixture' );
|
|
|
|
test( 'Fixture panel exists', function () {
|
|
|
|
ok( wp.customize.panel.has( 'fixture-panel' ) );
|
|
|
|
} );
|
2015-05-30 02:02:13 +02:00
|
|
|
test( 'Fixture panel has content', function () {
|
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
|
|
|
ok( !! panel.params.content );
|
|
|
|
ok( !! panel.container );
|
|
|
|
} );
|
|
|
|
test( 'Fixture panel has section among its sections()', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
2015-05-30 02:02:13 +02:00
|
|
|
ok( -1 !== _.pluck( panel.sections(), 'id' ).indexOf( 'fixture-section' ) );
|
2014-12-16 20:43:22 +01:00
|
|
|
} );
|
|
|
|
test( 'Panel is not expanded by default', function () {
|
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
|
|
|
ok( ! panel.expanded() );
|
|
|
|
} );
|
|
|
|
test( 'Panel is not expanded by default', function () {
|
|
|
|
var panel = wp.customize.panel( 'fixture-panel' );
|
|
|
|
ok( ! panel.expanded() );
|
|
|
|
} );
|
|
|
|
test( 'Focusing on a control will expand the panel and section', function () {
|
|
|
|
var panel, section, control;
|
|
|
|
panel = wp.customize.panel( 'fixture-panel' );
|
|
|
|
section = wp.customize.section( 'fixture-section' );
|
|
|
|
control = wp.customize.control( 'fixture-control' );
|
|
|
|
ok( ! panel.expanded() );
|
|
|
|
ok( ! section.expanded() );
|
|
|
|
control.focus();
|
|
|
|
ok( section.expanded() );
|
|
|
|
ok( panel.expanded() );
|
|
|
|
} );
|
|
|
|
|
2015-05-30 02:02:13 +02:00
|
|
|
module( 'Customizer Default Panel with Template in Fixture' );
|
|
|
|
test( 'Fixture section exists', function () {
|
|
|
|
ok( wp.customize.panel.has( 'fixture-panel-default-templated' ) );
|
|
|
|
} );
|
|
|
|
test( 'Fixture panel has expected content', function () {
|
|
|
|
var id = 'fixture-panel-default-templated', panel;
|
|
|
|
panel = wp.customize.panel( id );
|
|
|
|
ok( ! panel.params.content );
|
|
|
|
ok( !! panel.container );
|
|
|
|
ok( panel.container.is( '.control-panel.control-panel-default' ) );
|
|
|
|
ok( 1 === panel.container.find( '> .accordion-section-title' ).length );
|
|
|
|
ok( 1 === panel.container.find( '> .control-panel-content' ).length );
|
|
|
|
} );
|
|
|
|
|
|
|
|
module( 'Customizer Custom Type Panel (titleless) with Template in Fixture' );
|
|
|
|
test( 'Fixture panel exists', function () {
|
|
|
|
ok( wp.customize.panel.has( 'fixture-panel-titleless-templated' ) );
|
|
|
|
} );
|
|
|
|
test( 'Fixture panel has expected content', function () {
|
|
|
|
var id = 'fixture-panel-titleless-templated', panel;
|
|
|
|
panel = wp.customize.panel( id );
|
|
|
|
ok( ! panel.params.content );
|
|
|
|
ok( !! panel.container );
|
|
|
|
ok( panel.container.is( '.control-panel.control-panel-titleless' ) );
|
|
|
|
ok( 0 === panel.container.find( '> .accordion-section-title' ).length );
|
|
|
|
ok( 1 === panel.container.find( '> .control-panel-content' ).length );
|
|
|
|
} );
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
|
|
|
|
module( 'Dynamically-created Customizer Setting Model' );
|
|
|
|
settingId = 'new_blogname';
|
|
|
|
settingValue = 'Hello World';
|
|
|
|
|
|
|
|
test( 'Create a new setting', function () {
|
|
|
|
mockSetting = wp.customize.create(
|
|
|
|
settingId,
|
|
|
|
settingId,
|
|
|
|
settingValue,
|
|
|
|
{
|
|
|
|
transport: 'refresh',
|
|
|
|
previewer: wp.customize.previewer
|
|
|
|
}
|
|
|
|
);
|
|
|
|
equal( mockSetting(), settingValue );
|
|
|
|
equal( mockSetting.id, settingId );
|
|
|
|
} );
|
|
|
|
|
|
|
|
module( 'Dynamically-created Customizer Section Model' );
|
|
|
|
|
|
|
|
sectionId = 'mock_title_tagline';
|
2015-05-30 02:02:13 +02:00
|
|
|
sectionContent = '<li id="accordion-section-mock_title_tagline" class="accordion-section control-section control-section-default"> <h3 class="accordion-section-title" tabindex="0"> Section Fixture <span class="screen-reader-text">Press return or enter to open</span> </h3> <ul class="accordion-section-content"> <li class="customize-section-description-container"> <div class="customize-section-title"> <button class="customize-section-back" tabindex="-1"> <span class="screen-reader-text">Back</span> </button> <h3> <span class="customize-action">Customizing ▸ Fixture Panel</span> Section Fixture </h3> </div> </li> </ul> </li>';
|
2014-12-16 20:43:22 +01:00
|
|
|
sectionData = {
|
|
|
|
content: sectionContent,
|
2015-05-30 02:02:13 +02:00
|
|
|
active: true,
|
|
|
|
type: 'default'
|
2014-12-16 20:43:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mockSection = new wp.customize.Section( sectionId, { params: sectionData } );
|
|
|
|
|
|
|
|
sectionExpectedValues = {
|
|
|
|
type: 'Section',
|
|
|
|
id: sectionId,
|
|
|
|
content: sectionContent,
|
|
|
|
priority: 100,
|
|
|
|
active: true // @todo This should default to true
|
|
|
|
};
|
|
|
|
|
|
|
|
testCustomizerModel( mockSection, sectionExpectedValues );
|
|
|
|
|
|
|
|
test( 'Section has been embedded', function () {
|
|
|
|
equal( mockSection.deferred.embedded.state(), 'resolved' );
|
|
|
|
} );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
wp.customize.section.add( sectionId, mockSection );
|
|
|
|
|
|
|
|
test( 'Section instance added to the wp.customize.section object', function () {
|
|
|
|
ok( wp.customize.section.has( sectionId ) );
|
|
|
|
});
|
|
|
|
|
|
|
|
sectionInstance = wp.customize.section( sectionId );
|
|
|
|
|
|
|
|
test( 'Section instance has right content when accessed from wp.customize.section()', function () {
|
|
|
|
equal( sectionInstance.params.content, sectionContent );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( 'Section instance has no children yet', function () {
|
|
|
|
equal( sectionInstance.controls().length, 0 );
|
|
|
|
});
|
|
|
|
|
|
|
|
module( 'Dynamically-created Customizer Control Model' );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
controlId = 'new_blogname';
|
|
|
|
controlLabel = 'Site Title';
|
|
|
|
controlType = 'text';
|
|
|
|
controlContent = '<li id="customize-control-blogname" class="customize-control customize-control-text"></li>';
|
|
|
|
controlDescription = 'Test control description';
|
|
|
|
|
|
|
|
controlData = {
|
2014-12-16 20:43:22 +01:00
|
|
|
content: controlContent,
|
|
|
|
description: controlDescription,
|
|
|
|
label: controlLabel,
|
|
|
|
settings: { 'default': 'new_blogname' },
|
|
|
|
type: controlType,
|
|
|
|
active: true // @todo This should default to true
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
mockControl = new wp.customize.Control( controlId, {
|
|
|
|
params: controlData,
|
|
|
|
previewer: wp.customize.previewer
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
controlExpectedValues = {
|
2014-12-16 20:43:22 +01:00
|
|
|
type: 'Control',
|
|
|
|
content: controlContent,
|
|
|
|
description: controlDescription,
|
|
|
|
label: controlLabel,
|
|
|
|
id: controlId,
|
|
|
|
priority: 10
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
testCustomizerModel( mockControl, controlExpectedValues );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
test( 'Control instance does not yet belong to a section.', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( mockControl.section(), undefined );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
2014-12-16 20:43:22 +01:00
|
|
|
test( 'Control has not been embedded yet', function () {
|
|
|
|
equal( mockControl.deferred.embedded.state(), 'pending' );
|
|
|
|
} );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
test( 'Control instance has the right selector.', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( mockControl.selector, '#customize-control-new_blogname' );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
wp.customize.control.add( controlId, mockControl );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
test( 'Control instance was added to the control class.', function () {
|
|
|
|
ok( wp.customize.control.has( controlId ) );
|
|
|
|
});
|
|
|
|
|
|
|
|
mockControlInstance = wp.customize.control( controlId );
|
|
|
|
|
|
|
|
test( 'Control instance has the right id when accessed from api.control().', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( mockControlInstance.id, controlId );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
test( 'Control section can be set as expected', function () {
|
|
|
|
mockControl.section( mockSection.id );
|
|
|
|
equal( mockControl.section(), mockSection.id );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
2014-12-16 20:43:22 +01:00
|
|
|
test( 'Associating a control with a section allows it to be embedded', function () {
|
|
|
|
equal( mockControl.deferred.embedded.state(), 'resolved' );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
test( 'Control is now available on section.controls()', function () {
|
|
|
|
equal( sectionInstance.controls().length, 1 );
|
|
|
|
equal( sectionInstance.controls()[0], mockControl );
|
|
|
|
});
|
2014-12-02 23:55:48 +01:00
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
module( 'Dynamically-created Customizer Panel Model' );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
panelId = 'mockPanelId';
|
|
|
|
panelTitle = 'Mock Panel Title';
|
|
|
|
panelDescription = 'Mock panel description';
|
|
|
|
panelContent = '<li id="accordion-panel-widgets" class="control-section control-panel accordion-section">';
|
|
|
|
panelData = {
|
2014-12-16 20:43:22 +01:00
|
|
|
content: panelContent,
|
|
|
|
title: panelTitle,
|
|
|
|
description: panelDescription,
|
2015-05-30 02:02:13 +02:00
|
|
|
active: true, // @todo This should default to true
|
|
|
|
type: 'default'
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
mockPanel = new wp.customize.Panel( panelId, { params: panelData } );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
panelExpectedValues = {
|
2014-12-16 20:43:22 +01:00
|
|
|
type: 'Panel',
|
|
|
|
id: panelId,
|
|
|
|
title: panelTitle,
|
|
|
|
description: panelDescription,
|
|
|
|
content: panelContent,
|
|
|
|
priority: 100,
|
|
|
|
active: true
|
2014-12-02 23:55:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-16 20:43:22 +01:00
|
|
|
testCustomizerModel( mockPanel, panelExpectedValues );
|
2014-12-02 23:55:48 +01:00
|
|
|
|
|
|
|
test( 'Panel instance is not contextuallyActive', function () {
|
2014-12-16 20:43:22 +01:00
|
|
|
equal( mockPanel.isContextuallyActive(), false );
|
2014-12-02 23:55:48 +01:00
|
|
|
});
|
|
|
|
});
|