Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit b2d2f6f

Browse files
author
Jacob Wenger
committed
Merge pull request #466 from firebase/kato-protractor
Fixing e2e tests and add SDK 2.0.x compatilibility
2 parents f8ca2ec + 5f0ad18 commit b2d2f6f

File tree

8 files changed

+218
-139
lines changed

8 files changed

+218
-139
lines changed

src/FirebaseArray.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
this._destroyFn = destroyFn;
6666

6767
// indexCache is a weak hashmap (a lazy list) of keys to array indices,
68-
// items are not guaranteed to stay up to date in this list (since the list
69-
// can be manually edited without calling the $ methods) and it should
68+
// items are not guaranteed to stay up to date in this list (since the data
69+
// array can be manually edited without calling the $ methods) and it should
7070
// always be used with skepticism regarding whether it is accurate
7171
// (see $indexFor() below for proper usage)
7272
this._indexCache = {};

tests/local_protractor.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports.config = {
1010
// Capabilities to be passed to the webdriver instance
1111
// For a full list of available capabilities, see https://code.google.com/p/selenium/wiki/DesiredCapabilities
1212
capabilities: {
13-
'browserName': 'chrome',
13+
'browserName': 'chrome'
1414
},
1515

1616
// Calls to protractor.get() with relative paths will be prepended with the baseUrl

tests/protractor/chat/chat.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var app = angular.module('chat', ['firebase']);
22
app.controller('ChatCtrl', function Chat($scope, $firebase) {
33
// Get a reference to the Firebase
44
var chatFirebaseRef = new Firebase('https://angularFireTests.firebaseio-demo.com/chat');
5-
var messagesFirebaseRef = chatFirebaseRef.child("messages").limit(2);
5+
var messagesFirebaseRef = chatFirebaseRef.child("messages").limitToLast(2);
66
var numMessagesFirebaseRef = chatFirebaseRef.child("numMessages");
77

88
// Get AngularFire sync objects
@@ -75,6 +75,11 @@ app.controller('ChatCtrl', function Chat($scope, $firebase) {
7575
$scope.messages.$destroy();
7676
};
7777

78+
$scope.$on('destroy', function() {
79+
$scope.chat.$destroy();
80+
$scope.messages.$destroy();
81+
});
82+
7883
/* Logs a message and throws an error if the inputted expression is false */
7984
function verify(expression, message) {
8085
if (!expression) {

tests/protractor/chat/chat.spec.js

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,39 @@ describe('Chat App', function () {
1717
// Reference to messages count
1818
var messagesCount = element(by.id('messagesCount'));
1919

20-
beforeEach(function (done) {
21-
// Navigate to the chat app
22-
browser.get('chat/chat.html');
20+
var flow = protractor.promise.controlFlow();
21+
22+
function waitOne() {
23+
return protractor.promise.delayed(500);
24+
}
2325

26+
function sleep() {
27+
flow.execute(waitOne);
28+
}
29+
30+
beforeEach(function () {
2431
// Clear the Firebase before the first test and sleep until it's finished
2532
if (!firebaseCleared) {
26-
firebaseRef.remove(function() {
27-
firebaseCleared = true;
28-
done();
33+
flow.execute(function() {
34+
var def = protractor.promise.defer();
35+
firebaseRef.remove(function(err) {
36+
if( err ) {
37+
def.reject(err);
38+
}
39+
else {
40+
firebaseCleared = true;
41+
def.fulfill();
42+
}
43+
});
44+
return def.promise;
2945
});
3046
}
31-
else {
32-
ptor.sleep(500);
33-
done();
34-
}
47+
48+
// Navigate to the chat app
49+
browser.get('chat/chat.html');
50+
51+
// wait for page to load
52+
sleep();
3553
});
3654

3755
it('loads', function () {
@@ -53,72 +71,80 @@ describe('Chat App', function () {
5371
newMessageInput.sendKeys('Oh, hi. How are you?\n');
5472
newMessageInput.sendKeys('Pretty fantastic!\n');
5573

74+
sleep();
75+
5676
// We should only have two messages in the repeater since we did a limit query
5777
expect(messages.count()).toBe(2);
5878

5979
// Messages count should include all messages, not just the ones displayed
6080
expect(messagesCount.getText()).toEqual('3');
6181
});
6282

63-
it('updates upon new remote messages', function (done) {
64-
// Simulate a message being added remotely
65-
firebaseRef.child("messages").push({
66-
from: 'Guest 2000',
67-
content: 'Remote message detected'
68-
}, function() {
69-
// Update the message count as well
70-
firebaseRef.child("numMessages").transaction(function(currentCount) {
71-
if (!currentCount) {
72-
return 1;
73-
} else {
74-
return currentCount + 1;
75-
}
76-
}, function () {
77-
// We should only have two messages in the repeater since we did a limit query
78-
expect(messages.count()).toBe(2);
79-
80-
// Messages count should include all messages, not just the ones displayed
81-
expect(messagesCount.getText()).toEqual('4');
82-
83-
// We need to sleep long enough for the promises above to resolve
84-
ptor.sleep(500).then(function() {
85-
done();
86-
});
87-
});
88-
});
89-
});
90-
91-
it('updates upon removed remote messages', function (done) {
92-
// Simulate a message being deleted remotely
93-
var onCallback = firebaseRef.child("messages").limit(1).on("child_added", function(childSnapshot) {
94-
firebaseRef.child("messages").off("child_added", onCallback);
95-
childSnapshot.ref().remove(function() {
83+
it('updates upon new remote messages', function () {
84+
flow.execute(function() {
85+
var def = protractor.promise.defer();
86+
// Simulate a message being added remotely
87+
firebaseRef.child("messages").push({
88+
from: 'Guest 2000',
89+
content: 'Remote message detected'
90+
}, function() {
91+
// Update the message count as well
9692
firebaseRef.child("numMessages").transaction(function(currentCount) {
9793
if (!currentCount) {
9894
return 1;
9995
} else {
100-
return currentCount - 1;
96+
return currentCount + 1;
10197
}
102-
}, function() {
103-
// We should only have two messages in the repeater since we did a limit query
104-
expect(messages.count()).toBe(2);
98+
}, function (e, c, s) {
99+
if( e ) { def.reject(e); }
100+
else { def.fulfill(); }
101+
});
102+
});
103+
return def.promise;
104+
});
105105

106-
// Messages count should include all messages, not just the ones displayed
107-
expect(messagesCount.getText()).toEqual('3');
106+
// We should only have two messages in the repeater since we did a limit query
107+
expect(messages.count()).toBe(2);
108+
109+
// Messages count should include all messages, not just the ones displayed
110+
expect(messagesCount.getText()).toEqual('4');
111+
});
108112

109-
// We need to sleep long enough for the promises above to resolve
110-
ptor.sleep(500).then(function() {
111-
done();
113+
it('updates upon removed remote messages', function () {
114+
flow.execute(function() {
115+
var def = protractor.promise.defer();
116+
// Simulate a message being deleted remotely
117+
var onCallback = firebaseRef.child("messages").limitToLast(1).on("child_added", function(childSnapshot) {
118+
firebaseRef.child("messages").off("child_added", onCallback);
119+
childSnapshot.ref().remove(function() {
120+
firebaseRef.child("numMessages").transaction(function(currentCount) {
121+
if (!currentCount) {
122+
return 1;
123+
} else {
124+
return currentCount - 1;
125+
}
126+
}, function(err) {
127+
if( err ) { def.reject(err); }
128+
else { def.fulfill(); }
112129
});
113130
});
114131
});
132+
return def.promise;
115133
});
134+
135+
// We should only have two messages in the repeater since we did a limit query
136+
expect(messages.count()).toBe(2);
137+
138+
// Messages count should include all messages, not just the ones displayed
139+
expect(messagesCount.getText()).toEqual('3');
116140
});
117141

118142
it('stops updating once the AngularFire bindings are destroyed', function () {
119143
// Destroy the AngularFire bindings
120144
$('#destroyButton').click();
121145

146+
sleep();
147+
122148
expect(messages.count()).toBe(0);
123149
expect(messagesCount.getText()).toEqual('0');
124150
});

tests/protractor/priority/priority.spec.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ describe('Priority App', function () {
1111
// Boolean used to clear the Firebase on the first test only
1212
var firebaseCleared = false;
1313

14-
beforeEach(function () {
15-
var flow = protractor.promise.controlFlow();
14+
var flow = protractor.promise.controlFlow();
15+
16+
function waitOne() {
17+
return protractor.promise.delayed(500);
18+
}
19+
20+
function sleep() {
21+
return flow.execute(waitOne);
22+
}
1623

24+
beforeEach(function () {
1725
if( !firebaseCleared ) {
1826
firebaseCleared = true;
1927
flow.execute(purge);
@@ -37,7 +45,9 @@ describe('Priority App', function () {
3745
function waitForData() {
3846
var def = protractor.promise.defer();
3947
firebaseRef.once('value', function() {
40-
def.fulfill(true);
48+
waitOne().then(function() {
49+
def.fulfill(true);
50+
});
4151
});
4252
return def.promise;
4353
}
@@ -66,6 +76,8 @@ describe('Priority App', function () {
6676
newMessageInput.sendKeys('Oh, hi. How are you?\n');
6777
newMessageInput.sendKeys('Pretty fantastic!\n');
6878

79+
sleep();
80+
6981
// Make sure the page has three messages
7082
expect(messages.count()).toBe(3);
7183

@@ -81,11 +93,9 @@ describe('Priority App', function () {
8193
});
8294

8395
it('responds to external priority updates', function () {
84-
var movesDone = waitForMoveEvents();
85-
var flow = protractor.promise.controlFlow();
8696
flow.execute(moveRecords);
97+
flow.execute(waitOne);
8798

88-
expect(movesDone).toBe(true);
8999
expect(messages.count()).toBe(3);
90100
expect($('.message:nth-of-type(1) .priority').getText()).toEqual('0');
91101
expect($('.message:nth-of-type(2) .priority').getText()).toEqual('1');
@@ -101,25 +111,9 @@ describe('Priority App', function () {
101111
.then(setPriority.bind(null, 2, 0));
102112
}
103113

104-
function waitForMoveEvents() {
105-
var def = protractor.promise.defer();
106-
var count = 0;
107-
firebaseRef.on('child_moved', updateCount, def.reject);
108-
109-
function updateCount() {
110-
if( ++count === 2 ) {
111-
setTimeout(function() {
112-
def.fulfill(true);
113-
}, 10);
114-
firebaseRef.off('child_moved', updateCount);
115-
}
116-
}
117-
return def.promise;
118-
}
119-
120114
function setPriority(start, pri) {
121115
var def = protractor.promise.defer();
122-
firebaseRef.startAt(start).limit(1).once('child_added', function(snap) {
116+
firebaseRef.startAt(start).limitToFirst(1).once('child_added', function(snap) {
123117
var data = snap.val();
124118
//todo https://github.com/firebase/angularFire/issues/333
125119
//todo makeItChange just forces Angular to update the dom since it won't change

tests/protractor/tictactoe/tictactoe.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ app.controller('TicTacToeCtrl', function Chat($scope, $firebase) {
1818
// Initialize $scope variables
1919
$scope.whoseTurn = 'X';
2020

21-
2221
/* Resets the tictactoe Firebase reference */
2322
$scope.resetRef = function () {
2423
["x0", "x1", "x2"].forEach(function (xCoord) {

0 commit comments

Comments
 (0)