|
@@ -1,11 +1,11 @@
|
|
|
(function (root, factory) {
|
|
|
define([
|
|
|
"converse"
|
|
|
- ], function (xmppchat) {
|
|
|
- return factory(xmppchat);
|
|
|
+ ], function (converse) {
|
|
|
+ return factory(converse);
|
|
|
}
|
|
|
);
|
|
|
-} (this, function (xmppchat) {
|
|
|
+} (this, function (converse) {
|
|
|
|
|
|
return describe("Converse.js", $.proxy(function() {
|
|
|
// Names from http://www.fakenamegenerator.com/
|
|
@@ -21,13 +21,12 @@
|
|
|
'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
|
|
|
];
|
|
|
var num_contacts = req_names.length + pend_names.length + cur_names.length;
|
|
|
- this.bare_jid = 'dummy@localhost';
|
|
|
mock_connection = {
|
|
|
'muc': {
|
|
|
'listRooms': function () {},
|
|
|
'join': function () {}
|
|
|
},
|
|
|
- 'jid': this.bare_jid,
|
|
|
+ 'jid': 'dummy@localhost',
|
|
|
'addHandler': function (handler, ns, name, type, id, from, options) {
|
|
|
return function () {};
|
|
|
},
|
|
@@ -54,9 +53,13 @@
|
|
|
|
|
|
// Clear localStorage
|
|
|
window.localStorage.clear();
|
|
|
- this.prebind = true;
|
|
|
+ this.initialize({
|
|
|
+ prebind: false,
|
|
|
+ xhr_user_search: false,
|
|
|
+ auto_subscribe: false,
|
|
|
+ animate: false
|
|
|
+ });
|
|
|
this.onConnected(mock_connection);
|
|
|
- this.animate = false; // don't use animations
|
|
|
|
|
|
// Variable declarations for specs
|
|
|
var open_controlbox;
|
|
@@ -64,7 +67,7 @@
|
|
|
describe("The Control Box", $.proxy(function () {
|
|
|
it("is not shown by default", $.proxy(function () {
|
|
|
expect(this.rosterview.$el.is(':visible')).toEqual(false);
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
open_controlbox = $.proxy(function () {
|
|
|
// This spec will only pass if the controlbox is not currently
|
|
@@ -74,7 +77,7 @@
|
|
|
$('.toggle-online-users').click();
|
|
|
expect(this.toggleControlBox).toHaveBeenCalled();
|
|
|
expect($("div#controlbox").is(':visible')).toBe(true);
|
|
|
- }, xmppchat);
|
|
|
+ }, converse);
|
|
|
it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox);
|
|
|
|
|
|
describe("The Status Widget", $.proxy(function () {
|
|
@@ -100,8 +103,8 @@
|
|
|
expect(view.updateStatusUI).toHaveBeenCalled();
|
|
|
expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
|
|
|
expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe('I am online');
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can be used to set a custom status message", $.proxy(function () {
|
|
|
var view = this.xmppstatusview;
|
|
@@ -123,17 +126,17 @@
|
|
|
expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
|
|
|
expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe(msg);
|
|
|
});
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("The Contacts Roster", $.proxy(function () {
|
|
|
|
|
|
describe("Pending Contacts", $.proxy(function () {
|
|
|
it("do not have a heading if there aren't any", $.proxy(function () {
|
|
|
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
|
|
var i, t, is_last;
|
|
@@ -159,17 +162,17 @@
|
|
|
t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
|
|
|
expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
|
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("Existing Contacts", $.proxy(function () {
|
|
|
it("do not have a heading if there aren't any", $.proxy(function () {
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none');
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
|
|
var i, t;
|
|
@@ -187,11 +190,11 @@
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
|
|
|
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('block');
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can change their status to online and be sorted alphabetically", $.proxy(function () {
|
|
|
var item, view, jid, t;
|
|
@@ -209,7 +212,7 @@
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
|
|
|
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
|
|
|
var item, view, jid, t;
|
|
@@ -226,7 +229,7 @@
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
|
|
|
expect(t).toEqual(cur_names.slice(3,i+1).sort().join(''));
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can change their status to away and be sorted alphabetically", $.proxy(function () {
|
|
|
var item, view, jid, t;
|
|
@@ -244,7 +247,7 @@
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
|
|
|
expect(t).toEqual(cur_names.slice(6,i+1).sort().join(''));
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
|
|
|
var item, view, jid, t;
|
|
@@ -262,7 +265,7 @@
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
|
|
|
expect(t).toEqual(cur_names.slice(9, i+1).sort().join(''));
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("are ordered according to status: online, busy, away, unavailable, offline", $.proxy(function () {
|
|
|
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
|
|
@@ -287,17 +290,17 @@
|
|
|
for (i=12; i<cur_names.length; i++) {
|
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("Requesting Contacts", $.proxy(function () {
|
|
|
// by default the dts are hidden from css class and only later they will be hidden
|
|
|
// by jQuery therefore for the first check we will see if visible instead of none
|
|
|
it("do not have a heading if there aren't any", $.proxy(function () {
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
|
|
var i, t;
|
|
@@ -319,11 +322,11 @@
|
|
|
// be opened.
|
|
|
expect(this.showControlBox).toHaveBeenCalled();
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block');
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can have their requests accepted by the user", $.proxy(function () {
|
|
|
// TODO: Testing can be more thorough here, the user is
|
|
@@ -338,7 +341,7 @@
|
|
|
accept_button.click();
|
|
|
expect(view.acceptRequest).toHaveBeenCalled();
|
|
|
expect(this.connection.roster.authorize).toHaveBeenCalled();
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can have their requests denied by the user", $.proxy(function () {
|
|
|
var jid = req_names.sort()[1].replace(' ','.').toLowerCase() + '@localhost';
|
|
@@ -354,8 +357,8 @@
|
|
|
expect(this.connection.roster.unauthorize).toHaveBeenCalled();
|
|
|
// There should now be one less contact
|
|
|
expect(this.roster.length).toEqual(num_contacts-1);
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("All Contacts", $.proxy(function () {
|
|
|
|
|
@@ -384,7 +387,7 @@
|
|
|
expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
|
|
|
}
|
|
|
this.rosterview.render();
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
afterEach($.proxy(function () {
|
|
|
// Contacts retrieved from localStorage have chat_status of
|
|
@@ -396,12 +399,24 @@
|
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
|
view.model.set('chat_status', 'online');
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
+
|
|
|
+ describe("The 'Add Contact' widget", $.proxy(function () {
|
|
|
+ it("opens up an add form when you click on it", $.proxy(function () {
|
|
|
+ var panel = this.chatboxesview.views.controlbox.contactspanel;
|
|
|
+ spyOn(panel, 'toggleContactForm').andCallThrough();
|
|
|
+ panel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
+ panel.$el.find('a.toggle-xmpp-contact-form').click();
|
|
|
+ expect(panel.toggleContactForm).toHaveBeenCalled();
|
|
|
+ // XXX: Awaiting more tests, close it again for now...
|
|
|
+ panel.$el.find('a.toggle-xmpp-contact-form').click();
|
|
|
+ }, converse));
|
|
|
+
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("A Chatbox", $.proxy(function () {
|
|
|
-
|
|
|
it("is created when you click on a roster item", $.proxy(function () {
|
|
|
var i, $el, click, jid, view;
|
|
|
// showControlBox was called earlier, so the controlbox is
|
|
@@ -419,7 +434,7 @@
|
|
|
expect(view.openChat).toHaveBeenCalled();
|
|
|
expect(this.chatboxes.length).toEqual(i+2);
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
|
|
|
// We instantiate a new ChatBoxes collection, which by default
|
|
@@ -439,7 +454,7 @@
|
|
|
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
|
|
|
}
|
|
|
this.rosterview.render();
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
|
|
|
var chatbox, view, $el,
|
|
@@ -452,7 +467,7 @@
|
|
|
view.$el.find('.close-chatbox-button').click();
|
|
|
expect(view.closeChat).toHaveBeenCalled();
|
|
|
}
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("will be removed from localStorage when closed", $.proxy(function () {
|
|
|
var newchatboxes = new this.ChatBoxes();
|
|
@@ -465,7 +480,7 @@
|
|
|
|
|
|
// Lets open the controlbox again, purely for visual feedback
|
|
|
open_controlbox();
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("A Chat Message", $.proxy(function () {
|
|
|
it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () {
|
|
@@ -473,7 +488,7 @@
|
|
|
var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
|
|
|
msg = $msg({
|
|
|
from: sender_jid,
|
|
|
- to: this.bare_jid,
|
|
|
+ to: this.connection.jid,
|
|
|
type: 'chat',
|
|
|
id: (new Date()).getTime()
|
|
|
}).c('body').t(message).up()
|
|
@@ -488,7 +503,7 @@
|
|
|
// messageReceived is a handler for received XMPP
|
|
|
// messages
|
|
|
this.chatboxes.messageReceived(msg);
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
waits(500);
|
|
|
runs($.proxy(function () {
|
|
|
// Since we didn't already have an open chatbox, one
|
|
@@ -514,8 +529,8 @@
|
|
|
// chatbox in the DOM
|
|
|
var txt = chatboxview.$el.find('.chat-content').find('.chat-message').find('.chat-message-content').text();
|
|
|
expect(txt).toEqual(message);
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("can be sent from a chatbox, and will appear inside it", $.proxy(function () {
|
|
|
var contact_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
|
|
@@ -528,9 +543,9 @@
|
|
|
expect(view.model.messages.length, 2);
|
|
|
var txt = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content').text();
|
|
|
expect(txt).toEqual(message);
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("The Controlbox Tabs", $.proxy(function () {
|
|
|
it("consist of two tabs, 'Contacts' and 'ChatRooms', of which 'Contacts' is by default visible", $.proxy(function () {
|
|
@@ -541,7 +556,7 @@
|
|
|
expect($panels.children().first().is(':visible')).toBe(true);
|
|
|
expect($panels.children().last().attr('id')).toBe('chatrooms');
|
|
|
expect($panels.children().last().is(':visible')).toBe(false);
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
describe("The Chatrooms Panel", $.proxy(function () {
|
|
|
|
|
@@ -562,7 +577,7 @@
|
|
|
expect($chatrooms.is(':visible')).toBe(true);
|
|
|
expect(cbview.switchTab).toHaveBeenCalled();
|
|
|
});
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
|
|
|
it("contains a form through which a new chatroom can be created", $.proxy(function () {
|
|
|
var roomspanel = this.chatboxesview.views.controlbox.roomspanel;
|
|
@@ -582,13 +597,9 @@
|
|
|
waits('250');
|
|
|
runs($.proxy(function () {
|
|
|
expect($('.chatroom').length).toBe(1); // There should now be an open chatroom
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
-
|
|
|
-
|
|
|
- }, xmppchat));
|
|
|
- }, xmppchat));
|
|
|
-
|
|
|
-
|
|
|
- }, xmppchat));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
+ }, converse));
|
|
|
}));
|