-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from cbernat/datahub
feat: allow custom tracking for datahub
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
import urlParse from 'url-parse'; | ||
|
||
export function timeout(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
export function getDataHubParams(partialUrl) { | ||
const parsedUrl = urlParse(partialUrl, false); | ||
return { | ||
navigatedPage: parsedUrl.pathname, | ||
hash: parsedUrl.hash, | ||
search: parsedUrl.query, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'jest'; | ||
import { getDataHubParams } from './utils'; | ||
|
||
describe('utils', () => { | ||
describe('getDataHubParams', () => { | ||
it('should parse url with no params and no hash correctly', () => { | ||
//Arrange | ||
//Act | ||
const dataHubParams = getDataHubParams('/login'); | ||
//Assert | ||
expect(dataHubParams.navigatedPage).toBe('/login'); | ||
expect(dataHubParams.search).toBe(''); | ||
expect(dataHubParams.hash).toBe(''); | ||
}); | ||
it('should parse url with no params and hash correctly', () => { | ||
//Arrange | ||
//Act | ||
const dataHubParams = getDataHubParams('/login#hash'); | ||
//Assert | ||
expect(dataHubParams.navigatedPage).toBe('/login'); | ||
expect(dataHubParams.search).toBe(''); | ||
expect(dataHubParams.hash).toBe('#hash'); | ||
}); | ||
it('should parse url with params and no hash correctly', () => { | ||
//Arrange | ||
//Act | ||
const dataHubParams = getDataHubParams('/login?param1=value'); | ||
//Assert | ||
expect(dataHubParams.navigatedPage).toBe('/login'); | ||
expect(dataHubParams.search).toBe('?param1=value'); | ||
expect(dataHubParams.hash).toBe(''); | ||
}); | ||
it('should parse url with params and hash correctly', () => { | ||
//Arrange | ||
//Act | ||
const dataHubParams = getDataHubParams('/login?param1=value#hash'); | ||
//Assert | ||
expect(dataHubParams.navigatedPage).toBe('/login'); | ||
expect(dataHubParams.search).toBe('?param1=value'); | ||
expect(dataHubParams.hash).toBe('#hash'); | ||
}); | ||
it('should parse url with several params and several hash correctly', () => { | ||
//Arrange | ||
//Act | ||
const dataHubParams = getDataHubParams('/login?param1=value¶m2=value2#hash1#hash2'); | ||
//Assert | ||
expect(dataHubParams.navigatedPage).toBe('/login'); | ||
expect(dataHubParams.search).toBe('?param1=value¶m2=value2'); | ||
expect(dataHubParams.hash).toBe('#hash1#hash2'); | ||
}); | ||
it('should parse url with several params even badly formatted and several hash correctly', () => { | ||
//Arrange | ||
//Act | ||
const dataHubParams = getDataHubParams( | ||
'/login?param1=value?param2=value2?param3=value3#hash1#hash2', | ||
); | ||
//Assert | ||
expect(dataHubParams.navigatedPage).toBe('/login'); | ||
expect(dataHubParams.search).toBe('?param1=value?param2=value2?param3=value3'); | ||
expect(dataHubParams.hash).toBe('#hash1#hash2'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters