@@ -3,10 +3,10 @@ var Firebase = require('firebase');
3
3
4
4
describe ( 'Chat App' , function ( ) {
5
5
// Reference to the Firebase which stores the data for this demo
6
- var firebaseRef = new Firebase ( 'https://angularFireTests .firebaseio-demo.com/chat' ) ;
6
+ var firebaseRef = new Firebase ( 'https://angularfire .firebaseio-demo.com/chat' ) ;
7
7
8
- // Boolean used to clear the Firebase on the first test only
9
- var firebaseCleared = false ;
8
+ // Boolean used to load the page on the first test only
9
+ var isPageLoaded = false ;
10
10
11
11
// Reference to the messages repeater
12
12
var messages = element . all ( by . repeater ( 'message in messages' ) ) ;
@@ -21,35 +21,41 @@ describe('Chat App', function () {
21
21
flow . execute ( waitOne ) ;
22
22
}
23
23
24
- beforeEach ( function ( ) {
25
- // Clear the Firebase before the first test and sleep until it's finished
26
- if ( ! firebaseCleared ) {
27
- flow . execute ( function ( ) {
28
- var def = protractor . promise . defer ( ) ;
29
- firebaseRef . remove ( function ( err ) {
30
- if ( err ) {
31
- def . reject ( err ) ;
32
- }
33
- else {
34
- firebaseCleared = true ;
35
- def . fulfill ( ) ;
36
- }
37
- } ) ;
38
- return def . promise ;
39
- } ) ;
40
- }
24
+ function clearFirebaseRef ( ) {
25
+ var deferred = protractor . promise . defer ( ) ;
41
26
42
- // Navigate to the chat app
43
- browser . get ( 'chat/chat.html' ) ;
27
+ firebaseRef . remove ( function ( err ) {
28
+ if ( err ) {
29
+ deferred . reject ( err ) ;
30
+ } else {
31
+ deferred . fulfill ( ) ;
32
+ }
33
+ } ) ;
44
34
45
- // wait for page to load
46
- sleep ( ) ;
47
- } ) ;
35
+ return deferred . promise ;
36
+ }
48
37
49
- it ( 'loads' , function ( ) {
38
+ beforeEach ( function ( done ) {
39
+ if ( ! isPageLoaded ) {
40
+ isPageLoaded = true ;
41
+
42
+ // Navigate to the chat app
43
+ browser . get ( 'chat/chat.html' ) . then ( function ( ) {
44
+ // Get the random push ID where the data is being stored
45
+ return $ ( '#pushId' ) . getText ( ) ;
46
+ } ) . then ( function ( pushId ) {
47
+ // Update the Firebase ref to point to the random push ID
48
+ firebaseRef = firebaseRef . child ( pushId ) ;
49
+
50
+ // Clear the Firebase ref
51
+ return clearFirebaseRef ( ) ;
52
+ } ) . then ( done ) ;
53
+ } else {
54
+ done ( ) ;
55
+ }
50
56
} ) ;
51
57
52
- it ( 'has the correct title ' , function ( ) {
58
+ it ( 'loads ' , function ( ) {
53
59
expect ( browser . getTitle ( ) ) . toEqual ( 'AngularFire Chat e2e Test' ) ;
54
60
} ) ;
55
61
@@ -74,7 +80,7 @@ describe('Chat App', function () {
74
80
flow . execute ( function ( ) {
75
81
var def = protractor . promise . defer ( ) ;
76
82
// Simulate a message being added remotely
77
- firebaseRef . child ( " messages" ) . push ( {
83
+ firebaseRef . child ( ' messages' ) . push ( {
78
84
from : 'Guest 2000' ,
79
85
content : 'Remote message detected'
80
86
} , function ( err ) {
@@ -92,8 +98,8 @@ describe('Chat App', function () {
92
98
flow . execute ( function ( ) {
93
99
var def = protractor . promise . defer ( ) ;
94
100
// Simulate a message being deleted remotely
95
- var onCallback = firebaseRef . child ( " messages" ) . limitToLast ( 1 ) . on ( " child_added" , function ( childSnapshot ) {
96
- firebaseRef . child ( " messages" ) . off ( " child_added" , onCallback ) ;
101
+ var onCallback = firebaseRef . child ( ' messages' ) . limitToLast ( 1 ) . on ( ' child_added' , function ( childSnapshot ) {
102
+ firebaseRef . child ( ' messages' ) . off ( ' child_added' , onCallback ) ;
97
103
childSnapshot . ref ( ) . remove ( function ( err ) {
98
104
if ( err ) { def . reject ( err ) ; }
99
105
else { def . fulfill ( ) ; }
0 commit comments