Skip to content

Commit

Permalink
Bring up code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkmalmgren committed Sep 1, 2017
1 parent 243b620 commit 16b1c7c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
64 changes: 64 additions & 0 deletions src/app/components/pages/giving.spec.ts
@@ -0,0 +1,64 @@
import { expect, sinon, async, MockBuilder } from 'testing';
import { GivingComponent } from './giving';
import { Analytics, Observable } from 'app/services';

describe('GivingComponent', () => {

describe('give', () => {
it('should stop propogation', () => {
const analytics = MockBuilder.of(Analytics)
.withStub('event', Observable.empty())
.build();

const giving = new GivingComponent(analytics);
expect(giving.give('easy')).to.be.false;
});

[
['easy', 'easytithe'],
['adventist', 'adventistgiving'],
['default', 'adventistgiving']
].forEach(([type, href]) => {
it('should record analytics event and then navigate', () => {
const analytics = MockBuilder.of(Analytics)
.withStub('event', Observable.of(''))
.build();

const location = {} as Location;

const giving = new GivingComponent(analytics);
giving._location = location;
giving.give(type);

expect(analytics.event).to.have.been.calledWithMatch('nav');
expect(location.href).to.contain(href);
});
});
});

describe('showing the envelope', () => {
it('should register analytics event', () => {
const analytics = MockBuilder.of(Analytics)
.withStub('event', Observable.of(''))
.build();

const giving = new GivingComponent(analytics);
const response = giving.showEnvelope();

expect(response).to.be.false;
expect(giving.envelopeShown).to.be.true;
expect(analytics.event).to.have.been.calledWithMatch('overlay');
});
});

describe('hiding the envelope', () => {
it('just hide the envelope', () => {
const giving = new GivingComponent(undefined);
giving.envelopeShown = true;
giving.hideEnvelope();

expect(giving.envelopeShown).to.be.false;
});
});

});
3 changes: 2 additions & 1 deletion src/app/components/pages/giving.ts
Expand Up @@ -8,6 +8,7 @@ import { Analytics } from '../../services';
export class GivingComponent {

envelopeShown: boolean = false;
_location: Location = location;

constructor(
private analytics: Analytics
Expand All @@ -16,7 +17,7 @@ export class GivingComponent {
give(type: string): boolean {
this.analytics.event('nav', 'leave', 'donate')
.subscribe(() => {
location.href = (type === 'easy') ?
this._location.href = (type === 'easy') ?
'http://www.easytithe.com/dl/?uid=boli301244t7' :
'https://www.adventistgiving.org/?OrgID=ANF4BV';
});
Expand Down

0 comments on commit 16b1c7c

Please sign in to comment.