Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
hardl committed Jun 3, 2022
1 parent aa4b9d6 commit 977222c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
14 changes: 11 additions & 3 deletions core/src/utilities/helpers/routing-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
: {};
}

/**
Expand Down
23 changes: 7 additions & 16 deletions core/test/utilities/helpers/routing-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down

0 comments on commit 977222c

Please sign in to comment.