Permalink
Browse files

1711 newsletter footer ga (#2931)

* wip add ga to newsletter footer form

* fix props in test

* fix lint errors in test

* actually fix up tests
  • Loading branch information...
meandavejustice authored and lmorchard committed Oct 12, 2017
1 parent b4f0578 commit 77c3321abcd61c02f280421e5eb43dbb6c64ef9d
@@ -3,11 +3,12 @@ import classnames from 'classnames';
import { Localized } from 'fluent-react/compat';
import React from 'react';
import LayoutWrapper from './LayoutWrapper';
import NewsletterForm from './NewsletterForm';
import LayoutWrapper from '../LayoutWrapper';
import NewsletterForm from '../NewsletterForm';
type NewsletterFooterProps = {
getWindowLocation: Function,
sendToGA: Function,
newsletterForm: {
failed: boolean,
succeeded: boolean
@@ -19,6 +20,12 @@ export default class NewsletterFooter extends React.Component {
renderError() {
if (this.props.newsletterForm.failed) {
this.props.sendToGA('event', {
eventCategory: 'HomePage Interactions',
eventAction: 'footer newsletter form submit',
eventLabel: 'email failed to submit to basket'
});
return (
<Localized id="newsletterFooterError">
<div className="error">
@@ -31,6 +38,12 @@ export default class NewsletterFooter extends React.Component {
}
renderSuccess() {
this.props.sendToGA('event', {
eventCategory: 'HomePage Interactions',
eventAction: 'footer newsletter form success',
eventLabel: 'email submitted to basket'
});
return (
<header className="success-header">
<Localized id="newsletterFooterSuccessHeader">
@@ -1,24 +1,33 @@
/* global describe, it */
import React from 'react';
import { expect } from 'chai';
import sinon from 'sinon';
import { shallow } from 'enzyme';
import NewsletterFooter from '../../../src/app/components/NewsletterFooter';
import NewsletterFooter from './index';
describe('app/components/NewsletterFooter', () => {
const props = {
getWindowLocation: sinon.spy(() => 'https://example.com'),
sendToGA: sinon.spy(),
newsletterForm: {
subscribe: sinon.spy(),
setEmail: sinon.spy(),
setPrivacy: sinon.spy()
}
};
const _subject = (form) => {
const props = {
const _subject = (form) => { // eslint-disable-line no-underscore-dangle
const mergedProps = Object.assign(props, {
getWindowLocation: sinon.spy(() => 'https://example.com'),
newsletterForm: {
subscribe: sinon.spy(),
setEmail: sinon.spy(),
setPrivacy: sinon.spy(),
...form
}
};
return shallow(<NewsletterFooter {...props} />);
});
return shallow(<NewsletterFooter {...mergedProps} />);
};
describe('error notification', () => {
@@ -55,6 +64,24 @@ describe('app/components/NewsletterFooter', () => {
expect(subject.hasClass('success')).to.equal(true);
});
it('should have called sendToGA with a success event when succeeded=true', () => {
_subject({ succeeded: true, failed: false });
expect(props.sendToGA.lastCall.args).to.deep.equal(['event', {
eventCategory: 'HomePage Interactions',
eventAction: 'footer newsletter form success',
eventLabel: 'email submitted to basket'
}]);
});
it('should have called sendToGA with a failure event when succeeded=false', () => {
_subject({ failed: true, succeeded: false });
expect(props.sendToGA.lastCall.args).to.deep.equal(['event', {
eventCategory: 'HomePage Interactions',
eventAction: 'footer newsletter form submit',
eventLabel: 'email failed to submit to basket'
}]);
});
it('should pass props to the child NewsletterForm', () => {
const subject = _subject({ foo: 'bar' });
expect(subject.find('NewsletterForm').prop('foo')).to.equal('bar');

0 comments on commit 77c3321

Please sign in to comment.