Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #839 from ezsystems/Fix-EZP-27059_UDW_should_work_…
Browse files Browse the repository at this point in the history
…without_correct_visible_method_1.7

Fix EZP-27059: UDW should work without correct visible method
  • Loading branch information
StephaneDiot authored Apr 25, 2017
2 parents 4c7fd34 + 62d82f9 commit fa9e063
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
15 changes: 14 additions & 1 deletion Resources/public/js/views/ez-universaldiscoveryview.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,12 @@ YUI.add('ez-universaldiscoveryview', function (Y) {
*/
_updateMethods: function () {
var visibleMethod = this.get('visibleMethod'),
startingLocationId = this.get('startingLocationId');
startingLocationId = this.get('startingLocationId'),
defaultMethodView;

if ( !this.get('active') ) {
return;
}
/**
* Stores a reference to the visible method view
*
Expand All @@ -281,6 +285,10 @@ YUI.add('ez-universaldiscoveryview', function (Y) {
Y.Array.each(this.get('methods'), function (method) {
var visible = (visibleMethod === method.get('identifier'));

if (!visible && (method.get('identifier') === Y.eZ.UniversalDiscoveryView.ATTRS.visibleMethod.value)) {
defaultMethodView = method;
}

method.setAttrs({
'multiple': this.get('multiple'),
'loadContent': true,
Expand All @@ -293,6 +301,11 @@ YUI.add('ez-universaldiscoveryview', function (Y) {
this._visibleMethodView = method;
}
}, this);

if ( !this._visibleMethodView ) {
defaultMethodView.set('visible', true);
this._visibleMethodView = defaultMethodView;
}
},

/**
Expand Down
24 changes: 22 additions & 2 deletions Tests/js/views/assets/ez-universaldiscoveryview-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ YUI.add('ez-universaldiscoveryview-tests', function (Y) {
this.method1 = new Y.eZ.UniversalDiscoveryMethodBaseView();
this.method1._set('identifier', 'method1');
this.method2 = new Y.eZ.UniversalDiscoveryMethodBaseView();
this.method2._set('identifier', 'method2');
this.method2._set('identifier', Y.eZ.UniversalDiscoveryView.ATTRS.visibleMethod.value);
this.confirmedList = new Y.View();
this.view = new Y.eZ.UniversalDiscoveryView({
container: '.container',
title: this.title,
visibleMethod: 'method2',
visibleMethod: Y.eZ.UniversalDiscoveryView.ATTRS.visibleMethod.value,
multiple: this.multiple,
methods: [this.method1, this.method2],
confirmedListView: this.confirmedList,
Expand All @@ -425,6 +425,7 @@ YUI.add('ez-universaldiscoveryview-tests', function (Y) {
},

"Should initialize the visibility flag of the method views": function () {
this.view.set('visibleMethod', 'method2');
this.view.render();
this.view.set('active', true);
Assert.isTrue(
Expand All @@ -438,6 +439,7 @@ YUI.add('ez-universaldiscoveryview-tests', function (Y) {
},

"Should change the visible flag depending on visibleMethod": function () {
this.view.set('active', true);
this.view.set('visibleMethod', 'method1');
Assert.isTrue(
this.method1.get('visible'),
Expand All @@ -449,6 +451,24 @@ YUI.add('ez-universaldiscoveryview-tests', function (Y) {
);
},

"Should change the visible flag depending on visibleMethod if view is NOT active": function () {
this.view.set('visibleMethod', 'method1');
Assert.isFalse(
this.method1.get('visible'),
"The method1 should NOT be visible"
);
},

"Should use the default visible method when a wrong method name is setted": function () {
this.view.render();
this.view.set('active', true);
this.view.set('visibleMethod', 'methodUnknown');
Assert.isTrue(
this.method2.get('visible'),
"The method2 should not be visible"
);
},

"Should initialize the isSelected function of the method views": function () {
var isSelectableResult = false,
isSelectable = function (contentStruct) {return isSelectableResult;},
Expand Down

0 comments on commit fa9e063

Please # to comment.