Skip to content

Commit

Permalink
fix(gst): add provided in root to gst closes #304
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed Oct 16, 2018
1 parent ea1cf3a commit aaa054f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
70 changes: 43 additions & 27 deletions src/lib/providers/gst/gst.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { fakeAsync, inject, ComponentFixture, TestBed } from '@angular/core/testing';
import {
fakeAsync,
inject,
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import { Angulartics2 } from 'angulartics2';
import { advance, createRoot, RootCmp, TestModule } from '../../test.mocks';
import { Angulartics2GoogleGlobalSiteTag } from './gst';


jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
declare var window: any;

Expand All @@ -19,14 +23,14 @@ describe('Angulartics2GoogleGlobalSiteTag', () => {
});

window.gtag = gtag = jasmine.createSpy('gtag');
window.ga = ga = function (callback) {
window.ga = ga = function(callback) {
callback();
};
window.ga.getAll = ga.getAll = function () {
window.ga.getAll = ga.getAll = function() {
return {
forEach: function (callback) {
forEach: function(callback) {
const tracker = {
get: function (value) {
get: function(value) {
return 'UA-111111111-1';
},
};
Expand All @@ -36,22 +40,30 @@ describe('Angulartics2GoogleGlobalSiteTag', () => {
};
});

it('should track pages',
fakeAsync(inject([Angulartics2, Angulartics2GoogleGlobalSiteTag],
(angulartics2: Angulartics2, angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag) => {
it('should track pages', fakeAsync(
inject(
[Angulartics2, Angulartics2GoogleGlobalSiteTag], (
angulartics2: Angulartics2,
angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag,
) => {
fixture = createRoot(RootCmp);
angulartics2GoogleGlobalSiteTag.startTracking();
angulartics2.pageTrack.next({ path: '/abc' });
advance(fixture);
expect(gtag.calls.count()).toEqual(1);
expect(gtag).toHaveBeenCalledWith('config', 'UA-111111111-1', { 'page_path': '/abc' });
expect(gtag).toHaveBeenCalledWith('config', 'UA-111111111-1', {
page_path: '/abc',
});
},
)),
);
),
));

it('should track events',
fakeAsync(inject([Angulartics2, Angulartics2GoogleGlobalSiteTag],
(angulartics2: Angulartics2, angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag) => {
it('should track events', fakeAsync(
inject(
[Angulartics2, Angulartics2GoogleGlobalSiteTag], (
angulartics2: Angulartics2,
angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag,
) => {
fixture = createRoot(RootCmp);
angulartics2GoogleGlobalSiteTag.startTracking();
angulartics2.eventTrack.next({
Expand All @@ -62,7 +74,7 @@ describe('Angulartics2GoogleGlobalSiteTag', () => {
gstCustom: {
customKey: 'customValue',
},
}
},
});
advance(fixture);
expect(gtag).toHaveBeenCalledWith('event', 'do', {
Expand All @@ -72,16 +84,21 @@ describe('Angulartics2GoogleGlobalSiteTag', () => {
non_interaction: undefined,
customKey: 'customValue',
});
}
)),
);
},
),
));

it('should track exceptions',
fakeAsync(inject([Angulartics2, Angulartics2GoogleGlobalSiteTag],
(angulartics2: Angulartics2, angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag) => {
it('should track exceptions', fakeAsync(
inject([Angulartics2, Angulartics2GoogleGlobalSiteTag], (
angulartics2: Angulartics2,
angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag,
) => {
fixture = createRoot(RootCmp);
angulartics2GoogleGlobalSiteTag.startTracking();
angulartics2.exceptionTrack.next({ description: 'bugger', gstCustom: { appId: 'app', appName: 'Test App', appVersion: '0.1' } });
angulartics2.exceptionTrack.next({
description: 'bugger',
gstCustom: { appId: 'app', appName: 'Test App', appVersion: '0.1' },
});
advance(fixture);
expect(gtag).toHaveBeenCalledWith('event', 'exception', {
event_category: 'interaction',
Expand All @@ -94,8 +111,7 @@ describe('Angulartics2GoogleGlobalSiteTag', () => {
appName: 'Test App',
appVersion: '0.1',
});
}
)),
);

},
),
));
});
2 changes: 1 addition & 1 deletion src/lib/providers/gst/gst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class GoogleGlobalSiteTagDefaults implements GoogleGlobalSiteTagSettings
}
}

@Injectable()
@Injectable({ providedIn: 'root' })
export class Angulartics2GoogleGlobalSiteTag {

constructor(protected angulartics2: Angulartics2) {
Expand Down

0 comments on commit aaa054f

Please sign in to comment.