Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JavaScript unit tests and refactor #35

Merged
merged 65 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
20e2430
Add initial basic test
sirbrillig Jan 20, 2017
d64c61f
Alter extendWidgetControl to a (mostly) pure function
sirbrillig Jan 20, 2017
1fe1906
Add truthy test for isJsWidgetControl
sirbrillig Jan 20, 2017
e2dcb33
Fix missing jsdoc rules to satisfy eslint
sirbrillig Jan 20, 2017
26915f7
Explicitly pass underscore to the IIFE
sirbrillig Jan 23, 2017
8c34cfe
Remove unnecessary use of `_.clone`
sirbrillig Jan 23, 2017
9cc5229
Export Form as a module when within CommonJS
sirbrillig Jan 23, 2017
739150e
Add customize-base for tests
sirbrillig Jan 24, 2017
9e66457
Add initial tests for Form
sirbrillig Jan 24, 2017
99c9ae2
Update Form.initialize to deep merge config with defaults
sirbrillig Jan 24, 2017
ba2700d
Update tests to prove setState does not unexpectedly mutate the model
sirbrillig Jan 25, 2017
1d2ad13
Add tests for Form.model.validate()
sirbrillig Jan 26, 2017
187ac67
Add additional test to verify merging properties for setState()
sirbrillig Jan 26, 2017
e296998
Remove test for sanitize adding a title property
sirbrillig Jan 26, 2017
5d3e100
Remove merging default_instance in validate
sirbrillig Jan 26, 2017
c9cab13
Remove merging default_instance in sanitize
sirbrillig Jan 31, 2017
ce79ba4
Remove adding missing title property to model in sanitize
sirbrillig Jan 31, 2017
3c99186
Remove merging default_instance in setState()
sirbrillig Jan 26, 2017
778bc95
Add jsdom to use real jQuery for tests
sirbrillig Jan 27, 2017
f531a00
Add test for two-way binding form and model data
sirbrillig Jan 27, 2017
235cf1d
Simplify the form.model.validate method
sirbrillig Jan 30, 2017
b19fba3
Simplify Form constructor
sirbrillig Jan 30, 2017
25b27ae
Add Form.renderNotificationsToContainer to allow testing
sirbrillig Jan 31, 2017
7f3d014
Add tests for renderNotificationsToContainer
sirbrillig Jan 31, 2017
ff9ff09
Update validate tests to prove notifications are always removed
sirbrillig Jan 31, 2017
4dc6349
Always remove all sanitize-added notifications in validate
sirbrillig Jan 31, 2017
ce7b650
Add missing semicolon to validate function
sirbrillig Jan 31, 2017
19f752a
Ignore js tests in jshintignore
sirbrillig Jan 31, 2017
5976cc7
Add `npm test` to travis config
sirbrillig Jan 31, 2017
cad5b6a
Remove trailing comma to placate jshint
sirbrillig Jan 31, 2017
cb7bf73
Add root slash for .jshintignore
westonruter Jan 31, 2017
7be5641
Add tests dir to jscsrc ignore
sirbrillig Jan 31, 2017
1b08fdf
Add tests/js/lib to eslintignore
sirbrillig Jan 31, 2017
6361e7c
Remove duplicate "npm install"
sirbrillig Jan 31, 2017
5bbceca
Simplify renderNotificationsToContainer
sirbrillig Feb 2, 2017
bafd1b9
Add jsdoc to each helper method
sirbrillig Feb 2, 2017
c0e778e
Rename renderNotificationsTemplate to renderMarkupToContainer
sirbrillig Feb 2, 2017
0602b2f
Change tests so only model and container can be Form arguments
sirbrillig Feb 4, 2017
6f707e1
Explicitly pluck Form arguments when assigning
sirbrillig Feb 4, 2017
b06d226
Change tests so Form constructor requires id_base and default_instance
sirbrillig Feb 4, 2017
c2e5a0d
Require id_base and config.default_instance in Form constructor
sirbrillig Feb 4, 2017
ff48f63
Add test for memory leak in Form.model.validate
sirbrillig Feb 4, 2017
5255291
Move Form private functions to bottom of file
sirbrillig Feb 6, 2017
2145662
Add test for changing notification area height on show
sirbrillig Feb 6, 2017
379af12
Fix changing height of Form notifications area
sirbrillig Feb 6, 2017
dae04c6
Change tests so that validate becomes a method on Form
sirbrillig Feb 10, 2017
c63043c
Move model.validate to Form.validate
sirbrillig Feb 10, 2017
8ba065a
Make model.get always explicit
sirbrillig Feb 10, 2017
33ed378
Add tests to be sure two-way binding uses validate
sirbrillig Feb 10, 2017
5f8f62b
Add placeholder for using setState in linkPropertyElements
sirbrillig Feb 10, 2017
02b0a1c
Add tests for destruct and field references
sirbrillig Feb 11, 2017
6bc2e66
Modify createSyncedPropertyValue to use setState
sirbrillig Feb 11, 2017
4f5aa12
Remove fixed todo
sirbrillig Feb 13, 2017
a0cb61f
Fix `properties.container` jsdoc for Form.initialize
sirbrillig Feb 13, 2017
067c045
Replace deprecated name param with field param
westonruter Feb 14, 2017
5d7ccb0
Ensure that id_base is defined on widget form prototypes
westonruter Feb 14, 2017
2688244
Merge props to validate on top of existing model
westonruter Feb 14, 2017
e796fed
Update setState test to better prove validate
sirbrillig Feb 14, 2017
29af225
Add test for early merge of model properties in setState
sirbrillig Feb 14, 2017
2b495c9
Remove unused variable in setState
sirbrillig Feb 14, 2017
a1c9533
Remove id_base from Form tests
sirbrillig Feb 15, 2017
caa5b49
Remove id_base property from Form
sirbrillig Feb 15, 2017
a7f8d07
Remove id_base from core-adapter-widgets
sirbrillig Feb 15, 2017
5194115
Rename validateForm to assertValidForm
westonruter Feb 15, 2017
8562511
Update readme, bump version, add props
westonruter Feb 16, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/*.min.js
**/node_modules/**
**/vendor/**
/tests/js/lib/**
**/*.browserified.js
/bower_components/**
1 change: 1 addition & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"**/*.jsx",
"**/node_modules/**",
"**/vendor/**",
"**/tests/**",
"bower_components/**"
]
}
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**/vendor/**
**/*.jsx
/bower_components/**
/tests/js/**
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install:
- source $DEV_LIB_PATH/travis.install.sh

script:
- npm test
- source $DEV_LIB_PATH/travis.script.sh

after_script:
Expand Down
4 changes: 1 addition & 3 deletions core-adapter-widgets/archives/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ wp.widgets.formConstructor.archives = (function() {
*
* @constructor
*/
ArchivesWidgetForm = wp.widgets.Form.extend( {
id_base: 'archives'
} );
ArchivesWidgetForm = wp.widgets.Form.extend( {} );

