Skip to content

Commit

Permalink
mes-9341-WaitingRoomAnalytics (#1512)
Browse files Browse the repository at this point in the history
* Added GA4 to waiting-room-to-car

* Updated tests

* reformatted Enum
  • Loading branch information
RLCorp authored Mar 27, 2024
1 parent 4d74112 commit 708d9dd
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
AnalyticsEventCategories,
AnalyticsEvents,
AnalyticsScreenNames,
GoogleAnalyticsEvents,
GoogleAnalyticsEventsTitles,
GoogleAnalyticsEventsValues,
} from '@providers/analytics/analytics.model';
import { StoreModel } from '@shared/models/store.model';
import { Application } from '@dvsa/mes-journal-schema';
Expand Down Expand Up @@ -81,6 +84,7 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
analyticsProviderMock = TestBed.inject(AnalyticsProvider);
store$ = TestBed.inject(Store);
spyOn(analyticsProviderMock, 'logEvent');
spyOn(analyticsProviderMock, 'logGAEvent');
});

describe('waitingRoomToCarViewDidEnter', () => {
Expand All @@ -96,6 +100,15 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
effects.waitingRoomToCarViewDidEnter$.subscribe((result) => {
expect(result.type === AnalyticRecorded.type)
.toBe(true);
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.APPLICATION_REFERENCE, '123456789');
expect(analyticsProviderMock.addGACustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.TEST_CATEGORY, 'B');
expect(analyticsProviderMock.setGACurrentPage)
.toHaveBeenCalledWith(screenName);

expect(analyticsProviderMock.addCustomDimension)
.toHaveBeenCalledWith(AnalyticsDimensionIndices.CANDIDATE_ID, '1');
expect(analyticsProviderMock.addCustomDimension)
Expand Down Expand Up @@ -143,6 +156,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
actions$.next(waitingRoomToCarActions.WaitingRoomToCarError('error 123'));
// ASSERT
effects.waitingRoomToCarError$.subscribe((result) => {
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`${GoogleAnalyticsEvents.SUBMIT_FORM_ERROR}`,
GoogleAnalyticsEventsTitles.BLANK_FIELD,
'error 123',
);
expect(result.type === AnalyticRecorded.type)
.toBe(true);
expect(analyticsProviderMock.logError)
Expand All @@ -164,6 +183,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
actions$.next(waitingRoomToCarActions.WaitingRoomToCarError('error 123'));
// ASSERT
effects.waitingRoomToCarError$.subscribe((result) => {
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.SUBMIT_FORM_ERROR}`,
GoogleAnalyticsEventsTitles.BLANK_FIELD,
'error 123',
);
expect(result.type === AnalyticRecorded.type)
.toBe(true);
expect(analyticsProviderMock.logError)
Expand All @@ -187,6 +212,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
actions$.next(waitingRoomToCarActions.WaitingRoomToCarValidationError('formControl1'));
// ASSERT
effects.waitingRoomToCarValidationError$.subscribe((result) => {
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`${GoogleAnalyticsEvents.VALIDATION_ERROR}`,
GoogleAnalyticsEventsTitles.BLANK_FIELD,
'formControl1',
);
expect(result.type === AnalyticRecorded.type)
.toBe(true);
expect(analyticsProviderMock.logError)
Expand All @@ -206,6 +237,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
actions$.next(waitingRoomToCarActions.WaitingRoomToCarValidationError('formControl1'));
// ASSERT
effects.waitingRoomToCarValidationError$.subscribe((result) => {
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.VALIDATION_ERROR}`,
GoogleAnalyticsEventsTitles.BLANK_FIELD,
'formControl1',
);
expect(result.type === AnalyticRecorded.type)
.toBe(true);
expect(analyticsProviderMock.logError)
Expand Down Expand Up @@ -237,6 +274,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.DUAL_CONTROLS_CHANGED}`,
'dual controls changed to Yes',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.DUAL_CONTROLS}`,
GoogleAnalyticsEventsTitles.SELECTION,
GoogleAnalyticsEventsValues.YES,
);
});
});
it('should record an analytic when dual controls is changed to No', () => {
Expand All @@ -257,6 +300,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.DUAL_CONTROLS_CHANGED}`,
'dual controls changed to No',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.DUAL_CONTROLS}`,
GoogleAnalyticsEventsTitles.SELECTION,
GoogleAnalyticsEventsValues.NO,
);
});
});
});
Expand All @@ -280,6 +329,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.GEARBOX_CATEGORY_CHANGED}`,
'Automatic',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.SET_TRANSMISSION}`,
GoogleAnalyticsEventsTitles.TRANSMISSION_TYPE,
'Automatic',
);
});
});
it('should record an analytic when transmission is changed to Manual', () => {
Expand All @@ -300,6 +355,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.GEARBOX_CATEGORY_CHANGED}`,
'Manual',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.SET_TRANSMISSION}`,
GoogleAnalyticsEventsTitles.TRANSMISSION_TYPE,
'Manual',
);
});
});
});
Expand All @@ -323,6 +384,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.PDI_LOGBOOK_CHANGED}`,
'pdi logbook changed to Yes',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.PDI_LOGBOOK}`,
GoogleAnalyticsEventsTitles.SELECTION,
GoogleAnalyticsEventsValues.YES,
);
});
});
it('should record an analytic when pdiLogbook is changed to No', () => {
Expand All @@ -343,6 +410,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.PDI_LOGBOOK_CHANGED}`,
'pdi logbook changed to No',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.PDI_LOGBOOK}`,
GoogleAnalyticsEventsTitles.SELECTION,
GoogleAnalyticsEventsValues.NO,
);
});
});
});
Expand All @@ -366,6 +439,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.TRAINEE_LICENCE_CHANGED}`,
'trainee licence changed to Yes',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.TRAINEE_LICENCE}`,
GoogleAnalyticsEventsTitles.SELECTION,
GoogleAnalyticsEventsValues.YES,
);
});
});
it('should record an analytic when traineeLicence is changed to No', () => {
Expand All @@ -386,6 +465,12 @@ describe('WaitingRoomToCarAnalyticsEffects', () => {
`${AnalyticsEventCategories.PRACTICE_MODE} - ${AnalyticsEvents.TRAINEE_LICENCE_CHANGED}`,
'trainee licence changed to No',
);
expect(analyticsProviderMock.logGAEvent)
.toHaveBeenCalledWith(
`PM_${GoogleAnalyticsEvents.TRAINEE_LICENCE}`,
GoogleAnalyticsEventsTitles.SELECTION,
GoogleAnalyticsEventsValues.NO,
);
});
});
});
Expand Down
Loading

0 comments on commit 708d9dd

Please sign in to comment.