Skip to content

Commit

Permalink
Merge pull request #45 from Yoast/stories/taxonomy-scraper-select2
Browse files Browse the repository at this point in the history
fix select2 problem with taxonomy scraper
  • Loading branch information
herregroen authored Aug 15, 2017
2 parents 915e239 + 94cddc5 commit b9c3fbc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
9 changes: 6 additions & 3 deletions js/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ var App = function(){
App.prototype.bindListeners = function(){

if(helper.acf_version >= 5){
this.replaceVars = replaceVars.createReplaceVars(collect);
acf.add_action('change remove append sortstop', this.maybeRefresh);
acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(this, collect, this.replaceVars));
var _self = this;
acf.add_action('ready', function () {
_self.replaceVars = replaceVars.createReplaceVars(collect);
acf.add_action('change remove append sortstop', _self.maybeRefresh);
acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(_self, collect, _self.replaceVars));
});
}else{
var fieldSelectors = config.fieldSelectors.slice(0);

Expand Down
2 changes: 1 addition & 1 deletion js/src/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var config = require( "./config/config.js" );

module.exports = {
acf_version: parseInt(config.acfVersion, 10)
acf_version: parseFloat(config.acfVersion, 10)
};
5 changes: 4 additions & 1 deletion js/src/scraper/scraper.taxonomy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var scrapers = require( "./../scraper-store.js" );
var helper = require( "./../helper.js" );

var Scraper = function() {};

Expand All @@ -16,8 +17,10 @@ Scraper.prototype.scrape = function(fields){

if( field.$el.find('.acf-taxonomy-field[data-type="multi_select"]').length > 0 ){

var select2Target = (helper.acf_version >= 5.6)?'select':'input';

terms = _.pluck(
field.$el.find('.acf-taxonomy-field[data-type="multi_select"] input')
field.$el.find('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target )
.select2('data')
, 'text'
);
Expand Down
18 changes: 12 additions & 6 deletions js/yoast-acf-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ var App = function(){
App.prototype.bindListeners = function(){

if(helper.acf_version >= 5){
this.replaceVars = replaceVars.createReplaceVars(collect);
acf.add_action('change remove append sortstop', this.maybeRefresh);
acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(this, collect, this.replaceVars));
var _self = this;
acf.add_action('ready', function () {
_self.replaceVars = replaceVars.createReplaceVars(collect);
acf.add_action('change remove append sortstop', _self.maybeRefresh);
acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(_self, collect, _self.replaceVars));
});
}else{
var fieldSelectors = config.fieldSelectors.slice(0);

Expand Down Expand Up @@ -300,7 +303,7 @@ module.exports = YoastACFAnalysisConfig;
var config = require( "./config/config.js" );

module.exports = {
acf_version: parseInt(config.acfVersion, 10)
acf_version: parseFloat(config.acfVersion, 10)
};
},{"./config/config.js":7}],9:[function(require,module,exports){
/* global jQuery, YoastACFAnalysis: true */
Expand Down Expand Up @@ -590,6 +593,7 @@ Scraper.prototype.scrape = function(fields){
module.exports = Scraper;
},{"./../cache/cache.attachments.js":2,"./../scraper-store.js":11}],15:[function(require,module,exports){
var scrapers = require( "./../scraper-store.js" );
var helper = require( "./../helper.js" );

var Scraper = function() {};

Expand All @@ -607,8 +611,10 @@ Scraper.prototype.scrape = function(fields){

if( field.$el.find('.acf-taxonomy-field[data-type="multi_select"]').length > 0 ){

var select2Target = (helper.acf_version >= 5.6)?'select':'input';

terms = _.pluck(
field.$el.find('.acf-taxonomy-field[data-type="multi_select"] input')
field.$el.find('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target )
.select2('data')
, 'text'
);
Expand Down Expand Up @@ -652,7 +658,7 @@ Scraper.prototype.scrape = function(fields){
};

module.exports = Scraper;
},{"./../scraper-store.js":11}],16:[function(require,module,exports){
},{"./../helper.js":8,"./../scraper-store.js":11}],16:[function(require,module,exports){
var config = require( "./../config/config.js" );
var scrapers = require( "./../scraper-store.js" );

Expand Down
51 changes: 37 additions & 14 deletions tests/js/system/tests/acf5/relational.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,51 @@ module.exports = {

'Taxonomy Multi Select Field' : function (browser) {

var selector = '.acf-taxonomy-field[data-type="multi_select"][data-taxonomy="category"] .select2-input ';
browser.execute(
function() {
return parseFloat(YoastACFAnalysisConfig.acfVersion, 10);
},
[],
function( result ){
var acfVersion = result.value;
var inputSelector, optionSelector, choiceSelector;

browser.waitForElementVisible( selector, 10000 );
if( acfVersion >= 5.6 ){
inputSelector = '.acf-taxonomy-field[data-type="multi_select"][data-taxonomy="category"] .select2-search__field ';
optionSelector = '.select2-results__option--highlighted';
choiceSelector = '.acf-taxonomy-field .select2-selection__choice';
}else{
inputSelector = '.acf-taxonomy-field[data-type="multi_select"][data-taxonomy="category"] .select2-input ';
optionSelector = '.select2-result:first-child';
choiceSelector = '.acf-taxonomy-field .select2-search-choice';
}

browser.setValue( selector, [ browser.Keys.SPACE ] );
browser.waitForElementVisible( inputSelector, 10000 );

browser.waitForElementVisible( '.select2-result:first-child', 10000 );
browser.setValue( inputSelector, [ browser.Keys.SPACE ] );

browser.setValue( selector, [ browser.Keys.ENTER ] );
browser.waitForElementVisible( optionSelector, 10000 );

browser.waitForElementVisible( '.acf-taxonomy-field .select2-search-choice', 10000 );
browser.setValue( inputSelector, [ browser.Keys.ENTER ] );

browser.execute(
function() {
return jQuery('.acf-taxonomy-field[data-type="multi_select"] input').select2('data')[0].text
},
[],
function( result ){
this.pause( 3000 );
logContains( browser, 'li>' + result.value , browser.assert.ok );
browser.waitForElementVisible( choiceSelector, 10000 );

browser.execute(
function() {

var select2Target = (parseFloat(YoastACFAnalysisConfig.acfVersion, 10) >= 5.6)?'select':'input';

return jQuery('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target).select2('data')[0].text
},
[],
function( result ){
this.pause( 3000 );
logContains( browser, 'li>' + result.value , browser.assert.ok );
}
);
}
);

},

after : function(browser) {
Expand Down

0 comments on commit b9c3fbc

Please sign in to comment.