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.hide_muc_server = false;
this.i18n = locales.en;
this.no_trimming = false; // Set to true for phantomjs tests (where browser apparently has no width)
this.prebind = false;
this.show_controlbox_by_default = false;
this.show_only_online_users = false;
@ -195,6 +196,7 @@
'fullname',
'hide_muc_server',
'i18n',
'no_trimming',
'jid',
'prebind',
'rid',
@ -2556,6 +2558,9 @@
* Check whether there is enough space in the page to show
* another chat box. Otherwise, close the oldest chat box.
*/
if (converse.no_trimming) {
return;
}
var toggle_width = 0,
trimmed_chats_width,
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
// --------------
// This is the end of the initialize method.
this.chatboxes = new this.ChatBoxes();
this.chatboxviews = new this.ChatBoxViews({model: this.chatboxes});
this.controlboxtoggle = new this.ControlBoxToggle();
this.otr = new this.OTR();
this._initialize();
if ((this.prebind) && (!this.connection)) {
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');

View File

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

View File

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

View File

@ -8,13 +8,10 @@
);
} (this, function (mock, utils) {
describe("The Control Box", $.proxy(function (mock, utils) {
beforeEach(function () {
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {});
});
it("can be opened by clicking a DOM element with class 'toggle-online-users'", $.proxy(function () {
@ -501,8 +498,6 @@
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {});
}, converse));
it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
@ -524,8 +519,6 @@
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {});
}, converse));
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" />
<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" media="screen" href="stylesheets/stylesheet.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/bootstrap/3.0.3/css/bootstrap.min.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 data-main="tests/main" src="components/requirejs/require.js"></script>
</head>
@ -19,6 +21,5 @@
<h2 id="project_tagline">Tests</h2>
</header>
</div>
<div id="conversejs"></div>
</body>
</html>

View File

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

View File

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