Merge pull request #1365 from mluto/fix-load-message-tests

Fix load message tests
This commit is contained in:
John McLear 2013-01-15 14:27:54 -08:00
commit 6055fa9cec
2 changed files with 21 additions and 17 deletions

View File

@ -56,13 +56,13 @@ var helper = {};
window.document.cookie = ""; window.document.cookie = "";
} }
helper.newPad = function(){ helper.newPad = function(cb, padName){
//build opts object //build opts object
var opts = {clearCookies: true} var opts = {clearCookies: true}
if(typeof arguments[0] === 'function'){ if(typeof cb === 'function'){
opts.cb = arguments[0] opts.cb = cb
} else { } else {
opts = _.defaults(arguments[0], opts); opts = _.defaults(cb, opts);
} }
//clear cookies //clear cookies
@ -70,7 +70,8 @@ var helper = {};
helper.clearCookies(); helper.clearCookies();
} }
var padName = "FRONTEND_TEST_" + helper.randomString(20); if(!padName)
padName = "FRONTEND_TEST_" + helper.randomString(20);
$iframe = $("<iframe src='/p/" + padName + "'></iframe>"); $iframe = $("<iframe src='/p/" + padName + "'></iframe>");
//clean up inner iframe references //clean up inner iframe references

View File

@ -1,6 +1,9 @@
describe("chat-load-messages", function(){ describe("chat-load-messages", function(){
var padName;
it("creates a pad", function(done) { it("creates a pad", function(done) {
helper.newPad(done); padName = helper.newPad(done);
this.timeout(60000);
}); });
it("adds a lot of messages", function(done) { it("adds a lot of messages", function(done) {
@ -11,6 +14,8 @@ describe("chat-load-messages", function(){
var chatInput = chrome$("#chatinput"); var chatInput = chrome$("#chatinput");
var chatText = chrome$("#chattext"); var chatText = chrome$("#chattext");
this.timeout(60000);
var messages = 140; var messages = 140;
for(var i=1; i <= messages; i++) { for(var i=1; i <= messages; i++) {
var num = ''+i; var num = ''+i;
@ -23,22 +28,17 @@ describe("chat-load-messages", function(){
} }
helper.waitFor(function(){ helper.waitFor(function(){
return chatText.children("p").length == messages; return chatText.children("p").length == messages;
}).always(function(){ }, 60000).always(function(){
expect(chatText.children("p").length).to.be(messages); expect(chatText.children("p").length).to.be(messages);
$('#iframe-container iframe')[0].contentWindow.location.reload(); helper.newPad(done, padName);
done();
}); });
}); });
it("checks initial message count", function(done) { it("checks initial message count", function(done) {
var chatText; var chatText;
var expectedCount = 101; var expectedCount = 101;
var chrome$ = helper.padChrome$;
helper.waitFor(function(){ helper.waitFor(function(){
// wait for the frame to load
var chrome$ = $('#iframe-container iframe')[0].contentWindow.$;
if(!chrome$) // page not fully loaded
return false;
var chatButton = chrome$("#chaticon"); var chatButton = chrome$("#chaticon");
chatButton.click(); chatButton.click();
chatText = chrome$("#chattext"); chatText = chrome$("#chattext");
@ -51,7 +51,7 @@ describe("chat-load-messages", function(){
it("loads more messages", function(done) { it("loads more messages", function(done) {
var expectedCount = 122; var expectedCount = 122;
var chrome$ = $('#iframe-container iframe')[0].contentWindow.$; var chrome$ = helper.padChrome$;
var chatButton = chrome$("#chaticon"); var chatButton = chrome$("#chaticon");
chatButton.click(); chatButton.click();
var chatText = chrome$("#chattext"); var chatText = chrome$("#chattext");
@ -68,17 +68,20 @@ describe("chat-load-messages", function(){
it("checks for button vanishing", function(done) { it("checks for button vanishing", function(done) {
var expectedDisplay = 'none'; var expectedDisplay = 'none';
var chrome$ = $('#iframe-container iframe')[0].contentWindow.$; var chrome$ = helper.padChrome$;
var chatButton = chrome$("#chaticon"); var chatButton = chrome$("#chaticon");
chatButton.click(); chatButton.click();
var chatText = chrome$("#chattext"); var chatText = chrome$("#chattext");
var loadMsgBtn = chrome$("#chatloadmessagesbutton"); var loadMsgBtn = chrome$("#chatloadmessagesbutton");
var loadMsgBall = chrome$("#chatloadmessagesball");
loadMsgBtn.click(); loadMsgBtn.click();
helper.waitFor(function(){ helper.waitFor(function(){
return loadMsgBtn.css('display') == expectedDisplay; return loadMsgBtn.css('display') == expectedDisplay &&
loadMsgBall.css('display') == expectedDisplay;
}).always(function(){ }).always(function(){
expect(loadMsgBtn.css('display')).to.be(expectedDisplay); expect(loadMsgBtn.css('display')).to.be(expectedDisplay);
expect(loadMsgBall.css('display')).to.be(expectedDisplay);
done(); done();
}); });
}); });