From 977222cbfb7b8ddb48dd460ccf52cd95deb3b624 Mon Sep 17 00:00:00 2001 From: Philipp Pracht Date: Fri, 3 Jun 2022 16:47:10 +0200 Subject: [PATCH] fix test --- core/src/utilities/helpers/routing-helpers.js | 14 ++++++++--- .../utilities/helpers/routing-helpers.spec.js | 23 ++++++------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/core/src/utilities/helpers/routing-helpers.js b/core/src/utilities/helpers/routing-helpers.js index db15eac33b..aa1d35c4f3 100644 --- a/core/src/utilities/helpers/routing-helpers.js +++ b/core/src/utilities/helpers/routing-helpers.js @@ -138,13 +138,21 @@ class RoutingHelpersClass { return hashRoutingActive ? this.getLocationHashQueryParams() : this.getLocationSearchQueryParams(); } + getLocation() { + return location; + } + getLocationHashQueryParams() { - const queryParamIndex = location.hash.indexOf(this.defaultQueryParamSeparator); - return queryParamIndex !== -1 ? RoutingHelpers.parseParams(location.hash.slice(queryParamIndex + 1)) : {}; + const queryParamIndex = RoutingHelpers.getLocation().hash.indexOf(this.defaultQueryParamSeparator); + return queryParamIndex !== -1 + ? RoutingHelpers.parseParams(RoutingHelpers.getLocation().hash.slice(queryParamIndex + 1)) + : {}; } getLocationSearchQueryParams() { - return location.search ? RoutingHelpers.parseParams(location.search.slice(1)) : {}; + return RoutingHelpers.getLocation().search + ? RoutingHelpers.parseParams(RoutingHelpers.getLocation().search.slice(1)) + : {}; } /** diff --git a/core/test/utilities/helpers/routing-helpers.spec.js b/core/test/utilities/helpers/routing-helpers.spec.js index 5e8015b4f5..89d325bf5f 100644 --- a/core/test/utilities/helpers/routing-helpers.spec.js +++ b/core/test/utilities/helpers/routing-helpers.spec.js @@ -593,40 +593,31 @@ describe('Routing-helpers', () => { }); describe('getModalPathFromPath & getModalParamsFromPath', () => { + const mockLocation = new URL('http://localhost'); beforeEach(() => { sinon.stub(RoutingHelpers, 'getModalViewParamName').returns('modal'); - sinon.stub(RoutingHelpers, 'getQueryParams'); + sinon.stub(RoutingHelpers, 'getLocation'); + RoutingHelpers.getLocation.returns(mockLocation); + mockLocation.href = 'http://localhost'; }); afterEach(() => { sinon.restore(); }); it('without modal param', () => { - RoutingHelpers.getQueryParams.returns({}); assert.equal(RoutingHelpers.getModalPathFromPath('/path/one'), null); }); it('with modal', () => { - const allQueryParams = { - modal: '%2Fhome%2Fchild-2' - }; - RoutingHelpers.getQueryParams.returns(allQueryParams); + mockLocation.search = '?modal=%2Fhome%2Fchild-2'; assert.equal(RoutingHelpers.getModalPathFromPath('defined through stub'), '/home/child-2'); }); it('with modal params', () => { - const allQueryParams = { - modal: '%2Fhome%2Fchild-2', - modalParams: '%7B%22title%22%3A%22Real%20Child%22%7D' - }; - RoutingHelpers.getQueryParams.returns(allQueryParams); + mockLocation.search = '?modal=%2Fhome%2Fchild-2&modalParams=%7B%22title%22%3A%22Real%20Child%22%7D'; assert.equal(RoutingHelpers.getModalPathFromPath('defined through stub'), '/home/child-2'); assert.deepEqual(RoutingHelpers.getModalParamsFromPath('defined through stub'), { title: 'Real Child' }); }); it('with custom modal param name', () => { - const allQueryParams = { - custom: '%2Fhome%2Fchild-2', - customParams: '%7B%22title%22%3A%22Real%20Child%22%7D' - }; + mockLocation.search = '?custom=%2Fhome%2Fchild-2&customParams=%7B%22title%22%3A%22Real%20Child%22%7D'; RoutingHelpers.getModalViewParamName.returns('custom'); - RoutingHelpers.getQueryParams.returns(allQueryParams); assert.equal(RoutingHelpers.getModalPathFromPath('defined through stub'), '/home/child-2'); assert.deepEqual(RoutingHelpers.getModalParamsFromPath('defined through stub'), { title: 'Real Child' });