if ( 'undefined' !== typeof module ) {
module.exports = ArchivesWidgetForm;
Expand Down
4 changes: 1 addition & 3 deletions core-adapter-widgets/categories/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ wp.widgets.formConstructor.categories = (function() {
*
* @constructor
*/
CategoriesWidgetForm = wp.widgets.Form.extend( {
id_base: 'categories'
} );
CategoriesWidgetForm = wp.widgets.Form.extend( {} );

if ( 'undefined' !== typeof module ) {
module.exports = CategoriesWidgetForm;
Expand Down
2 changes: 1 addition & 1 deletion core-adapter-widgets/tag_cloud/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function render_form_template() {
$taxonomy_choices[ $taxonomy->name ] = $taxonomy->label;
}
$this->render_form_field_template( array(
'name' => 'taxonomy',
'field' => 'taxonomy',
'label' => __( 'Taxonomy:', 'default' ),
'type' => 'select',
'choices' => $taxonomy_choices,
Expand Down
4 changes: 2 additions & 2 deletions js-widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Plugin Name: JS Widgets
* Description: The next generation of widgets in core, embracing JS for UI and powering the Widgets REST API.
* Plugin URI: https://github.com/xwp/wp-js-widgets/
* Version: 0.3.0
* Author: Weston Ruter, XWP
* Version: 0.3.0-beta
* Author: XWP
* Author URI: https://make.xwp.co/
* License: GPLv2+
*
Expand Down
30 changes: 18 additions & 12 deletions js/customize-js-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable complexity */
/* eslint consistent-this: [ "error", "control" ] */

wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-vars
wp.customize.JSWidgets = (function( wp, api, $, _ ) { // eslint-disable-line no-unused-vars
'use strict';

var component = {}, originalInitialize;
Expand All @@ -16,7 +16,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
* @returns {void}
*/
component.init = function initComponent() {
component.extendWidgetControl();
component.extendWidgetControl( api.Widgets.WidgetControl );

// Handle (re-)adding a (previously-removed) control.
api.control.bind( 'add', function( addedControl ) {
Expand Down Expand Up @@ -46,9 +46,10 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
/**
* Inject WidgetControl instances with our component.WidgetControl method overrides.
*
* @returns {void}
* @param {wp.Customize.Widgets.WidgetControl} WidgetControl The constructor function to modify
* @returns {WidgetControl} The constructor function with a modified prototype
*/
component.extendWidgetControl = function extendWidgetControl() {
component.extendWidgetControl = function extendWidgetControl( WidgetControl ) {

/**
* Initialize JS widget control.
Expand All @@ -57,7 +58,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
* @param {object} options Control options.
* @returns {void}
*/
api.Widgets.WidgetControl.prototype.initialize = function initializeWidgetControl( id, options ) {
WidgetControl.prototype.initialize = function initializeWidgetControl( id, options ) {
var control = this, isJsWidget;
isJsWidget = options.params.widget_id_base && 'undefined' !== typeof wp.widgets.formConstructor[ options.params.widget_id_base ];
if ( isJsWidget ) {
Expand All @@ -67,6 +68,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
originalInitialize.call( control, id, options );
}
};
return WidgetControl;
};

/**
Expand All @@ -83,11 +85,11 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
/**
* Initialize.
*
* @param {string} id
* @param {object} options
* @param {object} options.params
* @param {string} options.params.widget_id
* @param {string} options.params.widget_id_base
* @param {string} id The widget id
* @param {object} options The options (see below)
* @param {object} options.params The params (see below)
* @param {string} options.params.widget_id The widget id
* @param {string} options.params.widget_id_base The widget id_base
* @param {string} [options.params.type] - Must be 'widget_form'.
* @param {string} [options.params.content] - This may be supplied by addWidget, but it will not be read since the form is constructed dynamically.
* @param {string} [options.params.widget_control] - Handled internally, if supplied, an error will be thrown.
Expand Down Expand Up @@ -232,7 +234,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
* Submit the widget form via Ajax and get back the updated instance,
* along with the new widget control form to render.
*
* @param {object} [args]
* @param {object} [args] The args to update the widget (see below)
* @param {Object|null} [args.instance=null] When the model changes, the instance is sent here; otherwise, the inputs from the form are used
* @param {Function|null} [args.complete=null] Function which is called when the request finishes. Context is bound to the control. First argument is any error. Following arguments are for success.
* @returns {void}
Expand All @@ -259,6 +261,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
*
* @deprecated
* @private
* @return {void}
*/
_getInputs: function _getInputs() {
throw new Error( 'The _getInputs method should not be called for customize widget instances.' );
Expand All @@ -271,6 +274,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
*
* @deprecated
* @private
* @return {void}
*/
_getInputsSignature: function _getInputsSignature() {
throw new Error( 'The _getInputsSignature method should not be called for customize widget instances.' );
Expand All @@ -283,6 +287,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
*
* @deprecated
* @private
* @return {void}
*/
_getInputState: function _getInputState() {
throw new Error( 'The _getInputState method should not be called for customize widget instances.' );
Expand All @@ -295,6 +300,7 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-
*
* @deprecated
* @private
* @return {void}
*/
_setInputState: function _setInputState() {
throw new Error( 'The _setInputState method should not be called for customize widget instances.' );
Expand All @@ -310,4 +316,4 @@ wp.customize.JSWidgets = (function( api, $ ) { // eslint-disable-line no-unused-

return component;

})( wp.customize, jQuery );
})( wp, wp.customize, jQuery, _ );
Loading