merge trunk

This commit is contained in:
Ron Rennick 2021-04-29 13:47:25 -03:00
commit 00f7e30db5
21 changed files with 1312 additions and 343 deletions

View File

@ -55,8 +55,11 @@ jQuery( function( $ ) {
var wc_country_select_select2 = function() { var wc_country_select_select2 = function() {
$( 'select.country_select:visible, select.state_select:visible' ).each( function() { $( 'select.country_select:visible, select.state_select:visible' ).each( function() {
var $this = $( this );
var select2_args = $.extend({ var select2_args = $.extend({
placeholder: $( this ).attr( 'data-placeholder' ) || $( this ).attr( 'placeholder' ) || '', placeholder: $this.attr( 'data-placeholder' ) || $this.attr( 'placeholder' ) || '',
label: $this.attr( 'data-label' ) || null,
width: '100%' width: '100%'
}, getEnhancedSelectFormatString() ); }, getEnhancedSelectFormatString() );

View File

@ -1,27 +1,41 @@
/*! /*!
* Select2 4.0.3 * SelectWoo 1.0.9
* https://select2.github.io * https://github.com/woocommerce/selectWoo
* *
* Released under the MIT license * Released under the MIT license
* https://github.com/select2/select2/blob/master/LICENSE.md * https://github.com/woocommerce/selectWoo/blob/master/LICENSE.md
*/ */
(function (factory) { (function (factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define(['jquery'], factory); define(['jquery'], factory);
} else if (typeof exports === 'object') { } else if (typeof module === 'object' && module.exports) {
// Node/CommonJS // Node/CommonJS
factory(require('jquery')); module.exports = function (root, jQuery) {
if (jQuery === undefined) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if (typeof window !== 'undefined') {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else { } else {
// Browser globals // Browser globals
factory(jQuery); factory(jQuery);
} }
}(function (jQuery) { } (function (jQuery) {
// This is needed so we can catch the AMD loader configuration and use it // This is needed so we can catch the AMD loader configuration and use it
// The inner file should be wrapped (by `banner.start.js`) in a function that // The inner file should be wrapped (by `banner.start.js`) in a function that
// returns the AMD loader references. // returns the AMD loader references.
var S2 = var S2 =(function () {
(function () {
// Restore the Select2 AMD loader so it can be used // Restore the Select2 AMD loader so it can be used
// Needed mostly in the language files, where the loader is not inserted // Needed mostly in the language files, where the loader is not inserted
if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) { if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) {
@ -30,13 +44,11 @@
var S2;(function () { if (!S2 || !S2.requirejs) { var S2;(function () { if (!S2 || !S2.requirejs) {
if (!S2) { S2 = {}; } else { require = S2; } if (!S2) { S2 = {}; } else { require = S2; }
/** /**
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved. * @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
* Available via the MIT or new BSD license. * Released under MIT license, http://github.com/requirejs/almond/LICENSE
* see: http://github.com/jrburke/almond for details
*/ */
//Going sloppy to avoid 'use strict' string cost, but strict practices should //Going sloppy to avoid 'use strict' string cost, but strict practices should
//be followed. //be followed.
/*jslint sloppy: true */
/*global setTimeout: false */ /*global setTimeout: false */
var requirejs, require, define; var requirejs, require, define;
@ -64,60 +76,58 @@ var requirejs, require, define;
*/ */
function normalize(name, baseName) { function normalize(name, baseName) {
var nameParts, nameSegment, mapValue, foundMap, lastIndex, var nameParts, nameSegment, mapValue, foundMap, lastIndex,
foundI, foundStarMap, starI, i, j, part, foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
baseParts = baseName && baseName.split("/"), baseParts = baseName && baseName.split("/"),
map = config.map, map = config.map,
starMap = (map && map['*']) || {}; starMap = (map && map['*']) || {};
//Adjust any relative paths. //Adjust any relative paths.
if (name && name.charAt(0) === ".") { if (name) {
//If have a base name, try to normalize against it, name = name.split('/');
//otherwise, assume it is a top-level require that will lastIndex = name.length - 1;
//be relative to baseUrl in the end.
if (baseName) {
name = name.split('/');
lastIndex = name.length - 1;
// Node .js allowance: // If wanting node ID compatibility, strip .js from end
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { // of IDs. Have to do this here, and not in nameToUrl
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); // because node allows either .js or non .js to map
} // to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
//Lop off the last part of baseParts, so that . matches the // Starts with a '.' so need the baseName
//"directory" and not name of the baseName's module. For instance, if (name[0].charAt(0) === '.' && baseParts) {
//baseName of "one/two/three", maps to "one/two/three.js", but we //Convert baseName to array, and lop off the last part,
//want the directory, "one/two" for this normalization. //so that . matches that 'directory' and not name of the baseName's
name = baseParts.slice(0, baseParts.length - 1).concat(name); //module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
name = normalizedBaseParts.concat(name);
}
//start trimDots //start trimDots
for (i = 0; i < name.length; i += 1) { for (i = 0; i < name.length; i++) {
part = name[i]; part = name[i];
if (part === ".") { if (part === '.') {
name.splice(i, 1); name.splice(i, 1);
i -= 1; i -= 1;
} else if (part === "..") { } else if (part === '..') {
if (i === 1 && (name[2] === '..' || name[0] === '..')) { // If at the start, or previous value is still ..,
//End of the line. Keep at least one non-dot // keep them so that when converted to a path it may
//path segment at the front so it can be mapped // still work when converted to a path, even though
//correctly to disk. Otherwise, there is likely // as an ID it is less than ideal. In larger point
//no path mapping for a path starting with '..'. // releases, may be better to just kick out an error.
//This can still fail, but catches the most reasonable if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
//uses of .. continue;
break; } else if (i > 0) {
} else if (i > 0) { name.splice(i - 1, 2);
name.splice(i - 1, 2); i -= 2;
i -= 2;
}
} }
} }
//end trimDots
name = name.join("/");
} else if (name.indexOf('./') === 0) {
// No baseName, so this is ID is resolved relative
// to baseUrl, pull off the leading dot.
name = name.substring(2);
} }
//end trimDots
name = name.join('/');
} }
//Apply map config if available. //Apply map config if available.
@ -230,32 +240,39 @@ var requirejs, require, define;
return [prefix, name]; return [prefix, name];
} }
//Creates a parts array for a relName where first part is plugin ID,
//second part is resource ID. Assumes relName has already been normalized.
function makeRelParts(relName) {
return relName ? splitPrefix(relName) : [];
}
/** /**
* Makes a name map, normalizing the name, and using a plugin * Makes a name map, normalizing the name, and using a plugin
* for normalization if necessary. Grabs a ref to plugin * for normalization if necessary. Grabs a ref to plugin
* too, as an optimization. * too, as an optimization.
*/ */
makeMap = function (name, relName) { makeMap = function (name, relParts) {
var plugin, var plugin,
parts = splitPrefix(name), parts = splitPrefix(name),
prefix = parts[0]; prefix = parts[0],
relResourceName = relParts[1];
name = parts[1]; name = parts[1];
if (prefix) { if (prefix) {
prefix = normalize(prefix, relName); prefix = normalize(prefix, relResourceName);
plugin = callDep(prefix); plugin = callDep(prefix);
} }
//Normalize according //Normalize according
if (prefix) { if (prefix) {
if (plugin && plugin.normalize) { if (plugin && plugin.normalize) {
name = plugin.normalize(name, makeNormalize(relName)); name = plugin.normalize(name, makeNormalize(relResourceName));
} else { } else {
name = normalize(name, relName); name = normalize(name, relResourceName);
} }
} else { } else {
name = normalize(name, relName); name = normalize(name, relResourceName);
parts = splitPrefix(name); parts = splitPrefix(name);
prefix = parts[0]; prefix = parts[0];
name = parts[1]; name = parts[1];
@ -302,13 +319,14 @@ var requirejs, require, define;
}; };
main = function (name, deps, callback, relName) { main = function (name, deps, callback, relName) {
var cjsModule, depName, ret, map, i, var cjsModule, depName, ret, map, i, relParts,
args = [], args = [],
callbackType = typeof callback, callbackType = typeof callback,
usingExports; usingExports;
//Use name if no relName //Use name if no relName
relName = relName || name; relName = relName || name;
relParts = makeRelParts(relName);
//Call the callback to define the module, if necessary. //Call the callback to define the module, if necessary.
if (callbackType === 'undefined' || callbackType === 'function') { if (callbackType === 'undefined' || callbackType === 'function') {
@ -317,7 +335,7 @@ var requirejs, require, define;
//Default to [require, exports, module] if no deps //Default to [require, exports, module] if no deps
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
for (i = 0; i < deps.length; i += 1) { for (i = 0; i < deps.length; i += 1) {
map = makeMap(deps[i], relName); map = makeMap(deps[i], relParts);
depName = map.f; depName = map.f;
//Fast path CommonJS standard dependencies. //Fast path CommonJS standard dependencies.
@ -373,7 +391,7 @@ var requirejs, require, define;
//deps arg is the module name, and second arg (if passed) //deps arg is the module name, and second arg (if passed)
//is just the relName. //is just the relName.
//Normalize module name, if it contains . or .. //Normalize module name, if it contains . or ..
return callDep(makeMap(deps, callback).f); return callDep(makeMap(deps, makeRelParts(callback)).f);
} else if (!deps.splice) { } else if (!deps.splice) {
//deps is a config object, not an array. //deps is a config object, not an array.
config = deps; config = deps;
@ -737,6 +755,12 @@ S2.define('select2/utils',[
}); });
}; };
Utils.entityDecode = function (html) {
var txt = document.createElement('textarea');
txt.innerHTML = html;
return txt.value;
}
// Append an array of jQuery nodes to a given element. // Append an array of jQuery nodes to a given element.
Utils.appendMany = function ($element, $nodes) { Utils.appendMany = function ($element, $nodes) {
// jQuery 1.7.x does not support $.fn.append() with an array // jQuery 1.7.x does not support $.fn.append() with an array
@ -754,6 +778,14 @@ S2.define('select2/utils',[
$element.append($nodes); $element.append($nodes);
}; };
// Determine whether the browser is on a touchscreen device.
Utils.isTouchscreen = function() {
if ('undefined' === typeof Utils._isTouchscreenCache) {
Utils._isTouchscreenCache = 'ontouchstart' in document.documentElement;
}
return Utils._isTouchscreenCache;
}
return Utils; return Utils;
}); });
@ -773,7 +805,7 @@ S2.define('select2/results',[
Results.prototype.render = function () { Results.prototype.render = function () {
var $results = $( var $results = $(
'<ul class="select2-results__options" role="tree"></ul>' '<ul class="select2-results__options" role="listbox" tabindex="-1"></ul>'
); );
if (this.options.get('multiple')) { if (this.options.get('multiple')) {
@ -796,7 +828,7 @@ S2.define('select2/results',[
this.hideLoading(); this.hideLoading();
var $message = $( var $message = $(
'<li role="treeitem" aria-live="assertive"' + '<li role="alert" aria-live="assertive"' +
' class="select2-results__option"></li>' ' class="select2-results__option"></li>'
); );
@ -858,9 +890,9 @@ S2.define('select2/results',[
Results.prototype.highlightFirstItem = function () { Results.prototype.highlightFirstItem = function () {
var $options = this.$results var $options = this.$results
.find('.select2-results__option[aria-selected]'); .find('.select2-results__option[data-selected]');
var $selected = $options.filter('[aria-selected=true]'); var $selected = $options.filter('[data-selected=true]');
// Check if there are any selected options // Check if there are any selected options
if ($selected.length > 0) { if ($selected.length > 0) {
@ -884,7 +916,7 @@ S2.define('select2/results',[
}); });
var $options = self.$results var $options = self.$results
.find('.select2-results__option[aria-selected]'); .find('.select2-results__option[data-selected]');
$options.each(function () { $options.each(function () {
var $option = $(this); var $option = $(this);
@ -896,9 +928,9 @@ S2.define('select2/results',[
if ((item.element != null && item.element.selected) || if ((item.element != null && item.element.selected) ||
(item.element == null && $.inArray(id, selectedIds) > -1)) { (item.element == null && $.inArray(id, selectedIds) > -1)) {
$option.attr('aria-selected', 'true'); $option.attr('data-selected', 'true');
} else { } else {
$option.attr('aria-selected', 'false'); $option.attr('data-selected', 'false');
} }
}); });
@ -930,17 +962,18 @@ S2.define('select2/results',[
option.className = 'select2-results__option'; option.className = 'select2-results__option';
var attrs = { var attrs = {
'role': 'treeitem', 'role': 'option',
'aria-selected': 'false' 'data-selected': 'false',
'tabindex': -1
}; };
if (data.disabled) { if (data.disabled) {
delete attrs['aria-selected']; delete attrs['data-selected'];
attrs['aria-disabled'] = 'true'; attrs['aria-disabled'] = 'true';
} }
if (data.id == null) { if (data.id == null) {
delete attrs['aria-selected']; delete attrs['data-selected'];
} }
if (data._resultId != null) { if (data._resultId != null) {
@ -952,9 +985,8 @@ S2.define('select2/results',[
} }
if (data.children) { if (data.children) {
attrs.role = 'group';
attrs['aria-label'] = data.text; attrs['aria-label'] = data.text;
delete attrs['aria-selected']; delete attrs['data-selected'];
} }
for (var attr in attrs) { for (var attr in attrs) {
@ -971,6 +1003,7 @@ S2.define('select2/results',[
var $label = $(label); var $label = $(label);
this.template(data, label); this.template(data, label);
$label.attr('role', 'presentation');
var $children = []; var $children = [];
@ -983,10 +1016,11 @@ S2.define('select2/results',[
} }
var $childrenContainer = $('<ul></ul>', { var $childrenContainer = $('<ul></ul>', {
'class': 'select2-results__options select2-results__options--nested' 'class': 'select2-results__options select2-results__options--nested',
'role': 'listbox'
}); });
$childrenContainer.append($children); $childrenContainer.append($children);
$option.attr('role', 'list');
$option.append(label); $option.append(label);
$option.append($childrenContainer); $option.append($childrenContainer);
@ -1082,7 +1116,7 @@ S2.define('select2/results',[
var data = $highlighted.data('data'); var data = $highlighted.data('data');
if ($highlighted.attr('aria-selected') == 'true') { if ($highlighted.attr('data-selected') == 'true') {
self.trigger('close', {}); self.trigger('close', {});
} else { } else {
self.trigger('select', { self.trigger('select', {
@ -1094,7 +1128,7 @@ S2.define('select2/results',[
container.on('results:previous', function () { container.on('results:previous', function () {
var $highlighted = self.getHighlightedResults(); var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]'); var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted); var currentIndex = $options.index($highlighted);
@ -1128,7 +1162,7 @@ S2.define('select2/results',[
container.on('results:next', function () { container.on('results:next', function () {
var $highlighted = self.getHighlightedResults(); var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]'); var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted); var currentIndex = $options.index($highlighted);
@ -1156,7 +1190,8 @@ S2.define('select2/results',[
}); });
container.on('results:focus', function (params) { container.on('results:focus', function (params) {
params.element.addClass('select2-results__option--highlighted'); params.element.addClass('select2-results__option--highlighted').attr('aria-selected', 'true');
self.$results.attr('aria-activedescendant', params.element.attr('id'));
}); });
container.on('results:message', function (params) { container.on('results:message', function (params) {
@ -1188,13 +1223,13 @@ S2.define('select2/results',[
}); });
} }
this.$results.on('mouseup', '.select2-results__option[aria-selected]', this.$results.on('mouseup', '.select2-results__option[data-selected]',
function (evt) { function (evt) {
var $this = $(this); var $this = $(this);
var data = $this.data('data'); var data = $this.data('data');
if ($this.attr('aria-selected') === 'true') { if ($this.attr('data-selected') === 'true') {
if (self.options.get('multiple')) { if (self.options.get('multiple')) {
self.trigger('unselect', { self.trigger('unselect', {
originalEvent: evt, originalEvent: evt,
@ -1213,12 +1248,13 @@ S2.define('select2/results',[
}); });
}); });
this.$results.on('mouseenter', '.select2-results__option[aria-selected]', this.$results.on('mouseenter', '.select2-results__option[data-selected]',
function (evt) { function (evt) {
var data = $(this).data('data'); var data = $(this).data('data');
self.getHighlightedResults() self.getHighlightedResults()
.removeClass('select2-results__option--highlighted'); .removeClass('select2-results__option--highlighted')
.attr('aria-selected', 'false');
self.trigger('results:focus', { self.trigger('results:focus', {
data: data, data: data,
@ -1245,7 +1281,7 @@ S2.define('select2/results',[
return; return;
} }
var $options = this.$results.find('[aria-selected]'); var $options = this.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted); var currentIndex = $options.index($highlighted);
@ -1323,7 +1359,7 @@ S2.define('select2/selection/base',[
BaseSelection.prototype.render = function () { BaseSelection.prototype.render = function () {
var $selection = $( var $selection = $(
'<span class="select2-selection" role="combobox" ' + '<span class="select2-selection" ' +
' aria-haspopup="true" aria-expanded="false">' + ' aria-haspopup="true" aria-expanded="false">' +
'</span>' '</span>'
); );
@ -1349,6 +1385,7 @@ S2.define('select2/selection/base',[
var id = container.id + '-container'; var id = container.id + '-container';
var resultsId = container.id + '-results'; var resultsId = container.id + '-results';
var searchHidden = this.options.get('minimumResultsForSearch') === Infinity;
this.container = container; this.container = container;
@ -1390,7 +1427,11 @@ S2.define('select2/selection/base',[
self.$selection.removeAttr('aria-activedescendant'); self.$selection.removeAttr('aria-activedescendant');
self.$selection.removeAttr('aria-owns'); self.$selection.removeAttr('aria-owns');
self.$selection.focus(); // This needs to be delayed as the active element is the body when the
// key is pressed.
window.setTimeout(function () {
self.$selection.focus();
}, 1);
self._detachCloseHandler(container); self._detachCloseHandler(container);
}); });
@ -1440,8 +1481,14 @@ S2.define('select2/selection/base',[
} }
var $element = $this.data('element'); var $element = $this.data('element');
$element.select2('close'); $element.select2('close');
// Remove any focus when dropdown is closed by clicking outside the select area.
// Timeout of 1 required for close to finish wrapping up.
setTimeout(function(){
$this.find('*:focus').blur();
$target.focus();
}, 1);
}); });
}); });
}; };
@ -1500,8 +1547,21 @@ S2.define('select2/selection/single',[
var id = container.id + '-container'; var id = container.id + '-container';
this.$selection.find('.select2-selection__rendered').attr('id', id); this.$selection.find('.select2-selection__rendered')
this.$selection.attr('aria-labelledby', id); .attr('id', id)
.attr('role', 'textbox')
.attr('aria-readonly', 'true');
var label = this.options.get( 'label' );
if ( typeof( label ) === 'string' ) {
this.$selection.attr( 'aria-label', label );
} else {
this.$selection.attr( 'aria-labelledby', id );
}
// This makes single non-search selects work in screen readers. If it causes problems elsewhere, remove.
this.$selection.attr('role', 'combobox');
this.$selection.on('mousedown', function (evt) { this.$selection.on('mousedown', function (evt) {
// Only respond to left clicks // Only respond to left clicks
@ -1518,6 +1578,13 @@ S2.define('select2/selection/single',[
// User focuses on the container // User focuses on the container
}); });
this.$selection.on('keydown', function (evt) {
// If user starts typing an alphanumeric key on the keyboard, open if not opened.
if (!container.isOpen() && evt.which >= 48 && evt.which <= 90) {
container.open();
}
});
this.$selection.on('blur', function (evt) { this.$selection.on('blur', function (evt) {
// User exits the container // User exits the container
}); });
@ -1557,9 +1624,9 @@ S2.define('select2/selection/single',[
var selection = data[0]; var selection = data[0];
var $rendered = this.$selection.find('.select2-selection__rendered'); var $rendered = this.$selection.find('.select2-selection__rendered');
var formatted = this.display(selection, $rendered); var formatted = Utils.entityDecode(this.display(selection, $rendered));
$rendered.empty().append(formatted); $rendered.empty().text(formatted);
$rendered.prop('title', selection.title || selection.text); $rendered.prop('title', selection.title || selection.text);
}; };
@ -1583,7 +1650,7 @@ S2.define('select2/selection/multiple',[
$selection.addClass('select2-selection--multiple'); $selection.addClass('select2-selection--multiple');
$selection.html( $selection.html(
'<ul class="select2-selection__rendered"></ul>' '<ul class="select2-selection__rendered" aria-live="polite" aria-relevant="additions removals" aria-atomic="true"></ul>'
); );
return $selection; return $selection;
@ -1620,6 +1687,18 @@ S2.define('select2/selection/multiple',[
}); });
} }
); );
this.$selection.on('keydown', function (evt) {
// If user starts typing an alphanumeric key on the keyboard, open if not opened.
if (!container.isOpen() && evt.which >= 48 && evt.which <= 90) {
container.open();
}
});
// Focus on the search field when the container is focused instead of the main container.
container.on( 'focus', function(){
self.focusOnSearch();
});
}; };
MultipleSelection.prototype.clear = function () { MultipleSelection.prototype.clear = function () {
@ -1636,7 +1715,7 @@ S2.define('select2/selection/multiple',[
MultipleSelection.prototype.selectionContainer = function () { MultipleSelection.prototype.selectionContainer = function () {
var $container = $( var $container = $(
'<li class="select2-selection__choice">' + '<li class="select2-selection__choice">' +
'<span class="select2-selection__choice__remove" role="presentation">' + '<span class="select2-selection__choice__remove" role="presentation" aria-hidden="true">' +
'&times;' + '&times;' +
'</span>' + '</span>' +
'</li>' '</li>'
@ -1645,6 +1724,24 @@ S2.define('select2/selection/multiple',[
return $container; return $container;
}; };
/**
* Focus on the search field instead of the main multiselect container.
*/
MultipleSelection.prototype.focusOnSearch = function() {
var self = this;
if ('undefined' !== typeof self.$search) {
// Needs 1 ms delay because of other 1 ms setTimeouts when rendering.
setTimeout(function(){
// Prevent the dropdown opening again when focused from this.
// This gets reset automatically when focus is triggered.
self._keyUpPrevented = true;
self.$search.focus();
}, 1);
}
}
MultipleSelection.prototype.update = function (data) { MultipleSelection.prototype.update = function (data) {
this.clear(); this.clear();
@ -1658,9 +1755,14 @@ S2.define('select2/selection/multiple',[
var selection = data[d]; var selection = data[d];
var $selection = this.selectionContainer(); var $selection = this.selectionContainer();
var removeItemTag = $selection.html();
var formatted = this.display(selection, $selection); var formatted = this.display(selection, $selection);
if ('string' === typeof formatted) {
formatted = Utils.entityDecode(formatted.trim());
}
$selection.append(formatted); $selection.text(formatted);
$selection.prepend(removeItemTag);
$selection.prop('title', selection.title || selection.text); $selection.prop('title', selection.title || selection.text);
$selection.data('data', selection); $selection.data('data', selection);
@ -1699,7 +1801,7 @@ S2.define('select2/selection/placeholder',[
Placeholder.prototype.createPlaceholder = function (decorated, placeholder) { Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
var $placeholder = this.selectionContainer(); var $placeholder = this.selectionContainer();
$placeholder.html(this.display(placeholder)); $placeholder.text(Utils.entityDecode(this.display(placeholder)));
$placeholder.addClass('select2-selection__placeholder') $placeholder.addClass('select2-selection__placeholder')
.removeClass('select2-selection__choice'); .removeClass('select2-selection__choice');
@ -1836,8 +1938,8 @@ S2.define('select2/selection/search',[
Search.prototype.render = function (decorated) { Search.prototype.render = function (decorated) {
var $search = $( var $search = $(
'<li class="select2-search select2-search--inline">' + '<li class="select2-search select2-search--inline">' +
'<input class="select2-search__field" type="search" tabindex="-1"' + '<input class="select2-search__field" type="text" tabindex="-1"' +
' autocomplete="off" autocorrect="off" autocapitalize="off"' + ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
' spellcheck="false" role="textbox" aria-autocomplete="list" />' + ' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
'</li>' '</li>'
); );
@ -1854,16 +1956,19 @@ S2.define('select2/selection/search',[
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this; var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container); decorated.call(this, container, $container);
container.on('open', function () { container.on('open', function () {
self.$search.attr('aria-owns', resultsId);
self.$search.trigger('focus'); self.$search.trigger('focus');
}); });
container.on('close', function () { container.on('close', function () {
self.$search.val(''); self.$search.val('');
self.$search.removeAttr('aria-activedescendant'); self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.trigger('focus'); self.$search.trigger('focus');
}); });
@ -1882,7 +1987,7 @@ S2.define('select2/selection/search',[
}); });
container.on('results:focus', function (params) { container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.id); self.$search.attr('aria-activedescendant', params.data._resultId);
}); });
this.$selection.on('focusin', '.select2-search--inline', function (evt) { this.$selection.on('focusin', '.select2-search--inline', function (evt) {
@ -1913,6 +2018,9 @@ S2.define('select2/selection/search',[
evt.preventDefault(); evt.preventDefault();
} }
} else if (evt.which === KEYS.ENTER) {
container.open();
evt.preventDefault();
} }
}); });
@ -3004,8 +3112,15 @@ S2.define('select2/data/base',[
}; };
BaseAdapter.prototype.generateResultId = function (container, data) { BaseAdapter.prototype.generateResultId = function (container, data) {
var id = container.id + '-result-'; var id = '';
if (container != null) {
id += container.id
} else {
id += Utils.generateChars(4);
}
id += '-result-';
id += Utils.generateChars(4); id += Utils.generateChars(4);
if (data.id != null) { if (data.id != null) {
@ -3191,7 +3306,7 @@ S2.define('select2/data/select',[
} }
} }
if (data.id) { if (data.id !== undefined) {
option.value = data.id; option.value = data.id;
} }
@ -3289,7 +3404,7 @@ S2.define('select2/data/select',[
item.text = item.text.toString(); item.text = item.text.toString();
} }
if (item._resultId == null && item.id && this.container != null) { if (item._resultId == null && item.id) {
item._resultId = this.generateResultId(this.container, item); item._resultId = this.generateResultId(this.container, item);
} }
@ -3466,6 +3581,7 @@ S2.define('select2/data/ajax',[
} }
callback(results); callback(results);
self.container.focusOnActiveElement();
}, function () { }, function () {
// Attempt to detect if a request was aborted // Attempt to detect if a request was aborted
// Only works if the transport exposes a status property // Only works if the transport exposes a status property
@ -3550,7 +3666,10 @@ S2.define('select2/data/tags',[
}, true) }, true)
); );
var checkText = option.text === params.term; var optionText = (option.text || '').toUpperCase();
var paramsTerm = (params.term || '').toUpperCase();
var checkText = optionText === paramsTerm;
if (checkText || checkChildren) { if (checkText || checkChildren) {
if (child) { if (child) {
@ -3887,9 +4006,9 @@ S2.define('select2/dropdown/search',[
var $search = $( var $search = $(
'<span class="select2-search select2-search--dropdown">' + '<span class="select2-search select2-search--dropdown">' +
'<input class="select2-search__field" type="search" tabindex="-1"' + '<input class="select2-search__field" type="text" tabindex="-1"' +
' autocomplete="off" autocorrect="off" autocapitalize="off"' + ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
' spellcheck="false" role="textbox" />' + ' spellcheck="false" role="combobox" aria-autocomplete="list" aria-expanded="true" />' +
'</span>' '</span>'
); );
@ -3903,6 +4022,7 @@ S2.define('select2/dropdown/search',[
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this; var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container); decorated.call(this, container, $container);
@ -3926,7 +4046,7 @@ S2.define('select2/dropdown/search',[
container.on('open', function () { container.on('open', function () {
self.$search.attr('tabindex', 0); self.$search.attr('tabindex', 0);
self.$search.attr('aria-owns', resultsId);
self.$search.focus(); self.$search.focus();
window.setTimeout(function () { window.setTimeout(function () {
@ -3936,12 +4056,13 @@ S2.define('select2/dropdown/search',[
container.on('close', function () { container.on('close', function () {
self.$search.attr('tabindex', -1); self.$search.attr('tabindex', -1);
self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.val(''); self.$search.val('');
}); });
container.on('focus', function () { container.on('focus', function () {
if (container.isOpen()) { if (!container.isOpen()) {
self.$search.focus(); self.$search.focus();
} }
}); });
@ -3957,6 +4078,10 @@ S2.define('select2/dropdown/search',[
} }
} }
}); });
container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.data._resultId);
});
}; };
Search.prototype.handleSearch = function (evt) { Search.prototype.handleSearch = function (evt) {
@ -4098,7 +4223,7 @@ S2.define('select2/dropdown/infiniteScroll',[
var $option = $( var $option = $(
'<li ' + '<li ' +
'class="select2-results__option select2-results__option--load-more"' + 'class="select2-results__option select2-results__option--load-more"' +
'role="treeitem" aria-disabled="true"></li>' 'role="option" aria-disabled="true"></li>'
); );
var message = this.options.get('translations').get('loadingMore'); var message = this.options.get('translations').get('loadingMore');
@ -5344,16 +5469,22 @@ S2.define('select2/core',[
}); });
}); });
this.on('keypress', function (evt) { this.on('open', function(){
var key = evt.which; // Focus on the active element when opening dropdown.
// Needs 1 ms delay because of other 1 ms setTimeouts when rendering.
setTimeout(function(){
self.focusOnActiveElement();
}, 1);
});
$(document).on('keydown', function (evt) {
var key = evt.which;
if (self.isOpen()) { if (self.isOpen()) {
if (key === KEYS.ESC || key === KEYS.TAB || if (key === KEYS.ESC || (key === KEYS.UP && evt.altKey)) {
(key === KEYS.UP && evt.altKey)) {
self.close(); self.close();
evt.preventDefault(); evt.preventDefault();
} else if (key === KEYS.ENTER) { } else if (key === KEYS.ENTER || key === KEYS.TAB) {
self.trigger('results:select', {}); self.trigger('results:select', {});
evt.preventDefault(); evt.preventDefault();
@ -5370,17 +5501,42 @@ S2.define('select2/core',[
evt.preventDefault(); evt.preventDefault();
} }
} else {
if (key === KEYS.ENTER || key === KEYS.SPACE ||
(key === KEYS.DOWN && evt.altKey)) {
self.open();
var $searchField = self.$dropdown.find('.select2-search__field');
if (! $searchField.length) {
$searchField = self.$container.find('.select2-search__field');
}
// Move the focus to the selected element on keyboard navigation.
// Required for screen readers to work properly.
if (key === KEYS.DOWN || key === KEYS.UP) {
self.focusOnActiveElement();
} else {
// Focus on the search if user starts typing.
$searchField.focus();
// Focus back to active selection when finished typing.
// Small delay so typed character can be read by screen reader.
setTimeout(function(){
self.focusOnActiveElement();
}, 1000);
}
} else if (self.hasFocus()) {
if (key === KEYS.ENTER || key === KEYS.SPACE ||
key === KEYS.DOWN) {
self.open();
evt.preventDefault(); evt.preventDefault();
} }
} }
}); });
}; };
Select2.prototype.focusOnActiveElement = function () {
// Don't mess with the focus on touchscreens because it causes havoc with on-screen keyboards.
if (this.isOpen() && ! Utils.isTouchscreen()) {
this.$results.find('li.select2-results__option--highlighted').focus();
}
};
Select2.prototype._syncAttributes = function () { Select2.prototype._syncAttributes = function () {
this.options.set('disabled', this.$element.prop('disabled')); this.options.set('disabled', this.$element.prop('disabled'));
@ -6364,11 +6520,11 @@ S2.define('jquery.select2',[
'./select2/core', './select2/core',
'./select2/defaults' './select2/defaults'
], function ($, _, Select2, Defaults) { ], function ($, _, Select2, Defaults) {
if ($.fn.select2 == null) { if ($.fn.selectWoo == null) {
// All methods that should return the element // All methods that should return the element
var thisMethods = ['open', 'close', 'destroy']; var thisMethods = ['open', 'close', 'destroy'];
$.fn.select2 = function (options) { $.fn.selectWoo = function (options) {
options = options || {}; options = options || {};
if (typeof options === 'object') { if (typeof options === 'object') {
@ -6408,10 +6564,17 @@ S2.define('jquery.select2',[
}; };
} }
if ($.fn.select2.defaults == null) { if ($.fn.select2 != null && $.fn.select2.defaults != null) {
$.fn.select2.defaults = Defaults; $.fn.selectWoo.defaults = $.fn.select2.defaults;
} }
if ($.fn.selectWoo.defaults == null) {
$.fn.selectWoo.defaults = Defaults;
}
// Also register selectWoo under select2 if select2 is not already present.
$.fn.select2 = $.fn.select2 || $.fn.selectWoo;
return Select2; return Select2;
}); });
@ -6430,6 +6593,7 @@ S2.define('jquery.select2',[
// This allows Select2 to use the internal loader outside of this file, such // This allows Select2 to use the internal loader outside of this file, such
// as in the language files. // as in the language files.
jQuery.fn.select2.amd = S2; jQuery.fn.select2.amd = S2;
jQuery.fn.selectWoo.amd = S2;
// Return the Select2 instance for anyone who is importing it. // Return the Select2 instance for anyone who is importing it.
return select2; return select2;

View File

@ -1,27 +1,41 @@
/*! /*!
* Select2 4.0.3 * SelectWoo 1.0.9
* https://select2.github.io * https://github.com/woocommerce/selectWoo
* *
* Released under the MIT license * Released under the MIT license
* https://github.com/select2/select2/blob/master/LICENSE.md * https://github.com/woocommerce/selectWoo/blob/master/LICENSE.md
*/ */
(function (factory) { (function (factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define(['jquery'], factory); define(['jquery'], factory);
} else if (typeof exports === 'object') { } else if (typeof module === 'object' && module.exports) {
// Node/CommonJS // Node/CommonJS
factory(require('jquery')); module.exports = function (root, jQuery) {
if (jQuery === undefined) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if (typeof window !== 'undefined') {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else { } else {
// Browser globals // Browser globals
factory(jQuery); factory(jQuery);
} }
}(function (jQuery) { } (function (jQuery) {
// This is needed so we can catch the AMD loader configuration and use it // This is needed so we can catch the AMD loader configuration and use it
// The inner file should be wrapped (by `banner.start.js`) in a function that // The inner file should be wrapped (by `banner.start.js`) in a function that
// returns the AMD loader references. // returns the AMD loader references.
var S2 = var S2 =(function () {
(function () {
// Restore the Select2 AMD loader so it can be used // Restore the Select2 AMD loader so it can be used
// Needed mostly in the language files, where the loader is not inserted // Needed mostly in the language files, where the loader is not inserted
if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) { if (jQuery && jQuery.fn && jQuery.fn.select2 && jQuery.fn.select2.amd) {
@ -30,13 +44,11 @@
var S2;(function () { if (!S2 || !S2.requirejs) { var S2;(function () { if (!S2 || !S2.requirejs) {
if (!S2) { S2 = {}; } else { require = S2; } if (!S2) { S2 = {}; } else { require = S2; }
/** /**
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved. * @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
* Available via the MIT or new BSD license. * Released under MIT license, http://github.com/requirejs/almond/LICENSE
* see: http://github.com/jrburke/almond for details
*/ */
//Going sloppy to avoid 'use strict' string cost, but strict practices should //Going sloppy to avoid 'use strict' string cost, but strict practices should
//be followed. //be followed.
/*jslint sloppy: true */
/*global setTimeout: false */ /*global setTimeout: false */
var requirejs, require, define; var requirejs, require, define;
@ -64,60 +76,58 @@ var requirejs, require, define;
*/ */
function normalize(name, baseName) { function normalize(name, baseName) {
var nameParts, nameSegment, mapValue, foundMap, lastIndex, var nameParts, nameSegment, mapValue, foundMap, lastIndex,
foundI, foundStarMap, starI, i, j, part, foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
baseParts = baseName && baseName.split("/"), baseParts = baseName && baseName.split("/"),
map = config.map, map = config.map,
starMap = (map && map['*']) || {}; starMap = (map && map['*']) || {};
//Adjust any relative paths. //Adjust any relative paths.
if (name && name.charAt(0) === ".") { if (name) {
//If have a base name, try to normalize against it, name = name.split('/');
//otherwise, assume it is a top-level require that will lastIndex = name.length - 1;
//be relative to baseUrl in the end.
if (baseName) {
name = name.split('/');
lastIndex = name.length - 1;
// Node .js allowance: // If wanting node ID compatibility, strip .js from end
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { // of IDs. Have to do this here, and not in nameToUrl
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); // because node allows either .js or non .js to map
} // to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
//Lop off the last part of baseParts, so that . matches the // Starts with a '.' so need the baseName
//"directory" and not name of the baseName's module. For instance, if (name[0].charAt(0) === '.' && baseParts) {
//baseName of "one/two/three", maps to "one/two/three.js", but we //Convert baseName to array, and lop off the last part,
//want the directory, "one/two" for this normalization. //so that . matches that 'directory' and not name of the baseName's
name = baseParts.slice(0, baseParts.length - 1).concat(name); //module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
name = normalizedBaseParts.concat(name);
}
//start trimDots //start trimDots
for (i = 0; i < name.length; i += 1) { for (i = 0; i < name.length; i++) {
part = name[i]; part = name[i];
if (part === ".") { if (part === '.') {
name.splice(i, 1); name.splice(i, 1);
i -= 1; i -= 1;
} else if (part === "..") { } else if (part === '..') {
if (i === 1 && (name[2] === '..' || name[0] === '..')) { // If at the start, or previous value is still ..,
//End of the line. Keep at least one non-dot // keep them so that when converted to a path it may
//path segment at the front so it can be mapped // still work when converted to a path, even though
//correctly to disk. Otherwise, there is likely // as an ID it is less than ideal. In larger point
//no path mapping for a path starting with '..'. // releases, may be better to just kick out an error.
//This can still fail, but catches the most reasonable if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
//uses of .. continue;
break; } else if (i > 0) {
} else if (i > 0) { name.splice(i - 1, 2);
name.splice(i - 1, 2); i -= 2;
i -= 2;
}
} }
} }
//end trimDots
name = name.join("/");
} else if (name.indexOf('./') === 0) {
// No baseName, so this is ID is resolved relative
// to baseUrl, pull off the leading dot.
name = name.substring(2);
} }
//end trimDots
name = name.join('/');
} }
//Apply map config if available. //Apply map config if available.
@ -230,32 +240,39 @@ var requirejs, require, define;
return [prefix, name]; return [prefix, name];
} }
//Creates a parts array for a relName where first part is plugin ID,
//second part is resource ID. Assumes relName has already been normalized.
function makeRelParts(relName) {
return relName ? splitPrefix(relName) : [];
}
/** /**
* Makes a name map, normalizing the name, and using a plugin * Makes a name map, normalizing the name, and using a plugin
* for normalization if necessary. Grabs a ref to plugin * for normalization if necessary. Grabs a ref to plugin
* too, as an optimization. * too, as an optimization.
*/ */
makeMap = function (name, relName) { makeMap = function (name, relParts) {
var plugin, var plugin,
parts = splitPrefix(name), parts = splitPrefix(name),
prefix = parts[0]; prefix = parts[0],
relResourceName = relParts[1];
name = parts[1]; name = parts[1];
if (prefix) { if (prefix) {
prefix = normalize(prefix, relName); prefix = normalize(prefix, relResourceName);
plugin = callDep(prefix); plugin = callDep(prefix);
} }
//Normalize according //Normalize according
if (prefix) { if (prefix) {
if (plugin && plugin.normalize) { if (plugin && plugin.normalize) {
name = plugin.normalize(name, makeNormalize(relName)); name = plugin.normalize(name, makeNormalize(relResourceName));
} else { } else {
name = normalize(name, relName); name = normalize(name, relResourceName);
} }
} else { } else {
name = normalize(name, relName); name = normalize(name, relResourceName);
parts = splitPrefix(name); parts = splitPrefix(name);
prefix = parts[0]; prefix = parts[0];
name = parts[1]; name = parts[1];
@ -302,13 +319,14 @@ var requirejs, require, define;
}; };
main = function (name, deps, callback, relName) { main = function (name, deps, callback, relName) {
var cjsModule, depName, ret, map, i, var cjsModule, depName, ret, map, i, relParts,
args = [], args = [],
callbackType = typeof callback, callbackType = typeof callback,
usingExports; usingExports;
//Use name if no relName //Use name if no relName
relName = relName || name; relName = relName || name;
relParts = makeRelParts(relName);
//Call the callback to define the module, if necessary. //Call the callback to define the module, if necessary.
if (callbackType === 'undefined' || callbackType === 'function') { if (callbackType === 'undefined' || callbackType === 'function') {
@ -317,7 +335,7 @@ var requirejs, require, define;
//Default to [require, exports, module] if no deps //Default to [require, exports, module] if no deps
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
for (i = 0; i < deps.length; i += 1) { for (i = 0; i < deps.length; i += 1) {
map = makeMap(deps[i], relName); map = makeMap(deps[i], relParts);
depName = map.f; depName = map.f;
//Fast path CommonJS standard dependencies. //Fast path CommonJS standard dependencies.
@ -373,7 +391,7 @@ var requirejs, require, define;
//deps arg is the module name, and second arg (if passed) //deps arg is the module name, and second arg (if passed)
//is just the relName. //is just the relName.
//Normalize module name, if it contains . or .. //Normalize module name, if it contains . or ..
return callDep(makeMap(deps, callback).f); return callDep(makeMap(deps, makeRelParts(callback)).f);
} else if (!deps.splice) { } else if (!deps.splice) {
//deps is a config object, not an array. //deps is a config object, not an array.
config = deps; config = deps;
@ -737,6 +755,12 @@ S2.define('select2/utils',[
}); });
}; };
Utils.entityDecode = function (html) {
var txt = document.createElement('textarea');
txt.innerHTML = html;
return txt.value;
}
// Append an array of jQuery nodes to a given element. // Append an array of jQuery nodes to a given element.
Utils.appendMany = function ($element, $nodes) { Utils.appendMany = function ($element, $nodes) {
// jQuery 1.7.x does not support $.fn.append() with an array // jQuery 1.7.x does not support $.fn.append() with an array
@ -754,6 +778,14 @@ S2.define('select2/utils',[
$element.append($nodes); $element.append($nodes);
}; };
// Determine whether the browser is on a touchscreen device.
Utils.isTouchscreen = function() {
if ('undefined' === typeof Utils._isTouchscreenCache) {
Utils._isTouchscreenCache = 'ontouchstart' in document.documentElement;
}
return Utils._isTouchscreenCache;
}
return Utils; return Utils;
}); });
@ -773,7 +805,7 @@ S2.define('select2/results',[
Results.prototype.render = function () { Results.prototype.render = function () {
var $results = $( var $results = $(
'<ul class="select2-results__options" role="tree"></ul>' '<ul class="select2-results__options" role="listbox" tabindex="-1"></ul>'
); );
if (this.options.get('multiple')) { if (this.options.get('multiple')) {
@ -796,7 +828,7 @@ S2.define('select2/results',[
this.hideLoading(); this.hideLoading();
var $message = $( var $message = $(
'<li role="treeitem" aria-live="assertive"' + '<li role="alert" aria-live="assertive"' +
' class="select2-results__option"></li>' ' class="select2-results__option"></li>'
); );
@ -858,9 +890,9 @@ S2.define('select2/results',[
Results.prototype.highlightFirstItem = function () { Results.prototype.highlightFirstItem = function () {
var $options = this.$results var $options = this.$results
.find('.select2-results__option[aria-selected]'); .find('.select2-results__option[data-selected]');
var $selected = $options.filter('[aria-selected=true]'); var $selected = $options.filter('[data-selected=true]');
// Check if there are any selected options // Check if there are any selected options
if ($selected.length > 0) { if ($selected.length > 0) {
@ -884,7 +916,7 @@ S2.define('select2/results',[
}); });
var $options = self.$results var $options = self.$results
.find('.select2-results__option[aria-selected]'); .find('.select2-results__option[data-selected]');
$options.each(function () { $options.each(function () {
var $option = $(this); var $option = $(this);
@ -896,9 +928,9 @@ S2.define('select2/results',[
if ((item.element != null && item.element.selected) || if ((item.element != null && item.element.selected) ||
(item.element == null && $.inArray(id, selectedIds) > -1)) { (item.element == null && $.inArray(id, selectedIds) > -1)) {
$option.attr('aria-selected', 'true'); $option.attr('data-selected', 'true');
} else { } else {
$option.attr('aria-selected', 'false'); $option.attr('data-selected', 'false');
} }
}); });
@ -930,17 +962,18 @@ S2.define('select2/results',[
option.className = 'select2-results__option'; option.className = 'select2-results__option';
var attrs = { var attrs = {
'role': 'treeitem', 'role': 'option',
'aria-selected': 'false' 'data-selected': 'false',
'tabindex': -1
}; };
if (data.disabled) { if (data.disabled) {
delete attrs['aria-selected']; delete attrs['data-selected'];
attrs['aria-disabled'] = 'true'; attrs['aria-disabled'] = 'true';
} }
if (data.id == null) { if (data.id == null) {
delete attrs['aria-selected']; delete attrs['data-selected'];
} }
if (data._resultId != null) { if (data._resultId != null) {
@ -952,9 +985,8 @@ S2.define('select2/results',[
} }
if (data.children) { if (data.children) {
attrs.role = 'group';
attrs['aria-label'] = data.text; attrs['aria-label'] = data.text;
delete attrs['aria-selected']; delete attrs['data-selected'];
} }
for (var attr in attrs) { for (var attr in attrs) {
@ -971,6 +1003,7 @@ S2.define('select2/results',[
var $label = $(label); var $label = $(label);
this.template(data, label); this.template(data, label);
$label.attr('role', 'presentation');
var $children = []; var $children = [];
@ -983,10 +1016,11 @@ S2.define('select2/results',[
} }
var $childrenContainer = $('<ul></ul>', { var $childrenContainer = $('<ul></ul>', {
'class': 'select2-results__options select2-results__options--nested' 'class': 'select2-results__options select2-results__options--nested',
'role': 'listbox'
}); });
$childrenContainer.append($children); $childrenContainer.append($children);
$option.attr('role', 'list');
$option.append(label); $option.append(label);
$option.append($childrenContainer); $option.append($childrenContainer);
@ -1082,7 +1116,7 @@ S2.define('select2/results',[
var data = $highlighted.data('data'); var data = $highlighted.data('data');
if ($highlighted.attr('aria-selected') == 'true') { if ($highlighted.attr('data-selected') == 'true') {
self.trigger('close', {}); self.trigger('close', {});
} else { } else {
self.trigger('select', { self.trigger('select', {
@ -1094,7 +1128,7 @@ S2.define('select2/results',[
container.on('results:previous', function () { container.on('results:previous', function () {
var $highlighted = self.getHighlightedResults(); var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]'); var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted); var currentIndex = $options.index($highlighted);
@ -1128,7 +1162,7 @@ S2.define('select2/results',[
container.on('results:next', function () { container.on('results:next', function () {
var $highlighted = self.getHighlightedResults(); var $highlighted = self.getHighlightedResults();
var $options = self.$results.find('[aria-selected]'); var $options = self.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted); var currentIndex = $options.index($highlighted);
@ -1156,7 +1190,8 @@ S2.define('select2/results',[
}); });
container.on('results:focus', function (params) { container.on('results:focus', function (params) {
params.element.addClass('select2-results__option--highlighted'); params.element.addClass('select2-results__option--highlighted').attr('aria-selected', 'true');
self.$results.attr('aria-activedescendant', params.element.attr('id'));
}); });
container.on('results:message', function (params) { container.on('results:message', function (params) {
@ -1188,13 +1223,13 @@ S2.define('select2/results',[
}); });
} }
this.$results.on('mouseup', '.select2-results__option[aria-selected]', this.$results.on('mouseup', '.select2-results__option[data-selected]',
function (evt) { function (evt) {
var $this = $(this); var $this = $(this);
var data = $this.data('data'); var data = $this.data('data');
if ($this.attr('aria-selected') === 'true') { if ($this.attr('data-selected') === 'true') {
if (self.options.get('multiple')) { if (self.options.get('multiple')) {
self.trigger('unselect', { self.trigger('unselect', {
originalEvent: evt, originalEvent: evt,
@ -1213,12 +1248,13 @@ S2.define('select2/results',[
}); });
}); });
this.$results.on('mouseenter', '.select2-results__option[aria-selected]', this.$results.on('mouseenter', '.select2-results__option[data-selected]',
function (evt) { function (evt) {
var data = $(this).data('data'); var data = $(this).data('data');
self.getHighlightedResults() self.getHighlightedResults()
.removeClass('select2-results__option--highlighted'); .removeClass('select2-results__option--highlighted')
.attr('aria-selected', 'false');
self.trigger('results:focus', { self.trigger('results:focus', {
data: data, data: data,
@ -1245,7 +1281,7 @@ S2.define('select2/results',[
return; return;
} }
var $options = this.$results.find('[aria-selected]'); var $options = this.$results.find('[data-selected]');
var currentIndex = $options.index($highlighted); var currentIndex = $options.index($highlighted);
@ -1323,7 +1359,7 @@ S2.define('select2/selection/base',[
BaseSelection.prototype.render = function () { BaseSelection.prototype.render = function () {
var $selection = $( var $selection = $(
'<span class="select2-selection" role="combobox" ' + '<span class="select2-selection" ' +
' aria-haspopup="true" aria-expanded="false">' + ' aria-haspopup="true" aria-expanded="false">' +
'</span>' '</span>'
); );
@ -1349,6 +1385,7 @@ S2.define('select2/selection/base',[
var id = container.id + '-container'; var id = container.id + '-container';
var resultsId = container.id + '-results'; var resultsId = container.id + '-results';
var searchHidden = this.options.get('minimumResultsForSearch') === Infinity;
this.container = container; this.container = container;
@ -1390,7 +1427,11 @@ S2.define('select2/selection/base',[
self.$selection.removeAttr('aria-activedescendant'); self.$selection.removeAttr('aria-activedescendant');
self.$selection.removeAttr('aria-owns'); self.$selection.removeAttr('aria-owns');
self.$selection.focus(); // This needs to be delayed as the active element is the body when the
// key is pressed.
window.setTimeout(function () {
self.$selection.focus();
}, 1);
self._detachCloseHandler(container); self._detachCloseHandler(container);
}); });
@ -1440,8 +1481,14 @@ S2.define('select2/selection/base',[
} }
var $element = $this.data('element'); var $element = $this.data('element');
$element.select2('close'); $element.select2('close');
// Remove any focus when dropdown is closed by clicking outside the select area.
// Timeout of 1 required for close to finish wrapping up.
setTimeout(function(){
$this.find('*:focus').blur();
$target.focus();
}, 1);
}); });
}); });
}; };
@ -1500,8 +1547,21 @@ S2.define('select2/selection/single',[
var id = container.id + '-container'; var id = container.id + '-container';
this.$selection.find('.select2-selection__rendered').attr('id', id); this.$selection.find('.select2-selection__rendered')
this.$selection.attr('aria-labelledby', id); .attr('id', id)
.attr('role', 'textbox')
.attr('aria-readonly', 'true');
var label = this.options.get( 'label' );
if ( typeof( label ) === 'string' ) {
this.$selection.attr( 'aria-label', label );
} else {
this.$selection.attr( 'aria-labelledby', id );
}
// This makes single non-search selects work in screen readers. If it causes problems elsewhere, remove.
this.$selection.attr('role', 'combobox');
this.$selection.on('mousedown', function (evt) { this.$selection.on('mousedown', function (evt) {
// Only respond to left clicks // Only respond to left clicks
@ -1518,6 +1578,13 @@ S2.define('select2/selection/single',[
// User focuses on the container // User focuses on the container
}); });
this.$selection.on('keydown', function (evt) {
// If user starts typing an alphanumeric key on the keyboard, open if not opened.
if (!container.isOpen() && evt.which >= 48 && evt.which <= 90) {
container.open();
}
});
this.$selection.on('blur', function (evt) { this.$selection.on('blur', function (evt) {
// User exits the container // User exits the container
}); });
@ -1557,9 +1624,9 @@ S2.define('select2/selection/single',[
var selection = data[0]; var selection = data[0];
var $rendered = this.$selection.find('.select2-selection__rendered'); var $rendered = this.$selection.find('.select2-selection__rendered');
var formatted = this.display(selection, $rendered); var formatted = Utils.entityDecode(this.display(selection, $rendered));
$rendered.empty().append(formatted); $rendered.empty().text(formatted);
$rendered.prop('title', selection.title || selection.text); $rendered.prop('title', selection.title || selection.text);
}; };
@ -1583,7 +1650,7 @@ S2.define('select2/selection/multiple',[
$selection.addClass('select2-selection--multiple'); $selection.addClass('select2-selection--multiple');
$selection.html( $selection.html(
'<ul class="select2-selection__rendered"></ul>' '<ul class="select2-selection__rendered" aria-live="polite" aria-relevant="additions removals" aria-atomic="true"></ul>'
); );
return $selection; return $selection;
@ -1620,6 +1687,18 @@ S2.define('select2/selection/multiple',[
}); });
} }
); );
this.$selection.on('keydown', function (evt) {
// If user starts typing an alphanumeric key on the keyboard, open if not opened.
if (!container.isOpen() && evt.which >= 48 && evt.which <= 90) {
container.open();
}
});
// Focus on the search field when the container is focused instead of the main container.
container.on( 'focus', function(){
self.focusOnSearch();
});
}; };
MultipleSelection.prototype.clear = function () { MultipleSelection.prototype.clear = function () {
@ -1636,7 +1715,7 @@ S2.define('select2/selection/multiple',[
MultipleSelection.prototype.selectionContainer = function () { MultipleSelection.prototype.selectionContainer = function () {
var $container = $( var $container = $(
'<li class="select2-selection__choice">' + '<li class="select2-selection__choice">' +
'<span class="select2-selection__choice__remove" role="presentation">' + '<span class="select2-selection__choice__remove" role="presentation" aria-hidden="true">' +
'&times;' + '&times;' +
'</span>' + '</span>' +
'</li>' '</li>'
@ -1645,6 +1724,24 @@ S2.define('select2/selection/multiple',[
return $container; return $container;
}; };
/**
* Focus on the search field instead of the main multiselect container.
*/
MultipleSelection.prototype.focusOnSearch = function() {
var self = this;
if ('undefined' !== typeof self.$search) {
// Needs 1 ms delay because of other 1 ms setTimeouts when rendering.
setTimeout(function(){
// Prevent the dropdown opening again when focused from this.
// This gets reset automatically when focus is triggered.
self._keyUpPrevented = true;
self.$search.focus();
}, 1);
}
}
MultipleSelection.prototype.update = function (data) { MultipleSelection.prototype.update = function (data) {
this.clear(); this.clear();
@ -1658,9 +1755,14 @@ S2.define('select2/selection/multiple',[
var selection = data[d]; var selection = data[d];
var $selection = this.selectionContainer(); var $selection = this.selectionContainer();
var removeItemTag = $selection.html();
var formatted = this.display(selection, $selection); var formatted = this.display(selection, $selection);
if ('string' === typeof formatted) {
formatted = Utils.entityDecode(formatted.trim());
}
$selection.append(formatted); $selection.text(formatted);
$selection.prepend(removeItemTag);
$selection.prop('title', selection.title || selection.text); $selection.prop('title', selection.title || selection.text);
$selection.data('data', selection); $selection.data('data', selection);
@ -1699,7 +1801,7 @@ S2.define('select2/selection/placeholder',[
Placeholder.prototype.createPlaceholder = function (decorated, placeholder) { Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
var $placeholder = this.selectionContainer(); var $placeholder = this.selectionContainer();
$placeholder.html(this.display(placeholder)); $placeholder.text(Utils.entityDecode(this.display(placeholder)));
$placeholder.addClass('select2-selection__placeholder') $placeholder.addClass('select2-selection__placeholder')
.removeClass('select2-selection__choice'); .removeClass('select2-selection__choice');
@ -1836,8 +1938,8 @@ S2.define('select2/selection/search',[
Search.prototype.render = function (decorated) { Search.prototype.render = function (decorated) {
var $search = $( var $search = $(
'<li class="select2-search select2-search--inline">' + '<li class="select2-search select2-search--inline">' +
'<input class="select2-search__field" type="search" tabindex="-1"' + '<input class="select2-search__field" type="text" tabindex="-1"' +
' autocomplete="off" autocorrect="off" autocapitalize="off"' + ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
' spellcheck="false" role="textbox" aria-autocomplete="list" />' + ' spellcheck="false" role="textbox" aria-autocomplete="list" />' +
'</li>' '</li>'
); );
@ -1854,16 +1956,19 @@ S2.define('select2/selection/search',[
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this; var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container); decorated.call(this, container, $container);
container.on('open', function () { container.on('open', function () {
self.$search.attr('aria-owns', resultsId);
self.$search.trigger('focus'); self.$search.trigger('focus');
}); });
container.on('close', function () { container.on('close', function () {
self.$search.val(''); self.$search.val('');
self.$search.removeAttr('aria-activedescendant'); self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.trigger('focus'); self.$search.trigger('focus');
}); });
@ -1882,7 +1987,7 @@ S2.define('select2/selection/search',[
}); });
container.on('results:focus', function (params) { container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.id); self.$search.attr('aria-activedescendant', params.data._resultId);
}); });
this.$selection.on('focusin', '.select2-search--inline', function (evt) { this.$selection.on('focusin', '.select2-search--inline', function (evt) {
@ -1913,6 +2018,9 @@ S2.define('select2/selection/search',[
evt.preventDefault(); evt.preventDefault();
} }
} else if (evt.which === KEYS.ENTER) {
container.open();
evt.preventDefault();
} }
}); });
@ -3004,8 +3112,15 @@ S2.define('select2/data/base',[
}; };
BaseAdapter.prototype.generateResultId = function (container, data) { BaseAdapter.prototype.generateResultId = function (container, data) {
var id = container.id + '-result-'; var id = '';
if (container != null) {
id += container.id
} else {
id += Utils.generateChars(4);
}
id += '-result-';
id += Utils.generateChars(4); id += Utils.generateChars(4);
if (data.id != null) { if (data.id != null) {
@ -3191,7 +3306,7 @@ S2.define('select2/data/select',[
} }
} }
if (data.id) { if (data.id !== undefined) {
option.value = data.id; option.value = data.id;
} }
@ -3289,7 +3404,7 @@ S2.define('select2/data/select',[
item.text = item.text.toString(); item.text = item.text.toString();
} }
if (item._resultId == null && item.id && this.container != null) { if (item._resultId == null && item.id) {
item._resultId = this.generateResultId(this.container, item); item._resultId = this.generateResultId(this.container, item);
} }
@ -3466,6 +3581,7 @@ S2.define('select2/data/ajax',[
} }
callback(results); callback(results);
self.container.focusOnActiveElement();
}, function () { }, function () {
// Attempt to detect if a request was aborted // Attempt to detect if a request was aborted
// Only works if the transport exposes a status property // Only works if the transport exposes a status property
@ -3550,7 +3666,10 @@ S2.define('select2/data/tags',[
}, true) }, true)
); );
var checkText = option.text === params.term; var optionText = (option.text || '').toUpperCase();
var paramsTerm = (params.term || '').toUpperCase();
var checkText = optionText === paramsTerm;
if (checkText || checkChildren) { if (checkText || checkChildren) {
if (child) { if (child) {
@ -3887,9 +4006,9 @@ S2.define('select2/dropdown/search',[
var $search = $( var $search = $(
'<span class="select2-search select2-search--dropdown">' + '<span class="select2-search select2-search--dropdown">' +
'<input class="select2-search__field" type="search" tabindex="-1"' + '<input class="select2-search__field" type="text" tabindex="-1"' +
' autocomplete="off" autocorrect="off" autocapitalize="off"' + ' autocomplete="off" autocorrect="off" autocapitalize="none"' +
' spellcheck="false" role="textbox" />' + ' spellcheck="false" role="combobox" aria-autocomplete="list" aria-expanded="true" />' +
'</span>' '</span>'
); );
@ -3903,6 +4022,7 @@ S2.define('select2/dropdown/search',[
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this; var self = this;
var resultsId = container.id + '-results';
decorated.call(this, container, $container); decorated.call(this, container, $container);
@ -3926,7 +4046,7 @@ S2.define('select2/dropdown/search',[
container.on('open', function () { container.on('open', function () {
self.$search.attr('tabindex', 0); self.$search.attr('tabindex', 0);
self.$search.attr('aria-owns', resultsId);
self.$search.focus(); self.$search.focus();
window.setTimeout(function () { window.setTimeout(function () {
@ -3936,12 +4056,13 @@ S2.define('select2/dropdown/search',[
container.on('close', function () { container.on('close', function () {
self.$search.attr('tabindex', -1); self.$search.attr('tabindex', -1);
self.$search.removeAttr('aria-activedescendant');
self.$search.removeAttr('aria-owns');
self.$search.val(''); self.$search.val('');
}); });
container.on('focus', function () { container.on('focus', function () {
if (container.isOpen()) { if (!container.isOpen()) {
self.$search.focus(); self.$search.focus();
} }
}); });
@ -3957,6 +4078,10 @@ S2.define('select2/dropdown/search',[
} }
} }
}); });
container.on('results:focus', function (params) {
self.$search.attr('aria-activedescendant', params.data._resultId);
});
}; };
Search.prototype.handleSearch = function (evt) { Search.prototype.handleSearch = function (evt) {
@ -4098,7 +4223,7 @@ S2.define('select2/dropdown/infiniteScroll',[
var $option = $( var $option = $(
'<li ' + '<li ' +
'class="select2-results__option select2-results__option--load-more"' + 'class="select2-results__option select2-results__option--load-more"' +
'role="treeitem" aria-disabled="true"></li>' 'role="option" aria-disabled="true"></li>'
); );
var message = this.options.get('translations').get('loadingMore'); var message = this.options.get('translations').get('loadingMore');
@ -5344,16 +5469,22 @@ S2.define('select2/core',[
}); });
}); });
this.on('keypress', function (evt) { this.on('open', function(){
var key = evt.which; // Focus on the active element when opening dropdown.
// Needs 1 ms delay because of other 1 ms setTimeouts when rendering.
setTimeout(function(){
self.focusOnActiveElement();
}, 1);
});
$(document).on('keydown', function (evt) {
var key = evt.which;
if (self.isOpen()) { if (self.isOpen()) {
if (key === KEYS.ESC || key === KEYS.TAB || if (key === KEYS.ESC || (key === KEYS.UP && evt.altKey)) {
(key === KEYS.UP && evt.altKey)) {
self.close(); self.close();
evt.preventDefault(); evt.preventDefault();
} else if (key === KEYS.ENTER) { } else if (key === KEYS.ENTER || key === KEYS.TAB) {
self.trigger('results:select', {}); self.trigger('results:select', {});
evt.preventDefault(); evt.preventDefault();
@ -5370,17 +5501,42 @@ S2.define('select2/core',[
evt.preventDefault(); evt.preventDefault();
} }
} else {
if (key === KEYS.ENTER || key === KEYS.SPACE ||
(key === KEYS.DOWN && evt.altKey)) {
self.open();
var $searchField = self.$dropdown.find('.select2-search__field');
if (! $searchField.length) {
$searchField = self.$container.find('.select2-search__field');
}
// Move the focus to the selected element on keyboard navigation.
// Required for screen readers to work properly.
if (key === KEYS.DOWN || key === KEYS.UP) {
self.focusOnActiveElement();
} else {
// Focus on the search if user starts typing.
$searchField.focus();
// Focus back to active selection when finished typing.
// Small delay so typed character can be read by screen reader.
setTimeout(function(){
self.focusOnActiveElement();
}, 1000);
}
} else if (self.hasFocus()) {
if (key === KEYS.ENTER || key === KEYS.SPACE ||
key === KEYS.DOWN) {
self.open();
evt.preventDefault(); evt.preventDefault();
} }
} }
}); });
}; };
Select2.prototype.focusOnActiveElement = function () {
// Don't mess with the focus on touchscreens because it causes havoc with on-screen keyboards.
if (this.isOpen() && ! Utils.isTouchscreen()) {
this.$results.find('li.select2-results__option--highlighted').focus();
}
};
Select2.prototype._syncAttributes = function () { Select2.prototype._syncAttributes = function () {
this.options.set('disabled', this.$element.prop('disabled')); this.options.set('disabled', this.$element.prop('disabled'));
@ -5653,11 +5809,11 @@ S2.define('jquery.select2',[
'./select2/core', './select2/core',
'./select2/defaults' './select2/defaults'
], function ($, _, Select2, Defaults) { ], function ($, _, Select2, Defaults) {
if ($.fn.select2 == null) { if ($.fn.selectWoo == null) {
// All methods that should return the element // All methods that should return the element
var thisMethods = ['open', 'close', 'destroy']; var thisMethods = ['open', 'close', 'destroy'];
$.fn.select2 = function (options) { $.fn.selectWoo = function (options) {
options = options || {}; options = options || {};
if (typeof options === 'object') { if (typeof options === 'object') {
@ -5697,10 +5853,17 @@ S2.define('jquery.select2',[
}; };
} }
if ($.fn.select2.defaults == null) { if ($.fn.select2 != null && $.fn.select2.defaults != null) {
$.fn.select2.defaults = Defaults; $.fn.selectWoo.defaults = $.fn.select2.defaults;
} }
if ($.fn.selectWoo.defaults == null) {
$.fn.selectWoo.defaults = Defaults;
}
// Also register selectWoo under select2 if select2 is not already present.
$.fn.select2 = $.fn.select2 || $.fn.selectWoo;
return Select2; return Select2;
}); });
@ -5719,6 +5882,7 @@ S2.define('jquery.select2',[
// This allows Select2 to use the internal loader outside of this file, such // This allows Select2 to use the internal loader outside of this file, such
// as in the language files. // as in the language files.
jQuery.fn.select2.amd = S2; jQuery.fn.select2.amd = S2;
jQuery.fn.selectWoo.amd = S2;
// Return the Select2 instance for anyone who is importing it. // Return the Select2 instance for anyone who is importing it.
return select2; return select2;

View File

@ -1,5 +1,5 @@
/*! /*!
* SelectWoo 1.0.6 * SelectWoo 1.0.9
* https://github.com/woocommerce/selectWoo * https://github.com/woocommerce/selectWoo
* *
* Released under the MIT license * Released under the MIT license
@ -755,8 +755,8 @@ S2.define('select2/utils',[
}); });
}; };
Utils.entityDecode = function(html) { Utils.entityDecode = function (html) {
var txt = document.createElement("textarea"); var txt = document.createElement('textarea');
txt.innerHTML = html; txt.innerHTML = html;
return txt.value; return txt.value;
} }
@ -1551,7 +1551,14 @@ S2.define('select2/selection/single',[
.attr('id', id) .attr('id', id)
.attr('role', 'textbox') .attr('role', 'textbox')
.attr('aria-readonly', 'true'); .attr('aria-readonly', 'true');
this.$selection.attr('aria-labelledby', id);
var label = this.options.get( 'label' );
if ( typeof( label ) === 'string' ) {
this.$selection.attr( 'aria-label', label );
} else {
this.$selection.attr( 'aria-labelledby', id );
}
// This makes single non-search selects work in screen readers. If it causes problems elsewhere, remove. // This makes single non-search selects work in screen readers. If it causes problems elsewhere, remove.
this.$selection.attr('role', 'combobox'); this.$selection.attr('role', 'combobox');
@ -4398,6 +4405,7 @@ S2.define('select2/dropdown/attachBody',[
var parentOffset = $offsetParent.offset(); var parentOffset = $offsetParent.offset();
css.top -= parentOffset.top;
css.left -= parentOffset.left; css.left -= parentOffset.left;
if (!isCurrentlyAbove && !isCurrentlyBelow) { if (!isCurrentlyAbove && !isCurrentlyBelow) {
@ -4412,7 +4420,7 @@ S2.define('select2/dropdown/attachBody',[
if (newDirection == 'above' || if (newDirection == 'above' ||
(isCurrentlyAbove && newDirection !== 'below')) { (isCurrentlyAbove && newDirection !== 'below')) {
css.top = container.top - dropdown.height; css.top = container.top - parentOffset.top - dropdown.height;
} }
if (newDirection != null) { if (newDirection != null) {

View File

@ -1,5 +1,5 @@
/*! /*!
* SelectWoo 1.0.6 * SelectWoo 1.0.9
* https://github.com/woocommerce/selectWoo * https://github.com/woocommerce/selectWoo
* *
* Released under the MIT license * Released under the MIT license
@ -755,8 +755,8 @@ S2.define('select2/utils',[
}); });
}; };
Utils.entityDecode = function(html) { Utils.entityDecode = function (html) {
var txt = document.createElement("textarea"); var txt = document.createElement('textarea');
txt.innerHTML = html; txt.innerHTML = html;
return txt.value; return txt.value;
} }
@ -1551,7 +1551,14 @@ S2.define('select2/selection/single',[
.attr('id', id) .attr('id', id)
.attr('role', 'textbox') .attr('role', 'textbox')
.attr('aria-readonly', 'true'); .attr('aria-readonly', 'true');
this.$selection.attr('aria-labelledby', id);
var label = this.options.get( 'label' );
if ( typeof( label ) === 'string' ) {
this.$selection.attr( 'aria-label', label );
} else {
this.$selection.attr( 'aria-labelledby', id );
}
// This makes single non-search selects work in screen readers. If it causes problems elsewhere, remove. // This makes single non-search selects work in screen readers. If it causes problems elsewhere, remove.
this.$selection.attr('role', 'combobox'); this.$selection.attr('role', 'combobox');

View File

@ -21,7 +21,7 @@
"pelago/emogrifier": "3.1.0", "pelago/emogrifier": "3.1.0",
"psr/container": "1.0.0", "psr/container": "1.0.0",
"woocommerce/action-scheduler": "3.1.6", "woocommerce/action-scheduler": "3.1.6",
"woocommerce/woocommerce-admin": "2.2.1", "woocommerce/woocommerce-admin": "2.2.2-rc.1",
"woocommerce/woocommerce-blocks": "4.9.1" "woocommerce/woocommerce-blocks": "4.9.1"
}, },
"require-dev": { "require-dev": {

28
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "11158f53934e897bd84be190a184ec87", "content-hash": "be33d948ed1d2ee3a7a23ef657f3148d",
"packages": [ "packages": [
{ {
"name": "automattic/jetpack-autoloader", "name": "automattic/jetpack-autoloader",
@ -86,16 +86,16 @@
}, },
{ {
"name": "composer/installers", "name": "composer/installers",
"version": "v1.10.0", "version": "v1.11.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/composer/installers.git", "url": "https://github.com/composer/installers.git",
"reference": "1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d" "reference": "ae03311f45dfe194412081526be2e003960df74b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/composer/installers/zipball/1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d", "url": "https://api.github.com/repos/composer/installers/zipball/ae03311f45dfe194412081526be2e003960df74b",
"reference": "1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d", "reference": "ae03311f45dfe194412081526be2e003960df74b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -189,6 +189,7 @@
"majima", "majima",
"mako", "mako",
"mediawiki", "mediawiki",
"miaoxing",
"modulework", "modulework",
"modx", "modx",
"moodle", "moodle",
@ -206,6 +207,7 @@
"sydes", "sydes",
"sylius", "sylius",
"symfony", "symfony",
"tastyigniter",
"typo3", "typo3",
"wordpress", "wordpress",
"yawik", "yawik",
@ -226,7 +228,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-01-14T11:07:16+00:00" "time": "2021-04-28T06:42:17+00:00"
}, },
{ {
"name": "maxmind-db/reader", "name": "maxmind-db/reader",
@ -501,16 +503,16 @@
}, },
{ {
"name": "woocommerce/woocommerce-admin", "name": "woocommerce/woocommerce-admin",
"version": "2.2.1", "version": "2.2.2-rc.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/woocommerce/woocommerce-admin.git", "url": "https://github.com/woocommerce/woocommerce-admin.git",
"reference": "78cc9c5ef7de5be5bd0f9208483e5ae97422be9a" "reference": "0d305d1716481a0cc2010ec7b0a608a2d3c8ebe4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/78cc9c5ef7de5be5bd0f9208483e5ae97422be9a", "url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/0d305d1716481a0cc2010ec7b0a608a2d3c8ebe4",
"reference": "78cc9c5ef7de5be5bd0f9208483e5ae97422be9a", "reference": "0d305d1716481a0cc2010ec7b0a608a2d3c8ebe4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -542,7 +544,7 @@
], ],
"description": "A modern, javascript-driven WooCommerce Admin experience.", "description": "A modern, javascript-driven WooCommerce Admin experience.",
"homepage": "https://github.com/woocommerce/woocommerce-admin", "homepage": "https://github.com/woocommerce/woocommerce-admin",
"time": "2021-04-02T19:30:03+00:00" "time": "2021-04-28T19:39:33+00:00"
}, },
{ {
"name": "woocommerce/woocommerce-blocks", "name": "woocommerce/woocommerce-blocks",
@ -589,10 +591,6 @@
"gutenberg", "gutenberg",
"woocommerce" "woocommerce"
], ],
"support": {
"issues": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues",
"source": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/tree/v4.9.1"
},
"time": "2021-04-13T16:11:16+00:00" "time": "2021-04-13T16:11:16+00:00"
} }
], ],

View File

@ -224,7 +224,7 @@ class WC_Frontend_Scripts {
'selectWoo' => array( 'selectWoo' => array(
'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ), 'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
'deps' => array( 'jquery' ), 'deps' => array( 'jquery' ),
'version' => '1.0.6', 'version' => '1.0.9',
), ),
'wc-address-i18n' => array( 'wc-address-i18n' => array(
'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ), 'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ),

View File

@ -2753,8 +2753,9 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
$field .= '<input type="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . current( array_keys( $countries ) ) . '" ' . implode( ' ', $custom_attributes ) . ' class="country_to_state" readonly="readonly" />'; $field .= '<input type="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="' . current( array_keys( $countries ) ) . '" ' . implode( ' ', $custom_attributes ) . ' class="country_to_state" readonly="readonly" />';
} else { } else {
$data_label = ! empty( $args['label'] ) ? 'data-label="' . esc_attr( $args['label'] ) . '"' : '';
$field = '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="country_to_state country_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_attr__( 'Select a country / region&hellip;', 'woocommerce' ) ) . '"><option value="">' . esc_html__( 'Select a country / region&hellip;', 'woocommerce' ) . '</option>'; $field = '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="country_to_state country_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_attr__( 'Select a country / region&hellip;', 'woocommerce' ) ) . '" ' . $data_label . '><option value="">' . esc_html__( 'Select a country / region&hellip;', 'woocommerce' ) . '</option>';
foreach ( $countries as $ckey => $cvalue ) { foreach ( $countries as $ckey => $cvalue ) {
$field .= '<option value="' . esc_attr( $ckey ) . '" ' . selected( $value, $ckey, false ) . '>' . esc_html( $cvalue ) . '</option>'; $field .= '<option value="' . esc_attr( $ckey ) . '" ' . selected( $value, $ckey, false ) . '>' . esc_html( $cvalue ) . '</option>';
@ -2779,8 +2780,9 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
$field .= '<input type="hidden" class="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="" ' . implode( ' ', $custom_attributes ) . ' placeholder="' . esc_attr( $args['placeholder'] ) . '" readonly="readonly" data-input-classes="' . esc_attr( implode( ' ', $args['input_class'] ) ) . '"/>'; $field .= '<input type="hidden" class="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="" ' . implode( ' ', $custom_attributes ) . ' placeholder="' . esc_attr( $args['placeholder'] ) . '" readonly="readonly" data-input-classes="' . esc_attr( implode( ' ', $args['input_class'] ) ) . '"/>';
} elseif ( ! is_null( $for_country ) && is_array( $states ) ) { } elseif ( ! is_null( $for_country ) && is_array( $states ) ) {
$data_label = ! empty( $args['label'] ) ? 'data-label="' . esc_attr( $args['label'] ) . '"' : '';
$field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="state_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_html__( 'Select an option&hellip;', 'woocommerce' ) ) . '" data-input-classes="' . esc_attr( implode( ' ', $args['input_class'] ) ) . '"> $field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="state_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_html__( 'Select an option&hellip;', 'woocommerce' ) ) . '" data-input-classes="' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . $data_label . '>
<option value="">' . esc_html__( 'Select an option&hellip;', 'woocommerce' ) . '</option>'; <option value="">' . esc_html__( 'Select an option&hellip;', 'woocommerce' ) . '</option>';
foreach ( $states as $ckey => $cvalue ) { foreach ( $states as $ckey => $cvalue ) {

454
tests/e2e/core-tests/package-lock.json generated Normal file
View File

@ -0,0 +1,454 @@
{
"name": "@woocommerce/e2e-core-tests",
"version": "0.1.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@babel/code-frame": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",
"integrity": "sha512-HV1Cm0Q3ZrpCR93tkWOYiuYIgLxZXZFVG2VgK+MBWjUqZTundupbfx2aXarXuw5Ko5aMcjtJgbSs4vUGBS5v6g==",
"requires": {
"@babel/highlight": "^7.12.13"
}
},
"@babel/helper-validator-identifier": {
"version": "7.12.11",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz",
"integrity": "sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw=="
},
"@babel/highlight": {
"version": "7.13.10",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.13.10.tgz",
"integrity": "sha512-5aPpe5XQPzflQrFwL1/QoeHkP2MsA4JCntcXHRhEsdsfPVkvPi2w7Qix4iV7t5S/oC9OodGrggd8aco1g3SZFg==",
"requires": {
"@babel/helper-validator-identifier": "^7.12.11",
"chalk": "^2.0.0",
"js-tokens": "^4.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"@jest/environment": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/@jest/environment/-/environment-26.5.2.tgz",
"integrity": "sha512-YjhCD/Zhkz0/1vdlS/QN6QmuUdDkpgBdK4SdiVg4Y19e29g4VQYN5Xg8+YuHjdoWGY7wJHMxc79uDTeTOy9Ngw==",
"requires": {
"@jest/fake-timers": "^26.5.2",
"@jest/types": "^26.5.2",
"@types/node": "*",
"jest-mock": "^26.5.2"
}
},
"@jest/fake-timers": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-26.5.2.tgz",
"integrity": "sha512-09Hn5Oraqt36V1akxQeWMVL0fR9c6PnEhpgLaYvREXZJAh2H2Y+QLCsl0g7uMoJeoWJAuz4tozk1prbR1Fc1sw==",
"requires": {
"@jest/types": "^26.5.2",
"@sinonjs/fake-timers": "^6.0.1",
"@types/node": "*",
"jest-message-util": "^26.5.2",
"jest-mock": "^26.5.2",
"jest-util": "^26.5.2"
}
},
"@jest/globals": {
"version": "26.5.3",
"resolved": "https://registry.npmjs.org/@jest/globals/-/globals-26.5.3.tgz",
"integrity": "sha512-7QztI0JC2CuB+Wx1VdnOUNeIGm8+PIaqngYsZXQCkH2QV0GFqzAYc9BZfU0nuqA6cbYrWh5wkuMzyii3P7deug==",
"requires": {
"@jest/environment": "^26.5.2",
"@jest/types": "^26.5.2",
"expect": "^26.5.3"
}
},
"@jest/types": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/@jest/types/-/types-26.5.2.tgz",
"integrity": "sha512-QDs5d0gYiyetI8q+2xWdkixVQMklReZr4ltw7GFDtb4fuJIBCE6mzj2LnitGqCuAlLap6wPyb8fpoHgwZz5fdg==",
"requires": {
"@types/istanbul-lib-coverage": "^2.0.0",
"@types/istanbul-reports": "^3.0.0",
"@types/node": "*",
"@types/yargs": "^15.0.0",
"chalk": "^4.0.0"
}
},
"@sinonjs/commons": {
"version": "1.8.3",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz",
"integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==",
"requires": {
"type-detect": "4.0.8"
}
},
"@sinonjs/fake-timers": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz",
"integrity": "sha512-MZPUxrmFubI36XS1DI3qmI0YdN1gks62JtFZvxR67ljjSNCeK6U08Zx4msEWOXuofgqUt6zPHSi1H9fbjR/NRA==",
"requires": {
"@sinonjs/commons": "^1.7.0"
}
},
"@types/istanbul-lib-coverage": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz",
"integrity": "sha512-sz7iLqvVUg1gIedBOvlkxPlc8/uVzyS5OwGz1cKjXzkl3FpL3al0crU8YGU1WoHkxn0Wxbw5tyi6hvzJKNzFsw=="
},
"@types/istanbul-lib-report": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz",
"integrity": "sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==",
"requires": {
"@types/istanbul-lib-coverage": "*"
}
},
"@types/istanbul-reports": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.0.tgz",
"integrity": "sha512-nwKNbvnwJ2/mndE9ItP/zc2TCzw6uuodnF4EHYWD+gCQDVBuRQL5UzbZD0/ezy1iKsFU2ZQiDqg4M9dN4+wZgA==",
"requires": {
"@types/istanbul-lib-report": "*"
}
},
"@types/node": {
"version": "14.14.41",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.41.tgz",
"integrity": "sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g=="
},
"@types/stack-utils": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.0.tgz",
"integrity": "sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw=="
},
"@types/yargs": {
"version": "15.0.13",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.13.tgz",
"integrity": "sha512-kQ5JNTrbDv3Rp5X2n/iUu37IJBDU2gsZ5R/g1/KHOOEc5IKfUFjXT6DENPGduh08I/pamwtEq4oul7gUqKTQDQ==",
"requires": {
"@types/yargs-parser": "*"
}
},
"@types/yargs-parser": {
"version": "20.2.0",
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.0.tgz",
"integrity": "sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA=="
},
"ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"requires": {
"color-convert": "^2.0.1"
}
},
"braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"requires": {
"fill-range": "^7.0.1"
}
},
"chalk": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
"integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"ci-info": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz",
"integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ=="
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"config": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/config/-/config-3.3.3.tgz",
"integrity": "sha512-T3RmZQEAji5KYqUQpziWtyGJFli6Khz7h0rpxDwYNjSkr5ynyTWwO7WpfjHzTXclNCDfSWQRcwMb+NwxJesCKw==",
"requires": {
"json5": "^2.1.1"
}
},
"diff-sequences": {
"version": "26.5.0",
"resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.5.0.tgz",
"integrity": "sha512-ZXx86srb/iYy6jG71k++wBN9P9J05UNQ5hQHQd9MtMPvcqXPx/vKU69jfHV637D00Q2gSgPk2D+jSx3l1lDW/Q=="
},
"escape-string-regexp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz",
"integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w=="
},
"expect": {
"version": "26.5.3",
"resolved": "https://registry.npmjs.org/expect/-/expect-26.5.3.tgz",
"integrity": "sha512-kkpOhGRWGOr+TEFUnYAjfGvv35bfP+OlPtqPIJpOCR9DVtv8QV+p8zG0Edqafh80fsjeE+7RBcVUq1xApnYglw==",
"requires": {
"@jest/types": "^26.5.2",
"ansi-styles": "^4.0.0",
"jest-get-type": "^26.3.0",
"jest-matcher-utils": "^26.5.2",
"jest-message-util": "^26.5.2",
"jest-regex-util": "^26.0.0"
}
},
"faker": {
"version": "5.5.3",
"resolved": "https://registry.npmjs.org/faker/-/faker-5.5.3.tgz",
"integrity": "sha512-wLTv2a28wjUyWkbnX7u/ABZBkUkIF2fCd73V6P2oFqEGEktDfzWx4UxrSqtPRw0xPRAcjeAOIiJWqZm3pP4u3g=="
},
"fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"requires": {
"to-regex-range": "^5.0.1"
}
},
"graceful-fs": {
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
},
"is-ci": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz",
"integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==",
"requires": {
"ci-info": "^2.0.0"
}
},
"is-number": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
},
"jest-diff": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.5.2.tgz",
"integrity": "sha512-HCSWDUGwsov5oTlGzrRM+UPJI/Dpqi9jzeV0fdRNi3Ch5bnoXhnyJMmVg2juv9081zLIy3HGPI5mcuGgXM2xRA==",
"requires": {
"chalk": "^4.0.0",
"diff-sequences": "^26.5.0",
"jest-get-type": "^26.3.0",
"pretty-format": "^26.5.2"
}
},
"jest-get-type": {
"version": "26.3.0",
"resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-26.3.0.tgz",
"integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig=="
},
"jest-matcher-utils": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-26.5.2.tgz",
"integrity": "sha512-W9GO9KBIC4gIArsNqDUKsLnhivaqf8MSs6ujO/JDcPIQrmY+aasewweXVET8KdrJ6ADQaUne5UzysvF/RR7JYA==",
"requires": {
"chalk": "^4.0.0",
"jest-diff": "^26.5.2",
"jest-get-type": "^26.3.0",
"pretty-format": "^26.5.2"
}
},
"jest-message-util": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-26.5.2.tgz",
"integrity": "sha512-Ocp9UYZ5Jl15C5PNsoDiGEk14A4NG0zZKknpWdZGoMzJuGAkVt10e97tnEVMYpk7LnQHZOfuK2j/izLBMcuCZw==",
"requires": {
"@babel/code-frame": "^7.0.0",
"@jest/types": "^26.5.2",
"@types/stack-utils": "^2.0.0",
"chalk": "^4.0.0",
"graceful-fs": "^4.2.4",
"micromatch": "^4.0.2",
"slash": "^3.0.0",
"stack-utils": "^2.0.2"
}
},
"jest-mock": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-26.5.2.tgz",
"integrity": "sha512-9SiU4b5PtO51v0MtJwVRqeGEroH66Bnwtq4ARdNP7jNXbpT7+ByeWNAk4NeT/uHfNSVDXEXgQo1XRuwEqS6Rdw==",
"requires": {
"@jest/types": "^26.5.2",
"@types/node": "*"
}
},
"jest-regex-util": {
"version": "26.0.0",
"resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-26.0.0.tgz",
"integrity": "sha512-Gv3ZIs/nA48/Zvjrl34bf+oD76JHiGDUxNOVgUjh3j890sblXryjY4rss71fPtD/njchl6PSE2hIhvyWa1eT0A=="
},
"jest-util": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/jest-util/-/jest-util-26.5.2.tgz",
"integrity": "sha512-WTL675bK+GSSAYgS8z9FWdCT2nccO1yTIplNLPlP0OD8tUk/H5IrWKMMRudIQQ0qp8bb4k+1Qa8CxGKq9qnYdg==",
"requires": {
"@jest/types": "^26.5.2",
"@types/node": "*",
"chalk": "^4.0.0",
"graceful-fs": "^4.2.4",
"is-ci": "^2.0.0",
"micromatch": "^4.0.2"
}
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
},
"json5": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
"requires": {
"minimist": "^1.2.5"
}
},
"micromatch": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz",
"integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==",
"requires": {
"braces": "^3.0.1",
"picomatch": "^2.0.5"
}
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"picomatch": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.3.tgz",
"integrity": "sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg=="
},
"pretty-format": {
"version": "26.5.2",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.5.2.tgz",
"integrity": "sha512-VizyV669eqESlkOikKJI8Ryxl/kPpbdLwNdPs2GrbQs18MpySB5S0Yo0N7zkg2xTRiFq4CFw8ct5Vg4a0xP0og==",
"requires": {
"@jest/types": "^26.5.2",
"ansi-regex": "^5.0.0",
"ansi-styles": "^4.0.0",
"react-is": "^16.12.0"
}
},
"react-is": {
"version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
},
"slash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
"integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q=="
},
"stack-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.2.tgz",
"integrity": "sha512-0H7QK2ECz3fyZMzQ8rH0j2ykpfbnd20BFtfg/SqVC2+sCTtcw0aDTGB7dk+de4U4uUeuz6nOtJcrkFFLG1B0Rg==",
"requires": {
"escape-string-regexp": "^2.0.0"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"requires": {
"has-flag": "^4.0.0"
}
},
"to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
"requires": {
"is-number": "^7.0.0"
}
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="
}
}
}

View File

@ -41,7 +41,6 @@ const runOnboardingFlowTest = () => {
} }
it('can start and complete onboarding when visiting the site for the first time.', async () => { it('can start and complete onboarding when visiting the site for the first time.', async () => {
await merchant.runSetupWizard();
await completeOnboardingWizard(); await completeOnboardingWizard();
}); });
}); });
@ -62,7 +61,6 @@ const runTaskListTest = () => {
// Click on "Set up shipping" task to move to the next step // Click on "Set up shipping" task to move to the next step
const [ setupTaskListItem ] = await page.$x( '//div[contains(text(),"Set up shipping")]' ); const [ setupTaskListItem ] = await page.$x( '//div[contains(text(),"Set up shipping")]' );
await setupTaskListItem.click(); await setupTaskListItem.click();
await page.waitForNavigation({waitUntil: 'networkidle0'});
// Wait for "Proceed" button to become active // Wait for "Proceed" button to become active
await page.waitForSelector('button.is-primary:not(:disabled)'); await page.waitForSelector('button.is-primary:not(:disabled)');

View File

@ -0,0 +1,83 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests */
/**
* Internal dependencies
*/
const {
merchant,
completeOnboardingWizard,
withRestApi,
addShippingZoneAndMethod,
IS_RETEST_MODE,
} = require( '@woocommerce/e2e-utils' );
/**
* External dependencies
*/
const config = require( 'config' );
const {
it,
describe,
} = require( '@jest/globals' );
const shippingZoneNameUS = config.get( 'addresses.customer.shipping.country' );
const runOnboardingFlowTest = () => {
describe('Store owner can go through store Onboarding', () => {
if ( IS_RETEST_MODE ) {
it('can reset onboarding to default settings', async () => {
await withRestApi.resetOnboarding();
});
it('can reset shipping zones to default settings', async () => {
await withRestApi.deleteAllShippingZones();
});
it('can reset to default settings', async () => {
await withRestApi.resetSettingsGroupToDefault('general');
await withRestApi.resetSettingsGroupToDefault('products');
await withRestApi.resetSettingsGroupToDefault('tax');
});
}
it('can start and complete onboarding when visiting the site for the first time.', async () => {
await completeOnboardingWizard();
});
});
};
const runTaskListTest = () => {
describe('Store owner can go through setup Task List', () => {
it('can setup shipping', async () => {
await page.evaluate(() => {
document.querySelector('.woocommerce-list__item-title').scrollIntoView();
});
// Query for all tasks on the list
const taskListItems = await page.$$('.woocommerce-list__item-title');
expect(taskListItems.length).toBeInRange( 5, 6 );
// Work around for https://github.com/woocommerce/woocommerce-admin/issues/6761
if ( taskListItems.length == 6 ) {
// Click on "Set up shipping" task to move to the next step
const [ setupTaskListItem ] = await page.$x( '//div[contains(text(),"Set up shipping")]' );
await setupTaskListItem.click();
// Wait for "Proceed" button to become active
await page.waitForSelector('button.is-primary:not(:disabled)');
await page.waitFor(3000);
// Click on "Proceed" button to save shipping settings
await page.click('button.is-primary');
await page.waitFor(3000);
} else {
await merchant.openNewShipping();
await addShippingZoneAndMethod(shippingZoneNameUS);
}
});
});
};
module.exports = {
runOnboardingFlowTest,
runTaskListTest,
};

View File

@ -30,10 +30,12 @@ const runOrderApplyCouponTest = () => {
await createSimpleProduct(); await createSimpleProduct();
couponCode = await createCoupon(); couponCode = await createCoupon();
orderId = await createSimpleOrder('Pending payment', simpleProductName); orderId = await createSimpleOrder('Pending payment', simpleProductName);
await addProductToOrder(orderId, simpleProductName); await Promise.all([
addProductToOrder(orderId, simpleProductName),
// We need to remove any listeners on the `dialog` event otherwise we can't catch the dialog below // We need to remove any listeners on the `dialog` event otherwise we can't catch the dialog below
await page.removeAllListeners('dialog'); page.removeAllListeners('dialog'),
]);
// Make sure the simple product price is greater than the coupon amount // Make sure the simple product price is greater than the coupon amount
await expect(Number(simpleProductPrice)).toBeGreaterThan(5.00); await expect(Number(simpleProductPrice)).toBeGreaterThan(5.00);

View File

@ -1,4 +1,4 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests, */ /* eslint-disable jest/no-export, jest/no-disabled-tests, jest/expect-expect */
/** /**
* Internal dependencies * Internal dependencies
@ -10,36 +10,80 @@ const {
createSimpleProduct, createSimpleProduct,
addProductToOrder, addProductToOrder,
clickUpdateOrder, clickUpdateOrder,
factories,
selectOptionInSelect2,
} = require( '@woocommerce/e2e-utils' ); } = require( '@woocommerce/e2e-utils' );
const searchString = 'John Doe';
const customerBilling = {
first_name: 'John',
last_name: 'Doe',
company: 'Automattic',
country: 'US',
address_1: 'address1',
address_2: 'address2',
city: 'San Francisco',
state: 'CA',
postcode: '94107',
phone: '123456789',
email: 'john.doe@example.com',
};
const customerShipping = {
first_name: 'Tim',
last_name: 'Clark',
company: 'Automattic',
country: 'US',
address_1: 'Oxford Ave',
address_2: 'Linwood Ave',
city: 'Buffalo',
state: 'NY',
postcode: '14201',
phone: '123456789',
email: 'john.doe@example.com',
};
/**
* Set the billing fields for the customer account for this test suite.
*
* @returns {Promise<void>}
*/
const updateCustomerBilling = async () => {
const client = factories.api.withDefaultPermalinks;
const customerEndpoint = 'wc/v3/customers/';
const customers = await client.get( customerEndpoint, {
search: 'Jane',
role: 'all',
} );
if ( ! customers.data | ! customers.data.length ) {
return;
}
const customerId = customers.data[0].id;
const customerData = {
id: customerId,
billing: customerBilling,
shipping: customerShipping,
};
await client.put( customerEndpoint + customerId, customerData );
};
const runOrderSearchingTest = () => { const runOrderSearchingTest = () => {
describe('WooCommerce Orders > Search orders', () => { describe('WooCommerce Orders > Search orders', () => {
let orderId; let orderId;
beforeAll(async () => { beforeAll( async () => {
await merchant.login();
await createSimpleProduct('Wanted Product'); await createSimpleProduct('Wanted Product');
await updateCustomerBilling();
// Create new order for testing // Create new order for testing
await merchant.login();
await merchant.openNewOrder(); await merchant.openNewOrder();
await page.waitForSelector('#order_status'); await page.waitForSelector('#order_status');
await page.click('#customer_user'); await page.click('#customer_user');
await page.click('span.select2-search > input.select2-search__field'); await page.click('span.select2-search > input.select2-search__field');
await page.type('span.select2-search > input.select2-search__field', 'Customer'); await page.type('span.select2-search > input.select2-search__field', 'Jane Smith');
await page.waitFor(2000); // to avoid flakyness await page.waitFor(2000); // to avoid flakyness
await page.keyboard.press('Enter'); await page.keyboard.press('Enter');
// Change the shipping data
await page.waitFor(1000); // to avoid flakiness
await page.click('.billing-same-as-shipping');
await page.keyboard.press('Enter');
await page.waitForSelector('#_shipping_first_name');
await clearAndFillInput('#_shipping_first_name', 'Tim');
await clearAndFillInput('#_shipping_last_name', 'Clark');
await clearAndFillInput('#_shipping_address_1', 'Oxford Ave');
await clearAndFillInput('#_shipping_address_2', 'Linwood Ave');
await clearAndFillInput('#_shipping_city', 'Buffalo');
await clearAndFillInput('#_shipping_postcode', '14201');
// Get the post id // Get the post id
const variablePostId = await page.$('#post_ID'); const variablePostId = await page.$('#post_ID');
orderId = (await(await variablePostId.getProperty('value')).jsonValue()); orderId = (await(await variablePostId.getProperty('value')).jsonValue());
@ -53,79 +97,82 @@ const runOrderSearchingTest = () => {
}); });
it('can search for order by order id', async () => { it('can search for order by order id', async () => {
await searchForOrder(orderId, orderId, 'John Doe'); await searchForOrder(orderId, orderId, searchString);
}); });
it('can search for order by billing first name', async () => { it('can search for order by billing first name', async () => {
await searchForOrder('John', orderId, 'John Doe'); await searchForOrder(customerBilling.first_name, orderId, searchString);
}) })
it('can search for order by billing last name', async () => { it('can search for order by billing last name', async () => {
await searchForOrder('Doe', orderId, 'John Doe'); await searchForOrder(customerBilling.last_name, orderId, searchString);
}) })
it('can search for order by billing company name', async () => { it('can search for order by billing company name', async () => {
await searchForOrder('Automattic', orderId, 'John Doe'); await searchForOrder(customerBilling.company, orderId, searchString);
}) })
it('can search for order by billing first address', async () => { it('can search for order by billing first address', async () => {
await searchForOrder('addr 1', orderId, 'John Doe'); await searchForOrder(customerBilling.address_1, orderId, searchString);
}) })
it('can search for order by billing second address', async () => { it('can search for order by billing second address', async () => {
await searchForOrder('addr 2', orderId, 'John Doe'); await searchForOrder(customerBilling.address_2, orderId, searchString);
}) })
it('can search for order by billing city name', async () => { it('can search for order by billing city name', async () => {
await searchForOrder('San Francisco', orderId, 'John Doe'); await searchForOrder(customerBilling.city, orderId, searchString);
}) })
it('can search for order by billing post code', async () => { it('can search for order by billing post code', async () => {
await searchForOrder('94107', orderId, 'John Doe'); await searchForOrder(customerBilling.postcode, orderId, searchString);
}) })
it('can search for order by billing email', async () => { it('can search for order by billing email', async () => {
await searchForOrder('john.doe@example.com', orderId, 'John Doe'); await searchForOrder(customerBilling.email, orderId, searchString);
}) })
it('can search for order by billing phone', async () => { it('can search for order by billing phone', async () => {
await searchForOrder('123456789', orderId, 'John Doe'); await searchForOrder(customerBilling.phone, orderId, searchString);
}) })
it('can search for order by billing state', async () => { it('can search for order by billing state', async () => {
await searchForOrder('CA', orderId, 'John Doe'); await searchForOrder(customerBilling.state, orderId, searchString);
}) })
it('can search for order by shipping first name', async () => { it('can search for order by shipping first name', async () => {
await searchForOrder('Tim', orderId, 'John Doe'); await searchForOrder(customerShipping.first_name, orderId, searchString);
}) })
it('can search for order by shipping last name', async () => { it('can search for order by shipping last name', async () => {
await searchForOrder('Clark', orderId, 'John Doe'); await searchForOrder(customerShipping.last_name, orderId, searchString);
}) })
it('can search for order by shipping first address', async () => { it('can search for order by shipping first address', async () => {
await searchForOrder('Oxford Ave', orderId, 'John Doe'); await searchForOrder(customerShipping.address_1, orderId, searchString);
}) })
it('can search for order by shipping second address', async () => { it('can search for order by shipping second address', async () => {
await searchForOrder('Linwood Ave', orderId, 'John Doe'); await searchForOrder(customerShipping.address_2, orderId, searchString);
}) })
it('can search for order by shipping city name', async () => { it('can search for order by shipping city name', async () => {
await searchForOrder('Buffalo', orderId, 'John Doe'); await searchForOrder(customerShipping.city, orderId, searchString);
}) })
it('can search for order by shipping postcode name', async () => { it('can search for order by shipping postcode name', async () => {
await searchForOrder('14201', orderId, 'John Doe'); await searchForOrder(customerShipping.postcode, orderId, searchString);
}) })
it('can search for order by shipping state name', async () => { /**
await searchForOrder('CA', orderId, 'John Doe'); * shipping state is abbreviated. This test passes if billing and shipping state are the same
*/
it.skip('can search for order by shipping state name', async () => {
await searchForOrder('New York', orderId, searchString);
}) })
it('can search for order by item name', async () => { it('can search for order by item name', async () => {
await searchForOrder('Wanted Product', orderId, 'John Doe'); await searchForOrder('Wanted Product', orderId, searchString);
}) })
}); });
}; };

View File

@ -9,6 +9,7 @@
uiUnblocked, uiUnblocked,
setCheckbox, setCheckbox,
settingsPageSaveChanges, settingsPageSaveChanges,
addShippingZoneAndMethod,
withRestApi, withRestApi,
} = require( '@woocommerce/e2e-utils' ); } = require( '@woocommerce/e2e-utils' );
@ -36,6 +37,10 @@ const runCheckoutCreateAccountTest = () => {
await merchant.openSettings('account'); await merchant.openSettings('account');
await setCheckbox('#woocommerce_enable_signup_and_login_from_checkout'); await setCheckbox('#woocommerce_enable_signup_and_login_from_checkout');
await settingsPageSaveChanges(); await settingsPageSaveChanges();
// Set free shipping within California
await addShippingZoneAndMethod('Free Shipping CA', 'state:US:CA', ' ', 'free_shipping');
await merchant.logout(); await merchant.logout();
// Add simple product to cart and proceed to checkout // Add simple product to cart and proceed to checkout

View File

@ -4,7 +4,12 @@ echo "Initializing WooCommerce E2E"
wp plugin activate woocommerce wp plugin activate woocommerce
wp theme install twentynineteen --activate wp theme install twentynineteen --activate
wp user create customer customer@woocommercecoree2etestsuite.com --user_pass=password --role=subscriber --path=/var/www/html wp user create customer customer@woocommercecoree2etestsuite.com \
--user_pass=password \
--role=subscriber \
--first_name='Jane' \
--last_name='Smith' \
--path=/var/www/html
# we cannot create API keys for the API, so we using basic auth, this plugin allows that. # we cannot create API keys for the API, so we using basic auth, this plugin allows that.
wp plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --activate wp plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --activate

View File

@ -43,7 +43,10 @@ if ( appPath ) {
if ( ! fs.existsSync( customInitFile ) ) { if ( ! fs.existsSync( customInitFile ) ) {
customInitFile = ''; customInitFile = '';
} }
} else {
customInitFile = '';
} }
const appInitFile = customInitFile ? customInitFile : path.resolve( appPath, 'tests/e2e/docker/initialize.sh' ); const appInitFile = customInitFile ? customInitFile : path.resolve( appPath, 'tests/e2e/docker/initialize.sh' );
// If found, copy it into the wp-cli Docker context so // If found, copy it into the wp-cli Docker context so
// it gets picked up by the entrypoint script. // it gets picked up by the entrypoint script.

View File

@ -3,7 +3,7 @@
## Added ## Added
- `emptyCart()` Shopper flow helper that empties the cart - `emptyCart()` Shopper flow helper that empties the cart
- `deleteAllShippingZones` Delete all the existing shipping zones - `deleteAllShippingZones()` Delete all the existing shipping zones
- constants - constants
- `WP_ADMIN_POST_TYPE` - `WP_ADMIN_POST_TYPE`
- `WP_ADMIN_NEW_POST_TYPE` - `WP_ADMIN_NEW_POST_TYPE`
@ -11,6 +11,7 @@
- `WP_ADMIN_WC_HOME` - `WP_ADMIN_WC_HOME`
- `IS_RETEST_MODE` - `IS_RETEST_MODE`
- `withRestApi` flow containing utility functions that manage data with the rest api - `withRestApi` flow containing utility functions that manage data with the rest api
- `waitForSelectorWithoutThrow` - conditionally wait for a selector without throwing an error
# 0.1.4 # 0.1.4

View File

@ -181,6 +181,7 @@ This package provides support for enabling retries in tests:
| `selectOrderAction` | `action` | Helper method to select an order action in the `Order Actions` postbox | | `selectOrderAction` | `action` | Helper method to select an order action in the `Order Actions` postbox |
| `clickUpdateOrder` | `noticeText`, `waitForSave` | Helper method to click the Update button on the order details page | | `clickUpdateOrder` | `noticeText`, `waitForSave` | Helper method to click the Update button on the order details page |
| `deleteAllShippingZones` | | Delete all the existing shipping zones | | `deleteAllShippingZones` | | Delete all the existing shipping zones |
| `waitForSelectorWithoutThrow` | `selector`, `timeoutInSeconds` | conditionally wait for a selector without throwing an error. Default timeout is 5 seconds |
### Test Utilities ### Test Utilities

View File

@ -14,7 +14,8 @@ import {
setCheckbox, setCheckbox,
unsetCheckbox, unsetCheckbox,
evalAndClick, evalAndClick,
clearAndFillInput, backboneUnblocked,
waitForSelectorWithoutThrow,
} from './page-utils'; } from './page-utils';
import factories from './factories'; import factories from './factories';
import { Coupon } from '@woocommerce/api'; import { Coupon } from '@woocommerce/api';
@ -60,6 +61,7 @@ const waitAndClickPrimary = async ( waitForNetworkIdle = true ) => {
*/ */
const completeOnboardingWizard = async () => { const completeOnboardingWizard = async () => {
// Store Details section // Store Details section
await merchant.runSetupWizard();
// Fill store's address - first line // Fill store's address - first line
await expect( page ).toFill( '#inspector-text-control-0', config.get( 'addresses.admin.store.addressfirstline' ) ); await expect( page ).toFill( '#inspector-text-control-0', config.get( 'addresses.admin.store.addressfirstline' ) );
@ -86,8 +88,8 @@ const completeOnboardingWizard = async () => {
await page.click( 'button.is-primary', { text: 'Continue' } ); await page.click( 'button.is-primary', { text: 'Continue' } );
// Wait for usage tracking pop-up window to appear on a new site // Wait for usage tracking pop-up window to appear on a new site
if ( ! IS_RETEST_MODE ) { const usageTrackingHeader = await page.$('.components-modal__header-heading');
await page.waitForSelector('.components-modal__header-heading'); if ( usageTrackingHeader ) {
await expect(page).toMatchElement( await expect(page).toMatchElement(
'.components-modal__header-heading', {text: 'Build a better WooCommerce'} '.components-modal__header-heading', {text: 'Build a better WooCommerce'}
); );
@ -165,24 +167,18 @@ const completeOnboardingWizard = async () => {
} }
// Wait for homescreen welcome modal to appear // Wait for homescreen welcome modal to appear
await page.waitForSelector( '.woocommerce__welcome-modal__page-content__header' ); let welcomeHeader = await waitForSelectorWithoutThrow( '.woocommerce__welcome-modal__page-content' );
await expect( page ).toMatchElement( if ( ! welcomeHeader ) {
'.woocommerce__welcome-modal__page-content__header', { text: 'Welcome to your WooCommerce store\s online HQ!' } return;
); }
// Wait for "Next" button to become active
await page.waitForSelector( 'button.components-guide__forward-button' );
// Click on "Next" button to move to the next step
await page.click( 'button.components-guide__forward-button' );
// Wait for "Next" button to become active
await page.waitForSelector( 'button.components-guide__forward-button' );
// Click on "Next" button to move to the next step
await page.click( 'button.components-guide__forward-button' );
// Click two Next buttons
for ( let b = 0; b < 2; b++ ) {
await page.waitForSelector('button.components-guide__forward-button');
await page.click('button.components-guide__forward-button');
}
// Wait for "Let's go" button to become active // Wait for "Let's go" button to become active
await page.waitForSelector( 'button.components-guide__finish-button' ); await page.waitForSelector( 'button.components-guide__finish-button' );
// Click on "Let's go" button to move to the next step
await page.click( 'button.components-guide__finish-button' ); await page.click( 'button.components-guide__finish-button' );
}; };
@ -438,7 +434,9 @@ const addProductToOrder = async ( orderId, productName ) => {
await expect( page ).toFill('#wc-backbone-modal-dialog + .select2-container .select2-search__field', productName); await expect( page ).toFill('#wc-backbone-modal-dialog + .select2-container .select2-search__field', productName);
await page.waitForSelector( 'li[aria-selected="true"]', { timeout: 10000 } ); await page.waitForSelector( 'li[aria-selected="true"]', { timeout: 10000 } );
await expect( page ).toClick( 'li[aria-selected="true"]' ); await expect( page ).toClick( 'li[aria-selected="true"]' );
await page.click( '.wc-backbone-modal-content #btn-ok', { waitUntil: 'networkidle0' } ); await page.click( '.wc-backbone-modal-content #btn-ok' );
await backboneUnblocked();
// Verify the product we added shows as a line item now // Verify the product we added shows as a line item now
await expect( page ).toMatchElement( '.wc-order-item-name', { text: productName } ); await expect( page ).toMatchElement( '.wc-order-item-name', { text: productName } );

View File

@ -82,6 +82,32 @@ export const uiUnblocked = async () => {
await page.waitForFunction( () => ! Boolean( document.querySelector( '.blockUI' ) ) ); await page.waitForFunction( () => ! Boolean( document.querySelector( '.blockUI' ) ) );
}; };
/**
* Wait for backbone blocking to end.
*/
export const backboneUnblocked = async () => {
await page.waitForFunction( () => ! Boolean( document.querySelector( '.wc-backbone-modal' ) ) );
};
/**
* Conditionally wait for a selector without throwing an error.
*
* @param selector
* @param timeoutInSeconds
* @returns {Promise<boolean>}
*/
export const waitForSelectorWithoutThrow = async ( selector, timeoutInSeconds = 5 ) => {
let selected = await page.$( selector );
for ( let s = 0; s < timeoutInSeconds; s++ ) {
if ( selected ) {
break;
}
await page.waitFor( 1000 );
selected = await page.$( selector );
}
return Boolean( selected );
};
/** /**
* Publish, verify that item was published. Trash, verify that item was trashed. * Publish, verify that item was published. Trash, verify that item was trashed.
* *