diff --git a/Resources/public/js/views/services/ez-discoverybarviewservice.js b/Resources/public/js/views/services/ez-discoverybarviewservice.js index ca33c92ab..63f29cb0f 100644 --- a/Resources/public/js/views/services/ez-discoverybarviewservice.js +++ b/Resources/public/js/views/services/ez-discoverybarviewservice.js @@ -60,6 +60,9 @@ YUI.add('ez-discoverybarviewservice', function (Y) { startingLocationId: startingLocationId, minDiscoverDepth: rootDepth, confirmLabel: Y.eZ.trans('view.content.label', {}, 'bar'), + isSelectable: function (contentStruct) { + return startingLocationId !== contentStruct.location.get('id'); + } }, }); }, diff --git a/Tests/js/views/services/assets/ez-discoverybarviewservice-tests.js b/Tests/js/views/services/assets/ez-discoverybarviewservice-tests.js index 6ae7890ca..e3cb80e5a 100644 --- a/Tests/js/views/services/assets/ez-discoverybarviewservice-tests.js +++ b/Tests/js/views/services/assets/ez-discoverybarviewservice-tests.js @@ -131,11 +131,15 @@ YUI.add('ez-discoverybarviewservice-tests', function (Y) { }, "Should fire contentDiscover with a starting location on browseAction event": function () { - var contentDiscoverFired = false; + var contentDiscoverFired = false, + otherLocation = new Y.Base(); + otherLocation.set('id', 'AnyOtherId'); this.service.on('contentDiscover', Y.bind(function (e) { contentDiscoverFired = true; + Assert.isFunction(e.config.isSelectable, "config should have a function named isSelectable"); + Assert.areSame( e.config.startingLocationId, this.locationId, "startingLocationId should have the id of the current location of the locationViewView" @@ -150,6 +154,40 @@ YUI.add('ez-discoverybarviewservice-tests', function (Y) { Assert.isTrue(contentDiscoverFired, 'contentDiscover should be fired'); }, + + "Should NOT be able to select the current location when content discovering": function () { + var contentDiscoverFired = false; + + this.service.on('contentDiscover', Y.bind(function (e) { + contentDiscoverFired = true; + + Y.Assert.isFalse( + e.config.isSelectable({location: this.location}), + "isSelectable should return FALSE if location is the same" + ); + }, this)); + this.service.fire('browseAction'); + + Assert.isTrue(contentDiscoverFired, 'contentDiscover should be fired'); + }, + + "Should be able to select any other location than the current location when content discovering": function () { + var contentDiscoverFired = false, + otherLocation = new Y.Base(); + + otherLocation.set('id', 'AnyOtherId'); + this.service.on('contentDiscover', Y.bind(function (e) { + contentDiscoverFired = true; + + Y.Assert.isTrue( + e.config.isSelectable({location: otherLocation}), + "isSelectable should return TRUE if location is not the same" + ); + }, this)); + this.service.fire('browseAction'); + + Assert.isTrue(contentDiscoverFired, 'contentDiscover should be fired'); + }, "Should fire contentDiscover without starting location and minimum discover depth when current view is NOT a locationViewView": function () { var contentDiscoverFired = false;