-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#317: Client implementation complete
- Loading branch information
Showing
12 changed files
with
919 additions
and
643 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
20 changes: 20 additions & 0 deletions
20
client/src/google-analytics/__tests__/__snapshots__/google-analytics.test.jsx.snap
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,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Google Analytics component test suite Snapshot render Tracking ID NOT set in global variable, should render empty 1`] = `""`; | ||
|
||
exports[`Google Analytics component test suite Snapshot render Tracking ID set in global variable, should render script 1`] = ` | ||
<Fragment> | ||
<script | ||
async={true} | ||
src="https://www.googletagmanager.com/gtag/js?id=UA-1337-33" | ||
/> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', 'UA-1337-33'); | ||
</script> | ||
</Fragment> | ||
`; |
30 changes: 30 additions & 0 deletions
30
client/src/google-analytics/__tests__/google-analytics.test.jsx
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,30 @@ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme/build'; | ||
|
||
describe('Google Analytics component test suite', () => { | ||
let googleAnalyticsTrackingId; | ||
let GoogleAnalytics; | ||
beforeEach(() => { | ||
jest.mock('../selectors'); | ||
googleAnalyticsTrackingId = require('../selectors').googleAnalyticsTrackingId; | ||
GoogleAnalytics = require('../').default; | ||
}); | ||
describe('Snapshot render', () => { | ||
test('Tracking ID set in global variable, should render script', () => { | ||
// Given | ||
googleAnalyticsTrackingId.mockImplementationOnce(() => 'UA-1337-33'); | ||
// When | ||
const routes = shallow(<GoogleAnalytics />); | ||
// Then | ||
expect(routes).toMatchSnapshot(); | ||
}); | ||
test('Tracking ID NOT set in global variable, should render empty', () => { | ||
// Given | ||
googleAnalyticsTrackingId.mockImplementationOnce(() => null); | ||
// When | ||
const routes = shallow(<GoogleAnalytics />); | ||
// Then | ||
expect(routes).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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,28 @@ | ||
|
||
describe('Google Analytics selectors test suite', () => { | ||
let globals; | ||
let selectors; | ||
beforeEach(() => { | ||
jest.mock('../../selectors/globals'); | ||
globals = require('../../selectors/globals'); | ||
selectors = require('../selectors'); | ||
}); | ||
describe('googleAnalyticsTrackingId', () => { | ||
test('Tacking code exists, should return tracking code', () => { | ||
// Given | ||
globals.getIsotopeConfiguration.mockImplementationOnce(() => ({googleAnalyticsTrackingId: 'UA-1337-33'})); | ||
// When | ||
const result = selectors.googleAnalyticsTrackingId(); | ||
// Then | ||
expect(result).toBe('UA-1337-33'); | ||
}); | ||
test('Tacking code NOT in configuration, should return undefined', () => { | ||
// Given | ||
globals.getIsotopeConfiguration.mockImplementationOnce(() => ({})); | ||
// When | ||
const result = selectors.googleAnalyticsTrackingId(); | ||
// Then | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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,21 @@ | ||
import React from 'react'; | ||
import {googleAnalyticsTrackingId} from './selectors'; | ||
|
||
const GoogleAnalytics = () => { | ||
const trackingId = googleAnalyticsTrackingId(); | ||
return trackingId && ( | ||
<> | ||
<script async src={`https://www.googletagmanager.com/gtag/js?id=${trackingId}`} /> | ||
<script> | ||
{` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '${trackingId}'); | ||
`} | ||
</script> | ||
</> | ||
); | ||
}; | ||
|
||
export default GoogleAnalytics; |
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,2 @@ | ||
|
||
export {default} from './google-analytics'; |
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,4 @@ | ||
import get from 'lodash/get'; | ||
import {getIsotopeConfiguration} from '../selectors/globals'; | ||
|
||
export const googleAnalyticsTrackingId = () => get(getIsotopeConfiguration(), 'googleAnalyticsTrackingId'); |
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
45 changes: 45 additions & 0 deletions
45
client/src/routes/__tests__/__snapshots__/routes.test.jsx.snap
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,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Routes component test suite Snapshot render 1`] = ` | ||
<Router | ||
basename="/" | ||
history={ | ||
Object { | ||
"action": "POP", | ||
"block": [Function], | ||
"createHref": [Function], | ||
"go": [Function], | ||
"goBack": [Function], | ||
"goForward": [Function], | ||
"length": 1, | ||
"listen": [Function], | ||
"location": Object { | ||
"hash": "", | ||
"pathname": "/", | ||
"search": "", | ||
"state": undefined, | ||
}, | ||
"push": [Function], | ||
"replace": [Function], | ||
} | ||
} | ||
> | ||
<Switch> | ||
<Route | ||
exact={true} | ||
path="/configuration-not-found" | ||
render={[Function]} | ||
/> | ||
<Connect(ApplicationReadyRoute) | ||
exact={true} | ||
path="/login" | ||
render={[Function]} | ||
/> | ||
<Connect(ApplicationReadyRoute) | ||
component={[Function]} | ||
exact={true} | ||
path="/" | ||
/> | ||
</Switch> | ||
</Router> | ||
`; |
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,13 @@ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme/build'; | ||
import Routes from '../routes'; | ||
|
||
|
||
describe('Routes component test suite', () => { | ||
test('Snapshot render', () => { | ||
// When | ||
const routes = shallow(<Routes />); | ||
// Then | ||
expect(routes).toMatchSnapshot(); | ||
}); | ||
}); |
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