Commit 11b59b31 authored by JC Brand's avatar JC Brand

Fix tests after all the refactoring...

parent b9cf7950
......@@ -356,7 +356,6 @@ span.spinner.hor_centered {
padding: 4px 8px;
margin-right: 5px;
color: white;
display: none;
}
#connecting-to-chat {
......
......@@ -605,7 +605,7 @@
window.sessionStorage[hex_sha1(jid+'priv_key')] =
cipher.encrypt(CryptoJS.algo.AES, key.packPrivate(), pass).toString();
window.sessionStorage[hex_sha1(jid+'instance_tag')] = instance_tag;
window.sessionStorage[hex_sha1(jid+'pass_check')] =
window.sessionStorage[hex_sha1(jid+'pass_check')] =
cipher.encrypt(CryptoJS.algo.AES, 'match', pass).toString();
}
}
......@@ -866,7 +866,7 @@
this.updateVCard();
this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true});
this.render().show().focus().model.messages.fetch({add: true});
if (this.model.get('status')) {
this.showStatusMessage(this.model.get('status'));
......@@ -897,6 +897,7 @@
)
);
this.renderToolbar().renderAvatar();
converse.emit('onChatBoxOpened', this);
return this;
},
......@@ -1349,7 +1350,7 @@
FINISHED: FINISHED,
UNENCRYPTED: UNENCRYPTED,
UNVERIFIED: UNVERIFIED,
VERIFIED: VERIFIED,
VERIFIED: VERIFIED,
allow_otr: converse.allow_otr && !this.is_chatroom,
label_end_encrypted_conversation: __('End encrypted conversation'),
label_refresh_encrypted_conversation: __('Refresh encrypted conversation'),
......@@ -1391,6 +1392,7 @@
focus: function () {
this.$el.find('.chat-textarea').focus();
converse.emit('onChatBoxFocused', this);
return this;
},
......@@ -1404,14 +1406,13 @@
show: function (callback) {
if (this.$el.is(':visible') && this.$el.css('opacity') == "1") {
converse.emit('onChatBoxFocused', this);
return this.focus();
return this;
}
if (converse.animate) {
this.$el.css({'opacity': 0, 'display': 'inline'}).animate({opacity: '1'}, 200, null, callback);
this.$el.show(callback);
} else {
this.$el.css({'opacity': 1, 'display': 'inline'});
callback();
this.$el.show();
if (typeof callback === 'function') { callback(); }
}
if (converse.connection) {
// Without a connection, we haven't yet initialized
......@@ -1779,6 +1780,7 @@
hide: function (callback) {
this.$el.hide('fast', function () {
converse.emit('onChatBoxClosed', this);
converse.controlboxtoggle.show(function () {
if (typeof callback === "function") {
callback();
......@@ -1872,6 +1874,28 @@
},
is_chatroom: true,
initialize: function () {
this.connect(null);
this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('destroy', function (model, response, options) {
this.hide();
converse.connection.muc.leave(
this.model.get('jid'),
this.model.get('nick'),
$.proxy(this.onLeave, this),
undefined);
},
this);
this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true});
},
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(converse.templates.chatroom(this.model.toJSON()));
return this;
},
sendChatRoomMessage: function (body) {
var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false],
$chat_content;
......@@ -1915,12 +1939,6 @@
}
},
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(converse.templates.chatroom(this.model.toJSON()));
return this;
},
renderChatArea: function () {
if (!this.$el.find('.chat-area').length) {
this.$el.find('.chat-body').empty().append(
......@@ -1951,22 +1969,6 @@
}
},
initialize: function () {
this.connect(null);
this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('destroy', function (model, response, options) {
this.hide();
converse.connection.muc.leave(
this.model.get('jid'),
this.model.get('nick'),
$.proxy(this.onLeave, this),
undefined);
},
this);
this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true});
},
onLeave: function () {
this.model.set('connected', false);
},
......@@ -2935,11 +2937,11 @@
'label_contacts': __('My contacts')
});
if (converse.allow_contact_requests) {
roster_markup =
roster_markup =
converse.templates.requesting_contacts({
'label_contact_requests': __('Contact requests')
}) +
roster_markup +
}) +
roster_markup +
converse.templates.pending_contacts({
'label_pending_contacts': __('Pending contacts')
});
......@@ -3391,11 +3393,15 @@
},
render: function () {
$('#conversejs').append(this.$el.html(
var toggle = this.$el.html(
converse.templates.controlbox_toggle({
'label_toggle': __('Toggle chat')
})
));
);
if (converse.show_controlbox_by_default) {
toggle.hide(); // It's either or
}
$('#conversejs').append(toggle);
return this;
},
......
......@@ -7,8 +7,8 @@
<meta name="description" content="Converse.js: Open Source Browser-Based Instant Messaging" />
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
<link rel="stylesheet" type="text/css" media="screen" href="converse.css">
<!--<script data-main="main" src="components/requirejs/require.js"></script>-->
<script src="builds/converse.min.js"></script>
<script data-main="main" src="components/requirejs/require.js"></script>
<!-- <script src="builds/converse.min.js"></script> -->
<title>Converse.js</title>
</head>
......
This diff is collapsed.
......@@ -10,12 +10,35 @@
return describe("ChatRooms", $.proxy(function (mock, utils) {
describe("A Chat Room", $.proxy(function () {
beforeEach(function () {
utils.closeAllChatBoxes();
utils.createNewChatRoom('lounge', 'dummy');
});
afterEach(function () {
utils.closeAllChatBoxes();
runs(function () {
utils.closeAllChatBoxes();
});
waits(250);
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {
utils.openRoomsPanel();
});
waits(300);
runs(function () {
// Open a new chatroom
var roomspanel = converse.chatboxesview.views.controlbox.roomspanel;
var $input = roomspanel.$el.find('input.new-chatroom-name');
var $nick = roomspanel.$el.find('input.new-chatroom-nick');
var $server = roomspanel.$el.find('input.new-chatroom-server');
$input.val('lounge');
$nick.val('dummy');
$server.val('muc.localhost');
roomspanel.$el.find('form').submit();
});
waits(250);
runs(function () {
utils.closeControlBox();
});
waits(250);
runs(function () {});
});
it("shows users currently present in the room", $.proxy(function () {
......@@ -115,10 +138,15 @@
spyOn(converse, 'emit');
spyOn(converse.connection.muc, 'leave');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
view.$el.find('.close-chatbox-button').click();
expect(view.closeChat).toHaveBeenCalled();
expect(converse.connection.muc.leave).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
runs(function () {
view.$el.find('.close-chatbox-button').click();
});
waits(250);
runs(function () {
expect(view.closeChat).toHaveBeenCalled();
expect(this.connection.muc.leave).toHaveBeenCalled();
expect(this.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
}.bind(converse));
}, converse));
}, converse));
......
......@@ -8,27 +8,32 @@
);
} (this, function (mock, utils) {
describe("The Control Box", $.proxy(function (mock, utils) {
window.localStorage.clear();
it("is not shown by default", $.proxy(function () {
expect(this.rosterview.$el.is(':visible')).toEqual(false);
it("can be opened by clicking a DOM element with class 'toggle-online-users'", $.proxy(function () {
runs(function () {
utils.closeControlBox();
});
waits(250);
runs(function () {
// This spec will only pass if the controlbox is not currently
// open yet.
expect($("div#controlbox").is(':visible')).toBe(false);
spyOn(this.controlboxtoggle, 'onClick').andCallThrough();
spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
spyOn(converse, 'emit');
// Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
this.controlboxtoggle.delegateEvents();
$('.toggle-online-users').click();
}.bind(converse));
waits(250);
runs(function () {
expect(this.controlboxtoggle.onClick).toHaveBeenCalled();
expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
expect(this.emit).toHaveBeenCalledWith('onControlBoxOpened', jasmine.any(Object));
expect($("div#controlbox").is(':visible')).toBe(true);
}.bind(converse));
}, converse));
var open_controlbox = $.proxy(function () {
// This spec will only pass if the controlbox is not currently
// open yet.
expect($("div#controlbox").is(':visible')).toBe(false);
spyOn(this.controlboxtoggle, 'onClick').andCallThrough();
spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
// Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
this.controlboxtoggle.delegateEvents();
$('.toggle-online-users').click();
expect(this.controlboxtoggle.onClick).toHaveBeenCalled();
expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
expect($("div#controlbox").is(':visible')).toBe(true);
}, converse);
it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox);
describe("The Status Widget", $.proxy(function () {
it("shows the user's chat status, which is online by default", $.proxy(function () {
var view = this.xmppstatusview;
......@@ -88,13 +93,20 @@
});
}, converse));
}, converse));
}, converse, utils, mock));
}, converse, mock, utils));
describe("The Contacts Roster", $.proxy(function (utils, mock) {
describe("The Contacts Roster", $.proxy(function (mock, utils) {
describe("Pending Contacts", $.proxy(function () {
beforeEach(function () {
utils.openControlBox();
utils.openContactsPanel();
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {
utils.openContactsPanel();
});
waits(250);
runs(function () {});
});
it("do not have a heading if there aren't any", $.proxy(function () {
......@@ -132,7 +144,7 @@
runs($.proxy(function () {
view.$el.find('.remove-xmpp-contact').click();
}, converse));
waits(500);
waits(250);
runs($.proxy(function () {
expect(window.confirm).toHaveBeenCalled();
expect(this.connection.roster.remove).toHaveBeenCalled();
......@@ -177,8 +189,15 @@
describe("Existing Contacts", $.proxy(function () {
beforeEach($.proxy(function () {
utils.openControlBox();
utils.openContactsPanel();
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {
utils.openContactsPanel();
});
waits(250);
runs(function () {});
}, converse));
it("do not have a heading if there aren't any", $.proxy(function () {
......@@ -437,9 +456,9 @@
}
}, converse));
}, converse));
}, converse, utils, mock));
}, converse, mock, utils));
describe("The 'Add Contact' widget", $.proxy(function (utils, mock) {
describe("The 'Add Contact' widget", $.proxy(function (mock, utils) {
it("opens up an add form when you click on it", $.proxy(function () {
var panel = this.chatboxesview.views.controlbox.contactspanel;
spyOn(panel, 'toggleContactForm').andCallThrough();
......@@ -450,12 +469,19 @@
panel.$el.find('a.toggle-xmpp-contact-form').click();
}, converse));
}, converse, utils, mock));
}, converse, mock, utils));
describe("The Controlbox Tabs", $.proxy(function () {
beforeEach($.proxy(function () {
utils.closeAllChatBoxes();
utils.openControlBox();
runs(function () {
utils.closeAllChatBoxes();
});
waits(250);
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {});
}, converse));
it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
......@@ -468,10 +494,17 @@
expect($panels.children().last().is(':visible')).toBe(false);
}, converse));
describe("The Chatrooms Panel", $.proxy(function () {
describe("chatrooms panel", $.proxy(function () {
beforeEach($.proxy(function () {
utils.closeAllChatBoxes();
utils.openControlBox();
runs(function () {
utils.closeAllChatBoxes();
});
waits(250);
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {});
}, converse));
it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
......
......@@ -42,20 +42,26 @@
};
utils.openControlBox = function () {
var toggle = $(".toggle-online-users");
if (!$("#controlbox").is(':visible')) {
$('.toggle-online-users').click();
if (!toggle.is(':visible')) {
toggle.show(toggle.click);
} else {
toggle.click();
}
}
return this;
};
utils.closeControlBox = function () {
if ($("#controlbox").is(':visible')) {
$('.toggle-online-users').click();
$("#controlbox").find(".close-chatbox-button").click();
}
return this;
};
utils.removeControlBox = function () {
converse.controlboxtoggle.show();
$('#controlbox').remove();
};
......@@ -89,23 +95,6 @@
view.model.messages.reset().localStorage._clear();
};
utils.createNewChatRoom = function (room, nick) {
var controlbox_was_visible = $("#controlbox").is(':visible');
utils.openControlBox();
utils.openRoomsPanel();
var roomspanel = converse.chatboxesview.views.controlbox.roomspanel;
var $input = roomspanel.$el.find('input.new-chatroom-name');
var $nick = roomspanel.$el.find('input.new-chatroom-nick');
var $server = roomspanel.$el.find('input.new-chatroom-server');
$input.val('lounge');
$nick.val('dummy');
$server.val('muc.localhost');
roomspanel.$el.find('form').submit();
if (!controlbox_was_visible) {
utils.closeControlBox();
}
};
utils.createCurrentContacts = function () {
// Create current (as opposed to requesting or pending) contacts
// for the user's roster.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment