Skip to content

Commit

Permalink
fix angular tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chadbrokaw committed Dec 19, 2024
1 parent ba927d9 commit 3f86928
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
15 changes: 5 additions & 10 deletions app/assets/javascripts/shared/AnalyticsService.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ AnalyticsService = ($state) ->
Service = {}
Service.timer = {}

Service.resetProperties = {
# Any properties that should be reset on each event
}

Service.trackEvent = (event, properties) ->
dataLayer = window.dataLayer || []
combinedProperties = Object.assign({}, Service.resetProperties, properties)
unless combinedProperties.label
unless properties.label
# by default, grab the end of the URL e.g. the "contact" from "/x/y/z/contact"
current_path = _.first(_.last($state.current.url.split('/')).split('?'))
combinedProperties.label = current_path
combinedProperties.event = event
combinedProperties.event_timestamp = new Date().toISOString();
dataLayer.push(combinedProperties)
properties.label = current_path
properties.event = event
properties.event_timestamp = new Date().toISOString();
dataLayer.push(properties)

# Tracks the current page as the user navigates
Service.trackCurrentPage = ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ ShortFormApplicationController = (
if $window.ACCOUNT_INFORMATION_PAGES_REACT is "true"
$window.removeEventListener('beforeunload', ShortFormApplicationService.onExit)
$window.removeEventListener('unload', $scope.onUnload)

AnalyticsService.trackApplicationAbandon($scope.listing.Id, AccountService.loggedInUser.id, 'Logged In Save and Finish Later')
# user id should always be present, but we are being cautious
AnalyticsService.trackApplicationAbandon($scope.listing.Id, AccountService.loggedInUser?.id, 'Logged In Save and Finish Later')
# ShortFormNavigationService.isLoading(false) will happen after My Apps are loaded
# go to my applications without tracking Form Success
$scope.go('dahlia.my-applications', {skipConfirm: true})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ do ->
trackFormSuccess: jasmine.createSpy()
trackFormError: jasmine.createSpy()
trackFormAbandon: jasmine.createSpy()
trackApplicationStart: jasmine.createSpy()
trackApplicationComplete: jasmine.createSpy()
trackApplicationAbandon: jasmine.createSpy()
fakeShortFormApplicationService =
form:
applicationForm:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ do ->
describe 'goToApplicationPage', ->
it 'calls AnalyticsService.trackFormSuccess with "Application"', ->
ShortFormNavigationService.goToApplicationPage()
expect(fakeAnalyticsService.trackFormSuccess).toHaveBeenCalledWith('Application')
expect(fakeAnalyticsService.trackFormSuccess).toHaveBeenCalledWith('Application Page View')

describe 'when params are not provided', ->
it 'calls $state.go with the given path', ->
Expand Down

0 comments on commit 3f86928

Please sign in to comment.