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

Commit 81614a1

Browse files
author
jwngr
committed
Got tic-tac-toe page refresh test working
1 parent 77c24eb commit 81614a1

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

tests/protractor/tictactoe/tictactoe.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
var app = angular.module('tictactoe', ['firebase']);
22
app.controller('TicTacToeCtrl', function Chat($scope, $firebaseObject) {
33
// Get a reference to the Firebase
4-
var boardRef = new Firebase('https://angularfire.firebaseio-demo.com/tictactoe').push();
4+
var boardRef = new Firebase('https://angularfire.firebaseio-demo.com/tictactoe');
5+
6+
// If the query string contains a push ID, use that as the child for data storage;
7+
// otherwise, generate a new random push ID
8+
var pushId;
9+
if (window.location && window.location.search) {
10+
pushId = window.location.search.substr(1).split('=')[1];
11+
}
12+
if (pushId) {
13+
boardRef = boardRef.child(pushId);
14+
} else {
15+
boardRef = boardRef.push();
16+
}
517

618
// Put the random push ID into the DOM so that the test suite can grab it
719
document.getElementById('pushId').innerHTML = boardRef.key();

tests/protractor/tictactoe/tictactoe.spec.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,21 @@ describe('TicTacToe App', function () {
9494
expect(cells.get(6).getText()).toBe('X');
9595
});
9696

97-
xit('persists state across refresh', function() {
98-
// Make sure the board has 9 cells
99-
expect(cells.count()).toBe(9);
97+
it('persists state across refresh', function(done) {
98+
browser.get('tictactoe/tictactoe.html?pushId=' + firebaseRef.key()).then(function() {
99+
// Wait for AngularFire to sync the initial state
100+
sleep();
100101

101-
// Make sure the content of each clicked cell is correct
102-
expect(cells.get(0).getText()).toBe('X');
103-
expect(cells.get(2).getText()).toBe('O');
104-
expect(cells.get(6).getText()).toBe('X');
102+
// Make sure the board has 9 cells
103+
expect(cells.count()).toBe(9);
104+
105+
// Make sure the content of each clicked cell is correct
106+
expect(cells.get(0).getText()).toBe('X');
107+
expect(cells.get(2).getText()).toBe('O');
108+
expect(cells.get(6).getText()).toBe('X');
109+
110+
done();
111+
});
105112
});
106113

107114
it('stops updating Firebase once the AngularFire bindings are destroyed', function () {
@@ -117,7 +124,7 @@ describe('TicTacToe App', function () {
117124

118125
sleep();
119126

120-
expect(cells.get(4).getText()).toBe('O');
127+
expect(cells.get(4).getText()).toBe('X');
121128

122129
sleep();
123130

0 commit comments

Comments
 (0)