@@ -21,6 +21,7 @@ goog.provide('firebaseui.auth.ui.element.TosPpTestHelper');
2121goog . setTestOnly ( 'firebaseui.auth.ui.element.TosPpTestHelper' ) ;
2222
2323goog . require ( 'firebaseui.auth.ui.element' ) ;
24+ goog . require ( 'goog.testing.events' ) ;
2425
2526
2627goog . scope ( function ( ) {
@@ -37,60 +38,116 @@ goog.inherits(element.TosPpTestHelper, element.ElementTestHelper);
3738
3839/** @override */
3940element . TosPpTestHelper . prototype . resetState = function ( ) {
41+ this . tosLinkClicked_ = false ;
42+ this . privacyPolicyLinkClicked_ = false ;
4043} ;
4144
4245
43- /** Asserts the full message of ToS and Privacy Policy is displayed. */
46+ /** Handler for ToS link click event. */
47+ element . TosPpTestHelper . prototype . onTosLinkClick = function ( ) {
48+ this . tosLinkClicked_ = true ;
49+ } ;
50+
51+
52+ /** Handler for Privacy Policy link click event. */
53+ element . TosPpTestHelper . prototype . onPpLinkClick = function ( ) {
54+ this . privacyPolicyLinkClicked_ = true ;
55+ } ;
56+
57+
58+ /**
59+ * Asserts the full message of ToS and Privacy Policy is displayed.
60+ * @param {?function()|undefined } tosCallback The ToS callback.
61+ * @param {?function()|undefined } privacyPolicyCallback The Privacy Policy
62+ * callback.
63+ */
4464element . TosPpTestHelper . prototype . assertFullMessage = function (
45- tosUrl , privacyPolicyUrl ) {
65+ tosCallback , privacyPolicyCallback ) {
4666 var element = this . component . getTosPpElement ( ) ;
47- if ( ! tosUrl && ! privacyPolicyUrl ) {
67+ if ( ! tosCallback && ! privacyPolicyCallback ) {
4868 assertNull ( element ) ;
4969 } else {
5070 assertTrue ( element . classList . contains ( 'firebaseui-tospp-full-message' ) ) ;
51- assertEquals ( tosUrl , this . component . getTosLinkElement ( ) . href ) ;
52- assertEquals ( privacyPolicyUrl , this . component . getPpLinkElement ( ) . href ) ;
71+ this . assertTosLinkClicked_ ( ) ;
72+ this . assertPpLinkClicked_ ( ) ;
5373 }
5474} ;
5575
5676
57- /** Asserts the footer of ToS and Privacy Policy links is displayed. */
77+ /**
78+ * Asserts the footer of ToS and Privacy Policy links is displayed.
79+ * @param {?function()|undefined } tosCallback The ToS callback.
80+ * @param {?function()|undefined } privacyPolicyCallback The Privacy Policy
81+ * callback.
82+ */
5883element . TosPpTestHelper . prototype . assertFooter = function (
59- tosUrl , privacyPolicyUrl ) {
84+ tosCallback , privacyPolicyCallback ) {
6085 var element = this . component . getTosPpListElement ( ) ;
61- if ( ! tosUrl && ! privacyPolicyUrl ) {
86+ if ( ! tosCallback && ! privacyPolicyCallback ) {
6287 assertNull ( element ) ;
6388 } else {
6489 assertTrue ( element . classList . contains ( 'firebaseui-tos-list' ) ) ;
65- assertEquals ( tosUrl , this . component . getTosLinkElement ( ) . href ) ;
66- assertEquals ( privacyPolicyUrl , this . component . getPpLinkElement ( ) . href ) ;
90+ this . assertTosLinkClicked_ ( ) ;
91+ this . assertPpLinkClicked_ ( ) ;
6792 }
6893} ;
6994
7095
71- /** Asserts the full message of ToS and Privacy Policy and a notice to the user
72- * about SMS rates for phone authentication are displayed. */
96+ /**
97+ * Asserts the full message of ToS and Privacy Policy and a notice to the user
98+ * about SMS rates for phone authentication are displayed.
99+ * @param {?function()|undefined } tosCallback The ToS callback.
100+ * @param {?function()|undefined } privacyPolicyCallback The Privacy Policy
101+ * callback.
102+ */
73103element . TosPpTestHelper . prototype . assertPhoneFullMessage = function (
74- tosUrl , privacyPolicyUrl ) {
104+ tosCallback , privacyPolicyCallback ) {
75105 var element = this . component . getTosPpElement ( ) ;
76106 assertTrue ( element . classList . contains ( 'firebaseui-phone-tos' ) ) ;
77- if ( ! tosUrl && ! privacyPolicyUrl ) {
107+ if ( ! tosCallback && ! privacyPolicyCallback ) {
78108 assertNull ( this . component . getTosLinkElement ( ) ) ;
79109 assertNull ( this . component . getPpLinkElement ( ) ) ;
80110 } else {
81- assertEquals ( tosUrl , this . component . getTosLinkElement ( ) . href ) ;
82- assertEquals ( privacyPolicyUrl , this . component . getPpLinkElement ( ) . href ) ;
111+ this . assertTosLinkClicked_ ( ) ;
112+ this . assertPpLinkClicked_ ( ) ;
83113 }
84114} ;
85115
86116
87- /** Asserts a notice to the user about SMS rates for phone authentication
88- * and the link of ToS and Privacy Policy are displayed. */
117+ /**
118+ * Asserts a notice to the user about SMS rates for phone authentication
119+ * and the link of ToS and Privacy Policy are displayed.
120+ * @param {?function()|undefined } tosCallback The ToS callback.
121+ * @param {?function()|undefined } privacyPolicyCallback The Privacy Policy
122+ * callback.
123+ */
89124element . TosPpTestHelper . prototype . assertPhoneFooter = function (
90- tosUrl , privacyPolicyUrl ) {
125+ tosCallback , privacyPolicyCallback ) {
91126 var element = this . component . getTosPpElement ( ) ;
92127 assertTrue ( element . classList . contains ( 'firebaseui-phone-sms-notice' ) ) ;
93- this . assertFooter ( tosUrl , privacyPolicyUrl ) ;
128+ this . assertFooter ( tosCallback , privacyPolicyCallback ) ;
129+ } ;
130+
131+
132+ /**
133+ * Asserts the onClick callback is triggered when ToS link element is clicked.
134+ * @private
135+ */
136+ element . TosPpTestHelper . prototype . assertTosLinkClicked_ = function ( ) {
137+ assertFalse ( this . tosLinkClicked_ ) ;
138+ goog . testing . events . fireClickSequence ( this . component . getTosLinkElement ( ) ) ;
139+ assertTrue ( this . tosLinkClicked_ ) ;
140+ } ;
141+
142+
143+ /**
144+ * Asserts the onClick callback is triggered when Pp link element is clicked.
145+ * @private
146+ */
147+ element . TosPpTestHelper . prototype . assertPpLinkClicked_ = function ( ) {
148+ assertFalse ( this . privacyPolicyLinkClicked_ ) ;
149+ goog . testing . events . fireClickSequence ( this . component . getPpLinkElement ( ) ) ;
150+ assertTrue ( this . privacyPolicyLinkClicked_ ) ;
94151} ;
95152
96153
@@ -103,11 +160,13 @@ element.TosPpTestHelper.prototype.testGetTosPpElement_ = function() {
103160/** @private */
104161element . TosPpTestHelper . prototype . testGetTosLinkElement_ = function ( ) {
105162 assertNotNull ( this . component . getTosLinkElement ( ) ) ;
163+ this . assertTosLinkClicked_ ( ) ;
106164} ;
107165
108166
109167/** @private */
110168element . TosPpTestHelper . prototype . testGetPpLinkElement_ = function ( ) {
111169 assertNotNull ( this . component . getPpLinkElement ( ) ) ;
170+ this . assertPpLinkClicked_ ( ) ;
112171} ;
113172} ) ;
0 commit comments