@@ -21,7 +21,11 @@ goog.provide('firebaseui.auth.ui.page.PageTestHelper');
2121goog . setTestOnly ( 'firebaseui.auth.ui.page.PageTestHelper' ) ;
2222
2323goog . require ( 'firebaseui.auth.EventDispatcher' ) ;
24+ goog . require ( 'firebaseui.auth.ui.element.ElementTestHelper' ) ;
2425goog . require ( 'firebaseui.auth.ui.page.Base' ) ;
26+ goog . require ( 'goog.Promise' ) ;
27+ goog . require ( 'goog.dom' ) ;
28+ goog . require ( 'goog.dom.classlist' ) ;
2529goog . require ( 'goog.events' ) ;
2630
2731
@@ -32,13 +36,17 @@ var page = firebaseui.auth.ui.page;
3236/**
3337 * Initializes page test helper.
3438 * @constructor
39+ * @extends {firebaseui.auth.ui.element.ElementTestHelper }
3540 */
3641page . PageTestHelper = function ( ) {
42+ page . PageTestHelper . base ( this , 'constructor' , 'Page' ) ;
3743 this . entered_ = false ;
3844 this . exited_ = false ;
3945 this . enteredEvent_ = null ;
4046 this . exitedEvent_ = null ;
4147} ;
48+ goog . inherits (
49+ page . PageTestHelper , firebaseui . auth . ui . element . ElementTestHelper ) ;
4250
4351
4452/**
@@ -150,4 +158,54 @@ page.PageTestHelper.prototype.runTests = function(component, container) {
150158 this . assertExited ( component . getPageId ( ) ) ;
151159 this . resetState ( ) ;
152160} ;
161+
162+
163+ /**
164+ * @param {!goog.testing.MockClock } clock The mock clock to use for testing.
165+ * @return {!page.PageTestHelper } THe current page test helper instance.
166+ */
167+ page . PageTestHelper . prototype . setClock = function ( clock ) {
168+ this . mockClock = clock ;
169+ return this ;
170+ } ;
171+
172+
173+ /**
174+ * Tests executePromiseRequest and the busy indicators that gets displayed.
175+ * @return {!goog.Promise } Promise that resolves when the test completes.
176+ * @private
177+ */
178+ page . PageTestHelper . prototype . testExecutePromiseRequest_ = function ( ) {
179+ var root = this . component . getContainer ( ) ;
180+ var resolveBusyIndicator ;
181+ var pending = new goog . Promise ( function ( resolve , reject ) {
182+ resolveBusyIndicator = resolve ;
183+ } ) ;
184+ var p = this . component . executePromiseRequest (
185+ function ( ) {
186+ return pending ;
187+ } ,
188+ [ ] ,
189+ function ( ) { } ,
190+ function ( error ) { } ) ;
191+ this . mockClock . tick ( 500 ) ;
192+ var elements =
193+ goog . dom . getElementsByClass ( 'firebaseui-busy-indicator' , root ) ;
194+ assertEquals ( 1 , elements . length ) ;
195+ var busyIndicator = elements [ 0 ] ;
196+ if ( goog . dom . classlist . contains ( root . firstChild , 'firebaseui-use-spinner' ) ) {
197+ // Confirm mdl-spinner used instead of mdl-progress.
198+ assertTrue ( goog . dom . classlist . contains ( busyIndicator , 'mdl-spinner' ) ) ;
199+ } else {
200+ // Confirm mdl-progress bar used instead of mdl-spinner.
201+ assertTrue ( goog . dom . classlist . contains ( busyIndicator , 'mdl-progress' ) ) ;
202+ }
203+ // Resolve pending task.
204+ resolveBusyIndicator ( ) ;
205+ return p . then ( function ( ) {
206+ // Busy indicator should be removed when promise resolves.
207+ assertEquals ( 0 , goog . dom . getElementsByClass (
208+ 'firebaseui-busy-indicator' , root ) . length ) ;
209+ } ) ;
210+ } ;
153211} ) ;
0 commit comments