Fix tests.

This commit is contained in:
JC Brand 2014-05-27 19:18:02 +02:00
parent ad51e1c0f7
commit 38e0668372
7 changed files with 27 additions and 26 deletions

View File

@ -158,6 +158,7 @@
this.forward_messages = false; this.forward_messages = false;
this.hide_muc_server = false; this.hide_muc_server = false;
this.i18n = locales.en; this.i18n = locales.en;
this.no_trimming = false; // Set to true for phantomjs tests (where browser apparently has no width)
this.prebind = false; this.prebind = false;
this.show_controlbox_by_default = false; this.show_controlbox_by_default = false;
this.show_only_online_users = false; this.show_only_online_users = false;
@ -195,6 +196,7 @@
'fullname', 'fullname',
'hide_muc_server', 'hide_muc_server',
'i18n', 'i18n',
'no_trimming',
'jid', 'jid',
'prebind', 'prebind',
'rid', 'rid',
@ -2556,6 +2558,9 @@
* Check whether there is enough space in the page to show * Check whether there is enough space in the page to show
* another chat box. Otherwise, close the oldest chat box. * another chat box. Otherwise, close the oldest chat box.
*/ */
if (converse.no_trimming) {
return;
}
var toggle_width = 0, var toggle_width = 0,
trimmed_chats_width, trimmed_chats_width,
boxes_width = view.$el.outerWidth(true), boxes_width = view.$el.outerWidth(true),
@ -3630,14 +3635,17 @@
} }
}); });
this._initialize = function () {
this.chatboxes = new this.ChatBoxes();
this.chatboxviews = new this.ChatBoxViews({model: this.chatboxes});
this.controlboxtoggle = new this.ControlBoxToggle();
this.otr = new this.OTR();
};
// Initialization // Initialization
// -------------- // --------------
// This is the end of the initialize method. // This is the end of the initialize method.
this.chatboxes = new this.ChatBoxes(); this._initialize();
this.chatboxviews = new this.ChatBoxViews({model: this.chatboxes});
this.controlboxtoggle = new this.ControlBoxToggle();
this.otr = new this.OTR();
if ((this.prebind) && (!this.connection)) { if ((this.prebind) && (!this.connection)) {
if ((!this.jid) || (!this.sid) || (!this.rid) || (!this.bosh_service_url)) { if ((!this.jid) || (!this.sid) || (!this.rid) || (!this.bosh_service_url)) {
this.log('If you set prebind=true, you MUST supply JID, RID and SID values'); this.log('If you set prebind=true, you MUST supply JID, RID and SID values');

View File

@ -34,7 +34,7 @@
// openControlBox was called earlier, so the controlbox is // openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created. // visible, but no other chat boxes have been created.
expect(this.chatboxes.length).toEqual(1); expect(this.chatboxes.length).toEqual(1);
spyOn(this.chatboxviews, 'trimOpenChats'); spyOn(this.chatboxviews, 'trimChats');
var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat'); var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat');
for (i=0; i<online_contacts.length; i++) { for (i=0; i<online_contacts.length; i++) {
@ -46,7 +46,7 @@
$el.click(); $el.click();
expect(view.openChat).toHaveBeenCalled(); expect(view.openChat).toHaveBeenCalled();
expect(this.chatboxes.length).toEqual(i+2); expect(this.chatboxes.length).toEqual(i+2);
expect(this.chatboxviews.trimOpenChats).toHaveBeenCalled(); expect(this.chatboxviews.trimChats).toHaveBeenCalled();
} }
}, converse)); }, converse));
@ -72,14 +72,14 @@
it("can be saved to, and retrieved from, localStorage", $.proxy(function () { it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(this.chatboxviews, 'trimOpenChats'); spyOn(this.chatboxviews, 'trimChats');
runs(function () { runs(function () {
utils.openControlBox(); utils.openControlBox();
}); });
waits(250); waits(250);
runs(function () { runs(function () {
utils.openChatBoxes(6); utils.openChatBoxes(6);
expect(this.chatboxviews.trimOpenChats).toHaveBeenCalled(); expect(this.chatboxviews.trimChats).toHaveBeenCalled();
// We instantiate a new ChatBoxes collection, which by default // We instantiate a new ChatBoxes collection, which by default
// will be empty. // will be empty.
var newchatboxes = new this.ChatBoxes(); var newchatboxes = new this.ChatBoxes();
@ -166,7 +166,7 @@
it("will be removed from localStorage when closed", $.proxy(function () { it("will be removed from localStorage when closed", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(converse.chatboxviews, 'trimOpenChats'); spyOn(converse.chatboxviews, 'trimChats');
this.chatboxes.localStorage._clear(); this.chatboxes.localStorage._clear();
runs(function () { runs(function () {
utils.closeControlBox(); utils.closeControlBox();
@ -176,7 +176,7 @@
expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
expect(converse.chatboxes.length).toEqual(0); expect(converse.chatboxes.length).toEqual(0);
utils.openChatBoxes(6); utils.openChatBoxes(6);
expect(converse.chatboxviews.trimOpenChats).toHaveBeenCalled(); expect(converse.chatboxviews.trimChats).toHaveBeenCalled();
expect(converse.chatboxes.length).toEqual(6); expect(converse.chatboxes.length).toEqual(6);
expect(converse.emit).toHaveBeenCalledWith('onChatBoxOpened', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxOpened', jasmine.any(Object));
utils.closeAllChatBoxes(); utils.closeAllChatBoxes();

View File

@ -115,14 +115,14 @@
it("can be saved to, and retrieved from, localStorage", $.proxy(function () { it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
// We instantiate a new ChatBoxes collection, which by default // We instantiate a new ChatBoxes collection, which by default
// will be empty. // will be empty.
spyOn(this.chatboxviews, 'trimOpenChats'); spyOn(this.chatboxviews, 'trimChats');
utils.openControlBox(); utils.openControlBox();
var newchatboxes = new this.ChatBoxes(); var newchatboxes = new this.ChatBoxes();
expect(newchatboxes.length).toEqual(0); expect(newchatboxes.length).toEqual(0);
// The chatboxes will then be fetched from localStorage inside the // The chatboxes will then be fetched from localStorage inside the
// onConnected method // onConnected method
newchatboxes.onConnected(); newchatboxes.onConnected();
expect(this.chatboxviews.trimOpenChats).toHaveBeenCalled(); expect(this.chatboxviews.trimChats).toHaveBeenCalled();
expect(newchatboxes.length).toEqual(2); // XXX: Includes controlbox, is this a bug? expect(newchatboxes.length).toEqual(2); // XXX: Includes controlbox, is this a bug?
// Check that the chatrooms retrieved from localStorage // Check that the chatrooms retrieved from localStorage
// have the same attributes values as the original ones. // have the same attributes values as the original ones.

View File

@ -8,13 +8,10 @@
); );
} (this, function (mock, utils) { } (this, function (mock, utils) {
describe("The Control Box", $.proxy(function (mock, utils) { describe("The Control Box", $.proxy(function (mock, utils) {
beforeEach(function () { beforeEach(function () {
runs(function () { runs(function () {
utils.openControlBox(); utils.openControlBox();
}); });
waits(250);
runs(function () {});
}); });
it("can be opened by clicking a DOM element with class 'toggle-online-users'", $.proxy(function () { it("can be opened by clicking a DOM element with class 'toggle-online-users'", $.proxy(function () {
@ -501,8 +498,6 @@
runs(function () { runs(function () {
utils.openControlBox(); utils.openControlBox();
}); });
waits(250);
runs(function () {});
}, converse)); }, converse));
it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () { it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
@ -524,8 +519,6 @@
runs(function () { runs(function () {
utils.openControlBox(); utils.openControlBox();
}); });
waits(250);
runs(function () {});
}, converse)); }, converse));
it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () { it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {

View File

@ -6,8 +6,10 @@
<meta name="description" content="Converse.js: A chat client for your website" /> <meta name="description" content="Converse.js: A chat client for your website" />
<link rel="shortcut icon" type="image/png" href="components/jasmine/images/jasmine_favicon.png"> <link rel="shortcut icon" type="image/png" href="components/jasmine/images/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="components/jasmine/src/html/jasmine.css"> <link rel="stylesheet" type="text/css" href="components/jasmine/src/html/jasmine.css">
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css"> <link type="text/css" rel="stylesheet" media="screen" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="converse.css"> <link type="text/css" rel="stylesheet" media="screen" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" />
<link type="text/css" rel="stylesheet" media="screen" href="css/theme.css" />
<link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" />
<script src="main.js"></script> <script src="main.js"></script>
<script data-main="tests/main" src="components/requirejs/require.js"></script> <script data-main="tests/main" src="components/requirejs/require.js"></script>
</head> </head>
@ -19,6 +21,5 @@
<h2 id="project_tagline">Tests</h2> <h2 id="project_tagline">Tests</h2>
</header> </header>
</div> </div>
<div id="conversejs"></div>
</body> </body>
</html> </html>

View File

@ -45,7 +45,7 @@ require([
auto_subscribe: false, auto_subscribe: false,
animate: false, animate: false,
connection: mock.mock_connection, connection: mock.mock_connection,
testing: true no_trimming: true
}, function (converse) { }, function (converse) {
window.converse = converse; window.converse = converse;
window.crypto = { window.crypto = {

View File

@ -31,8 +31,7 @@
}; };
utils.initConverse = function () { utils.initConverse = function () {
converse.chatboxes = new converse.ChatBoxes(); converse._initialize();
converse.chatboxviews = new converse.ChatBoxViews({model: converse.chatboxes});
converse.onConnected(); converse.onConnected();
}; };