feat(aio): add google analytics (#15081)

This commit is contained in:
Ward Bell
2017-03-13 18:08:23 -07:00
committed by Chuck Jazdzewski
parent 914797a8ff
commit 1c1085b140
12 changed files with 283 additions and 13 deletions

View File

@ -2,6 +2,7 @@ import { async, inject, ComponentFixture, TestBed } from '@angular/core/testing'
import { APP_BASE_HREF } from '@angular/common';
import { AppComponent } from './app.component';
import { AppModule } from './app.module';
import { GaService } from 'app/shared/ga.service';
import { SearchService } from 'app/search/search.service';
import { MockSearchService } from 'testing/search.service';
@ -14,7 +15,8 @@ describe('AppComponent', () => {
imports: [ AppModule ],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: SearchService, useClass: MockSearchService }
{ provide: SearchService, useClass: MockSearchService },
{ provide: GaService, useClass: TestGaService }
]
});
TestBed.compileComponents();
@ -29,6 +31,18 @@ describe('AppComponent', () => {
expect(component).toBeDefined();
});
describe('google analytics', () => {
it('should call gaService.locationChanged with initial URL', () => {
const url = window.location.pathname.substr(1); // strip leading '/'
const { locationChanged } = TestBed.get(GaService) as TestGaService;
expect(locationChanged.calls.count()).toBe(1, 'gaService.locationChanged');
const args = locationChanged.calls.first().args;
expect(args[0]).toBe(url);
});
// Todo: add test to confirm tracking URL when navigate.
});
describe('isHamburgerVisible', () => {
});
@ -57,3 +71,7 @@ describe('AppComponent', () => {
}));
});
});
class TestGaService {
locationChanged = jasmine.createSpy('locationChanged');
}