forked from FirebaseExtended/angularfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for angularFireCollection based chat
- Loading branch information
Showing
2 changed files
with
106 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,102 @@ | ||
|
||
var system = require('system'); | ||
var system = require("system"); | ||
|
||
casper.test.comment('Testing Chat example with angularFireCollection'); | ||
casper.test.comment("Testing Chat example with angularFireCollection"); | ||
|
||
casper.start('tests/test_chat.html', function() { | ||
this.test.assertTitle('AngularFire Chat Demo'); | ||
casper.start("tests/test_chat.html", function() { | ||
// Sanity test for the environment. | ||
this.test.assertTitle("AngularFire Chat Demo"); | ||
this.test.assertEval(function() { | ||
return Firebase ? true : false; | ||
}, "Firebase exists"); | ||
this.test.assertEval(function() { | ||
return AngularFire ? true : false; | ||
}, "AngularFire exists"); | ||
this.test.assertEval(function() { | ||
return testModule ? true : false; | ||
}, "Test module exists"); | ||
return _scope ? true : false; | ||
}, "Angular scope exists"); | ||
}); | ||
|
||
casper.thenEvaluate(function() { | ||
// Clean up Firebase to start fresh test. | ||
var fbRef = new Firebase(_url); | ||
fbRef.set(null, function(err) { | ||
window.__flag = true; | ||
}); | ||
}); | ||
|
||
casper.waitFor(function() { | ||
return this.getGlobal("__flag") === true; | ||
}); | ||
|
||
casper.then(function(params) { | ||
casper.then(function() { | ||
var _testName = "TestGuest"; | ||
var _testMessage = "This is a test message"; | ||
|
||
this.test.assertEval(function(params) { | ||
testModule.addMessage(params[0], params[1]); | ||
return true; | ||
_scope.username = params[0]; | ||
_scope.message = params[1]; | ||
_scope.addMessage(); | ||
return _scope.message == ""; | ||
}, "Adding a new message", [_testName, _testMessage]); | ||
|
||
this.waitForSelector(".messageBlock", function() { | ||
this.test.assertEval(function(params) { | ||
return testIfInDOM( | ||
params[0], params[1], document.querySelector(".messageBlock") | ||
); | ||
}, "Testing if message is in the DOM", [_testName, _testMessage]); | ||
}); | ||
}); | ||
|
||
casper.then(function() { | ||
var _testName = "GuestTest"; | ||
var _testMessage = "This is another test message"; | ||
|
||
this.evaluate(function(params) { | ||
window.__flag = false; | ||
var ref = new Firebase(_url); | ||
ref.push({from: params[0], content: params[1]}, function(err) { | ||
window.__flag = true; | ||
}); | ||
}, [_testName, _testMessage]); | ||
|
||
this.waitFor(function() { | ||
return this.getGlobal("__flag") === true; | ||
}, function() { | ||
this.test.assertEval(function(params) { | ||
var msgs = document.querySelectorAll(".messageBlock"); | ||
if (msgs.length != 2) { | ||
return false; | ||
} | ||
return testIfInDOM(params[0], params[1], msgs[1]); | ||
}, "Testing if remote message is in the DOM", [_testName, _testMessage]); | ||
}); | ||
}); | ||
|
||
casper.then(function() { | ||
this.test.assertEval(function() { | ||
_scope.message = "Limit Test"; | ||
_scope.addMessage(); | ||
|
||
var ref = new Firebase(_url); | ||
ref.once("value", function(snapshot) { | ||
window.__flag = snapshot.val(); | ||
}); | ||
|
||
return _scope.message == ""; | ||
}, "Adding limit message"); | ||
|
||
this.waitFor(function() { | ||
return this.getGlobal("__flag") != true; | ||
}, function() { | ||
this.test.assertEval(function() { | ||
var msgs = document.querySelectorAll(".messageBlock"); | ||
return msgs.length === 2; | ||
}, "Testing if limits and queries work"); | ||
}); | ||
}); | ||
|
||
casper.run(function() { | ||
this.test.done(4); | ||
this.test.done(9); | ||
}); |