Skip to content

Commit

Permalink
fix(history-service): set initial hash from root location on primary …
Browse files Browse the repository at this point in the history
…location (#527)
  • Loading branch information
unstubbable authored and clebert committed Jul 11, 2019
1 parent e681706 commit 052f7aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,24 @@ describe('#createRootLocationTransformer', () => {

describe('#getConsumerPathFromRootLocation', () => {
describe('with consumers encoded into the query parameter', () => {
it('returns the consumer-specific locations', () => {
it('returns the consumer-specific locations including a hash for the primary consumer', () => {
const locationTransformer = createRootLocationTransformer({
consumerPathsQueryParamName: '---',
primaryConsumerHistoryKey: 'testPri'
});

const rootLocation = {
pathname: '/foo',
search: `?bar=1&---=${encodeConsumerPaths({test1: '/baz?qux=3'})}`
search: `?bar=1&---=${encodeConsumerPaths({test1: '/baz?qux=3'})}`,
hash: '#some-anchor'
};

expect(
locationTransformer.getConsumerPathFromRootLocation(
rootLocation as Location,
'testPri'
)
).toEqual('/foo?bar=1');
).toEqual('/foo?bar=1#some-anchor');

expect(
locationTransformer.getConsumerPathFromRootLocation(
Expand Down
5 changes: 3 additions & 2 deletions packages/history-service/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,16 @@ describe('defineHistoryService', () => {
destroyHistories();

const consumerStates = {test1: 'foo state', test2: 'bar state'};
const url = createUrl({test1: '/foo', test2: 'bar'});
const url = createUrl({test1: '/foo#some-anchor', test2: 'bar'});

window.history.pushState({state: consumerStates}, '', url);

createHistories();

expect(history1.location).toMatchObject({
pathname: '/foo',
state: 'foo state'
state: 'foo state',
hash: '#some-anchor'
});

expect(history2.location).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ export function createRootLocationTransformer(
if (isPrimaryConsumer) {
searchParams.delete(consumerPathsQueryParamName);

const pathname = rootLocation.pathname;
const {pathname, hash} = rootLocation;
const search = serializeSearchParams(searchParams);

return history.createPath({pathname, search});
return history.createPath({pathname, search, hash});
}

const consumerPaths = searchParams.get(consumerPathsQueryParamName);
Expand Down

0 comments on commit 052f7aa

Please sign in to comment.