From 3f86928a8e41cac1081897d3edcb377cb278a2a1 Mon Sep 17 00:00:00 2001 From: Chad Brokaw <36685920+chadbrokaw@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:43:11 -0700 Subject: [PATCH] fix angular tests --- .../javascripts/shared/AnalyticsService.js.coffee | 15 +++++---------- .../ShortFormApplicationController.js.coffee | 4 ++-- .../short_form_application_controller_spec.coffee | 3 +++ .../short_form_navigation_service_spec.coffee | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/shared/AnalyticsService.js.coffee b/app/assets/javascripts/shared/AnalyticsService.js.coffee index a49653ebb4..48410fdb82 100644 --- a/app/assets/javascripts/shared/AnalyticsService.js.coffee +++ b/app/assets/javascripts/shared/AnalyticsService.js.coffee @@ -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 = -> diff --git a/app/assets/javascripts/short-form/ShortFormApplicationController.js.coffee b/app/assets/javascripts/short-form/ShortFormApplicationController.js.coffee index 853a4b8b5a..b62f733709 100644 --- a/app/assets/javascripts/short-form/ShortFormApplicationController.js.coffee +++ b/app/assets/javascripts/short-form/ShortFormApplicationController.js.coffee @@ -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}) diff --git a/spec/javascripts/controllers/short_form_application_controller_spec.coffee b/spec/javascripts/controllers/short_form_application_controller_spec.coffee index 7936401526..d34a13e98f 100644 --- a/spec/javascripts/controllers/short_form_application_controller_spec.coffee +++ b/spec/javascripts/controllers/short_form_application_controller_spec.coffee @@ -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: diff --git a/spec/javascripts/services/short_form_navigation_service_spec.coffee b/spec/javascripts/services/short_form_navigation_service_spec.coffee index a8dbc8706c..0596fdb367 100644 --- a/spec/javascripts/services/short_form_navigation_service_spec.coffee +++ b/spec/javascripts/services/short_form_navigation_service_spec.coffee @@ -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', ->