From 7abe22f2da09f5c6e94f614e31a0c0cbfaed80cb Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Thu, 15 Sep 2016 13:59:38 +0200 Subject: [PATCH 1/3] EZS-952: eZ Studio hangs forever with grayed out and spinner --- .../services/plugins/ezs-studionavigationhubplugin.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js b/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js index 931db0a..e8060bc 100644 --- a/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js +++ b/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js @@ -30,6 +30,8 @@ YUI.add('ezs-studionavigationhubplugin', function (Y) { siteaccesses = host.get('app').get('config.studioSiteaccesses'), contentService = host.get('capi').getContentService(); + host.detach('*:activeNavigationChange', host._navigateToFirstItemRoute); + this._isUsingAppRoutes = false; this._originalLoadFunctio = null; @@ -56,6 +58,7 @@ YUI.add('ezs-studionavigationhubplugin', function (Y) { this.onHostEvent('*:matchedRouteChange', this._updateRouteUrlFromPlatform, this); this.onHostEvent('*:activeNavigationChange', this._navigateToStudio, this); + this.afterHostEvent('*:activeNavigationChange', this._navigateToFirstItemRoute, this); this.afterHostEvent('dynamicNavigationItemView:activeChange', this._collectMenuItemViews, this); this.after('selectedLocationIdChange', this._updateContentRoute, this); @@ -141,6 +144,22 @@ YUI.add('ezs-studionavigationhubplugin', function (Y) { }, /** + * Redirects to the first item of the active zone + * + * @method _navigateToFirstItemRoute + * @protected + * @param event {Object} event facade + * @param event.newVal {String} new value of `activeNavigation` attribute + */ + _navigateToFirstItemRoute: function (event) { + if (event.newVal === NAVIGATION_ZONE_STUDIO) { + return; + } + + this.get('host')._navigateToFirstItemRoute(event); + }, + + /** * Creates a new instance of navigation menu item * * @protected From eae52cd854edaebcc5777e8fd6b373bed804d7ca Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Fri, 16 Sep 2016 10:04:11 +0200 Subject: [PATCH 2/3] EZS-952: JS unit tests --- .../assets/ezs-studionavigationhubplugin-tests.js | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js b/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js index 1a34cc4..de87c49 100644 --- a/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js +++ b/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js @@ -5,6 +5,7 @@ YUI.add('ezs-studionavigationhubplugin-tests', function (Y) { var ajaxSuccessPluginTest, ajaxFailurePluginTest, + navigateEventsPluginTest, registerTest, eventsTest, responseUrl = 'Tests/js/views/services/plugins/echo/get/json/?response=', responseData = Y.config.win.encodeURIComponent(JSON.stringify({siteaccesses: {0: 'eng', 1: 'pl'}})); @@ -161,6 +162,127 @@ YUI.add('ezs-studionavigationhubplugin-tests', function (Y) { // }, }); + navigateEventsPluginTest = new Y.Test.Case({ + name: 'eZS Studio Navigation Hub plugin navigate events tests', + + setUp: function () { + var siteaccessesUrl = responseUrl + responseData; + + this.app = new Y.Mock(); + this.capi = new Y.Mock(); + this.contentService = new Y.Mock(); + this.service = new Y.View({ + app: this.app, + capi: this.capi, + studioNavigationItems: [] + }); + this.itemView = Y.View; + this.isMethodExecuted = false; + + Y.Mock.expect(this.app, { + method: 'get', + args: [Y.Mock.Value.String], + callCount: 2, + run: function (name) { + var params = { + 'config.studioSiteaccesses': ['site'] + }; + + return params[name]; + } + }); + + Y.Mock.expect(this.app, { + method: 'on', + args: [Y.Mock.Value.String, Y.Mock.Value.Function, Y.Mock.Value.Object], + callCount: 3 + }); + + Y.Mock.expect(this.app, { + method: 'set', + args: [Y.Mock.Value.String, Y.Mock.Value.String] + }); + + Y.Mock.expect(this.app, { + method: 'navigateTo', + args: [Y.Mock.Value.String, Y.Mock.Value.Object] + }); + + Y.Mock.expect(this.capi, { + method: 'getContentService', + returns: this.contentService + }); + + Y.Mock.expect(this.contentService, { + method: 'loadRoot', + args: [Y.Mock.Value.Function] + }); + + this.service.addNavigationItem = function (item, zone) { + this.get(zone + 'NavigationItems').push(item); + }; + + this.service._getItem = function () { + return true; + }; + + this.service._navigateToFirstItemRoute = Y.bind(function () { + this.isMethodExecuted = true; + }, this); + + this.plugin = new Y.eZS.Plugin.StudioNavigationHub({ + host: this.service, + itemView: this.itemView, + siteaccessesUrl: siteaccessesUrl + }); + + this.service.addTarget(this.plugin); + }, + + tearDown: function () { + this.service.destroy(); + this.plugin.destroy(); + + delete this.service; + delete this.plugin; + delete this.app; + delete this.capi; + delete this.contentService; + }, + + 'Should not redirect user to first item in menu when entering to studio': function () { + this.service.set('activeNavigation', 'studio'); + + Y.Assert.isFalse(this.isMethodExecuted, 'Should not execute `_navigateToFirstItemRoute` method'); + + Y.Mock.verify(this.app); + Y.Mock.verify(this.capi); + Y.Mock.verify(this.contentService); + }, + + 'Should redirect user to first item in menu when entering to other tab than studio': function () { + Y.Mock.expect(this.app, { + method: 'set', + args: [Y.Mock.Value.String, Y.Mock.Value.String], + callCount: 0 + }); + + Y.Mock.expect(this.app, { + method: 'navigateTo', + args: [Y.Mock.Value.String, Y.Mock.Value.Object], + callCount: 0 + }); + + this.service.set('activeNavigation', 'performance'); + + Y.Assert.isTrue(this.isMethodExecuted, 'Should execute `_navigateToFirstItemRoute` method'); + + Y.Mock.verify(this.app); + Y.Mock.verify(this.capi); + Y.Mock.verify(this.contentService); + }, + }); + registerTest = new Y.Test.Case(Y.eZ.Test.PluginRegisterTest); registerTest.Plugin = Y.eZS.Plugin.StudioNavigationHub; registerTest.components = ['navigationHubViewService']; @@ -168,6 +290,7 @@ YUI.add('ezs-studionavigationhubplugin-tests', function (Y) { Y.Test.Runner.setName('eZS Studio Navigation Hub plugin tests'); Y.Test.Runner.add(ajaxSuccessPluginTest); Y.Test.Runner.add(ajaxFailurePluginTest); + Y.Test.Runner.add(navigateEventsPluginTest); Y.Test.Runner.add(eventsTest); Y.Test.Runner.add(registerTest); }, '', { From c285443104bda8501f1124e9817371949d0fdac7 Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Fri, 16 Sep 2016 13:31:20 +0200 Subject: [PATCH 3/3] changes after review --- .../assets/ezs-studionavigationhubplugin-tests.js | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js b/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js index de87c49..675e27d 100644 --- a/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js +++ b/Tests/js/views/services/plugins/assets/ezs-studionavigationhubplugin-tests.js @@ -177,7 +177,6 @@ YUI.add('ezs-studionavigationhubplugin-tests', function (Y) { studioNavigationItems: [] }); this.itemView = Y.View; - this.isMethodExecuted = false; Y.Mock.expect(this.app, { method: 'get', @@ -222,13 +221,16 @@ YUI.add('ezs-studionavigationhubplugin-tests', function (Y) { this.get(zone + 'NavigationItems').push(item); }; - this.service._getItem = function () { - return true; - }; + Y.Mock.expect(this.service, { + method: '_getItem', + args: [Y.Mock.Value.Object, Y.Mock.Value.Object], + returns: true + }); - this.service._navigateToFirstItemRoute = Y.bind(function () { - this.isMethodExecuted = true; - }, this); + Y.Mock.expect(this.service, { + method: '_navigateToFirstItemRoute', + args: [Y.Mock.Value.Object] + }); this.plugin = new Y.eZS.Plugin.StudioNavigationHub({ host: this.service, @@ -253,8 +255,13 @@ YUI.add('ezs-studionavigationhubplugin-tests', function (Y) { 'Should not redirect user to first item in menu when entering to studio': function () { this.service.set('activeNavigation', 'studio'); - Y.Assert.isFalse(this.isMethodExecuted, 'Should not execute `_navigateToFirstItemRoute` method'); + Y.Mock.expect(this.service, { + method: '_navigateToFirstItemRoute', + args: [Y.Mock.Value.Object], + callCount: 0, + }); + Y.Mock.verify(this.service); Y.Mock.verify(this.app); Y.Mock.verify(this.capi); Y.Mock.verify(this.contentService); @@ -275,8 +282,7 @@ YUI.add('ezs-studionavigationhubplugin-tests', function (Y) { this.service.set('activeNavigation', 'performance'); - Y.Assert.isTrue(this.isMethodExecuted, 'Should execute `_navigateToFirstItemRoute` method'); - + Y.Mock.verify(this.service); Y.Mock.verify(this.app); Y.Mock.verify(this.capi); Y.Mock.verify(this.contentService);