3
3
var $ = window . jQuery
4
4
5
5
describe ( 'A radio group tracker' , function ( ) {
6
- 'use strict'
6
+
7
7
8
8
var GOVUK = window . GOVUK
9
9
var tracker
@@ -20,7 +20,7 @@ describe('A radio group tracker', function () {
20
20
'<form onsubmit="event.preventDefault()">' +
21
21
'<input type="radio" name="sign-in-option" value="government-gateway">' +
22
22
'<input type="radio" name="sign-in-option" value="govuk-verify">' +
23
- '<input type="radio" name="sign-in-option" value="lost-account-details ">' +
23
+ '<input type="radio" name="sign-in-option" value="create-an-account ">' +
24
24
'<button>Submit</button>' +
25
25
'</form>' +
26
26
'</div>'
@@ -30,6 +30,7 @@ describe('A radio group tracker', function () {
30
30
tracker . start ( element )
31
31
} )
32
32
33
+
33
34
it ( 'tracks government-gateway checked radio when clicking submit' , function ( ) {
34
35
element . find ( 'input[value="government-gateway"]' ) . trigger ( 'click' )
35
36
element . find ( 'form' ) . trigger ( 'submit' )
@@ -46,7 +47,101 @@ describe('A radio group tracker', function () {
46
47
expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
47
48
'Radio button chosen' , 'govuk-verify' , { transport : 'beacon' }
48
49
)
49
- } )
50
+ } ) ;
51
+
52
+ it ( 'tracks govuk-verify-with-hint event when clicking submit if user has visited verify' , function ( ) {
53
+ var data = {
54
+ status : 'OK' ,
55
+ value : true
56
+ }
57
+ tracker . trackVerifyUser ( element , data )
58
+ element . find ( 'input[value="govuk-verify"]' ) . trigger ( 'click' )
59
+ element . find ( 'form' ) . trigger ( 'submit' )
60
+
61
+ expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
62
+ 'verify-hint' , 'shown' , { transport : 'beacon' }
63
+ )
64
+ expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
65
+ 'Radio button chosen' , 'govuk-verify' , { transport : 'beacon' }
66
+ )
67
+ expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
68
+ 'Radio button chosen' , 'govuk-verify-with-hint' , { transport : 'beacon' }
69
+ )
70
+ } ) ;
71
+
72
+ it ( 'does not track govuk-verify-with-hint event when clicking submit if user has not visited verify' , function ( ) {
73
+ var data = {
74
+ status : 'OK' ,
75
+ value : false
76
+ }
77
+ tracker . trackVerifyUser ( element , data )
78
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
79
+ 'verify-hint' , 'shown' , { transport : 'beacon' }
80
+ )
81
+ element . find ( 'input[value="govuk-verify"]' ) . trigger ( 'click' )
82
+ element . find ( 'form' ) . trigger ( 'submit' )
83
+
84
+ expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
85
+ 'Radio button chosen' , 'govuk-verify' , { transport : 'beacon' }
86
+ )
87
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
88
+ 'Radio button chosen' , 'govuk-verify-with-hint' , { transport : 'beacon' }
89
+ )
90
+ } ) ;
91
+
92
+ it ( 'does not track govuk-verify-with-hint event when clicking submit if verify value is not boolean' , function ( ) {
93
+ var data = {
94
+ status : 'OK' ,
95
+ value : 'bar'
96
+ }
97
+ tracker . trackVerifyUser ( element , data )
98
+ element . find ( 'input[value="govuk-verify"]' ) . trigger ( 'click' )
99
+ element . find ( 'form' ) . trigger ( 'submit' )
100
+
101
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
102
+ 'verify-hint' , 'shown' , { transport : 'beacon' }
103
+ )
104
+ expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
105
+ 'Radio button chosen' , 'govuk-verify' , { transport : 'beacon' }
106
+ )
107
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
108
+ 'Radio button chosen' , 'govuk-verify-with-hint' , { transport : 'beacon' }
109
+ )
110
+ } ) ;
111
+
112
+ it ( 'does not track govuk-verify-with-hint event when clicking submit if verify response is null' , function ( ) {
113
+ var data = null
114
+ tracker . trackVerifyUser ( element , data )
115
+ element . find ( 'input[value="govuk-verify"]' ) . trigger ( 'click' )
116
+ element . find ( 'form' ) . trigger ( 'submit' )
117
+
118
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
119
+ 'verify-hint' , 'shown' , { transport : 'beacon' }
120
+ )
121
+ expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
122
+ 'Radio button chosen' , 'govuk-verify' , { transport : 'beacon' }
123
+ )
124
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
125
+ 'Radio button chosen' , 'govuk-verify-with-hint' , { transport : 'beacon' }
126
+ )
127
+ } ) ;
128
+
129
+ it ( 'does not track govuk-verify-with-hint event when clicking submit if verify response is not an object' , function ( ) {
130
+ var data = 'string'
131
+ tracker . trackVerifyUser ( element , data )
132
+ element . find ( 'input[value="govuk-verify"]' ) . trigger ( 'click' )
133
+ element . find ( 'form' ) . trigger ( 'submit' )
134
+
135
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
136
+ 'verify-hint' , 'shown' , { transport : 'beacon' }
137
+ )
138
+ expect ( GOVUK . analytics . trackEvent ) . toHaveBeenCalledWith (
139
+ 'Radio button chosen' , 'govuk-verify' , { transport : 'beacon' }
140
+ )
141
+ expect ( GOVUK . analytics . trackEvent ) . not . toHaveBeenCalledWith (
142
+ 'Radio button chosen' , 'govuk-verify-with-hint' , { transport : 'beacon' }
143
+ )
144
+ } ) ;
50
145
51
146
it ( 'tracks no choice when clicking submit and checked nothing' , function ( ) {
52
147
element . find ( 'form' ) . trigger ( 'submit' )
0 commit comments