2015-10-25 18:49:35 +01:00
|
|
|
/*global converse */
|
2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2014-10-15 19:16:02 +02:00
|
|
|
"jquery",
|
2015-10-25 18:49:35 +01:00
|
|
|
"underscore",
|
2013-11-02 12:37:38 +01:00
|
|
|
"mock",
|
2014-08-08 22:06:01 +02:00
|
|
|
"test_utils"
|
2015-10-25 18:49:35 +01:00
|
|
|
], function ($, _, mock, test_utils) {
|
|
|
|
return factory($, _, mock, test_utils);
|
2013-11-02 12:37:38 +01:00
|
|
|
}
|
|
|
|
);
|
2015-10-25 18:49:35 +01:00
|
|
|
} (this, function ($, _, mock, test_utils) {
|
2015-02-01 16:15:34 +01:00
|
|
|
var $pres = converse_api.env.$pres;
|
|
|
|
var $iq = converse_api.env.$iq;
|
2014-07-20 20:45:59 +02:00
|
|
|
|
|
|
|
var checkHeaderToggling = function ($header) {
|
|
|
|
var $toggle = $header.find('a.group-toggle');
|
|
|
|
expect($header.css('display')).toEqual('block');
|
|
|
|
expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:visible').length).toBeTruthy();
|
|
|
|
expect($toggle.hasClass('icon-closed')).toBeFalsy();
|
|
|
|
expect($toggle.hasClass('icon-opened')).toBeTruthy();
|
|
|
|
$toggle.click();
|
|
|
|
expect($toggle.hasClass('icon-closed')).toBeTruthy();
|
|
|
|
expect($toggle.hasClass('icon-opened')).toBeFalsy();
|
|
|
|
expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:hidden').length).toBeTruthy();
|
|
|
|
$toggle.click();
|
|
|
|
expect($toggle.hasClass('icon-closed')).toBeFalsy();
|
|
|
|
expect($toggle.hasClass('icon-opened')).toBeTruthy();
|
|
|
|
expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:visible').length).toBeTruthy();
|
|
|
|
};
|
|
|
|
|
2014-08-08 22:06:01 +02:00
|
|
|
describe("The Control Box", $.proxy(function (mock, test_utils) {
|
2014-03-04 14:48:16 +01:00
|
|
|
beforeEach(function () {
|
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
2014-03-04 14:48:16 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-16 00:03:34 +02:00
|
|
|
it("can be opened by clicking a DOM element with class 'toggle-controlbox'", $.proxy(function () {
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeControlBox();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2014-06-29 18:30:01 +02:00
|
|
|
waits(50);
|
2014-02-28 03:04:52 +01:00
|
|
|
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();
|
2014-06-16 00:03:34 +02:00
|
|
|
$('.toggle-controlbox').click();
|
2014-02-28 03:04:52 +01:00
|
|
|
}.bind(converse));
|
2014-06-29 18:30:01 +02:00
|
|
|
waits(50);
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
|
|
|
expect(this.controlboxtoggle.onClick).toHaveBeenCalled();
|
|
|
|
expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(this.emit).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object));
|
2014-02-28 03:04:52 +01:00
|
|
|
expect($("div#controlbox").is(':visible')).toBe(true);
|
|
|
|
}.bind(converse));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("The Status Widget", $.proxy(function () {
|
2014-03-04 14:48:16 +01:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
2014-03-04 14:48:16 +01:00
|
|
|
});
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("shows the user's chat status, which is online by default", $.proxy(function () {
|
|
|
|
var view = this.xmppstatusview;
|
|
|
|
expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
|
|
|
|
expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am online');
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can be used to set the current user's chat status", $.proxy(function () {
|
|
|
|
var view = this.xmppstatusview;
|
|
|
|
spyOn(view, 'toggleOptions').andCallThrough();
|
|
|
|
spyOn(view, 'setStatus').andCallThrough();
|
2013-12-15 17:13:39 +01:00
|
|
|
spyOn(converse, 'emit');
|
2013-11-02 12:37:38 +01:00
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
runs(function () {
|
|
|
|
view.$el.find('a.choose-xmpp-status').click();
|
|
|
|
expect(view.toggleOptions).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
spyOn(view, 'updateStatusUI').andCallThrough();
|
|
|
|
view.initialize(); // Rebind events for spy
|
2013-12-15 17:13:39 +01:00
|
|
|
$(view.$el.find('.dropdown dd ul li a')[1]).click(); // Change status to "dnd"
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(view.setStatus).toHaveBeenCalled();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('statusChanged', 'dnd');
|
2013-11-02 12:37:38 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
expect(view.updateStatusUI).toHaveBeenCalled();
|
|
|
|
expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(false);
|
|
|
|
expect(view.$el.find('a.choose-xmpp-status').hasClass('dnd')).toBe(true);
|
|
|
|
expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am busy');
|
|
|
|
}, converse));
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can be used to set a custom status message", $.proxy(function () {
|
|
|
|
var view = this.xmppstatusview;
|
|
|
|
this.xmppstatus.save({'status': 'online'});
|
|
|
|
spyOn(view, 'setStatusMessage').andCallThrough();
|
|
|
|
spyOn(view, 'renderStatusChangeForm').andCallThrough();
|
2013-12-15 17:13:39 +01:00
|
|
|
spyOn(converse, 'emit');
|
2013-11-02 12:37:38 +01:00
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
view.$el.find('a.change-xmpp-status-message').click();
|
|
|
|
expect(view.renderStatusChangeForm).toHaveBeenCalled();
|
|
|
|
// The async testing here is used only to provide time for
|
|
|
|
// visual feedback
|
|
|
|
var msg = 'I am happy';
|
|
|
|
runs (function () {
|
|
|
|
view.$el.find('form input.custom-xmpp-status').val(msg);
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs (function () {
|
|
|
|
view.$el.find('form#set-custom-xmpp-status').submit();
|
|
|
|
expect(view.setStatusMessage).toHaveBeenCalled();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('statusMessageChanged', msg);
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
|
|
|
|
expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe(msg);
|
|
|
|
});
|
|
|
|
}, converse));
|
|
|
|
}, converse));
|
2014-08-08 22:06:01 +02:00
|
|
|
}, converse, mock, test_utils));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2014-08-18 20:37:38 +02:00
|
|
|
describe("The Contacts Roster", $.proxy(function (mock, utils) {
|
|
|
|
function _clearContacts () {
|
|
|
|
utils.clearBrowserStorage();
|
|
|
|
converse.rosterview.model.reset();
|
|
|
|
}
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2014-08-18 20:37:38 +02:00
|
|
|
describe("The live filter", $.proxy(function () {
|
2016-03-13 18:40:36 +01:00
|
|
|
beforeEach(function () {
|
|
|
|
test_utils.openControlBox();
|
2016-04-13 17:11:04 +02:00
|
|
|
test_utils.openContactsPanel();
|
2016-03-13 18:40:36 +01:00
|
|
|
});
|
|
|
|
|
2016-04-02 13:30:54 +02:00
|
|
|
it("will only appear when roster contacts flow over the visible area", function () {
|
2014-08-18 20:37:38 +02:00
|
|
|
var $filter = converse.rosterview.$('.roster-filter');
|
|
|
|
var names = mock.cur_names;
|
2016-04-02 13:30:54 +02:00
|
|
|
runs(function () {
|
|
|
|
_clearContacts();
|
2014-08-18 20:37:38 +02:00
|
|
|
converse.rosterview.update(); // XXX: Will normally called as event handler
|
2016-04-02 13:30:54 +02:00
|
|
|
});
|
|
|
|
waits(5); // Needed, due to debounce
|
|
|
|
runs(function () {
|
|
|
|
expect($filter.length).toBe(1);
|
|
|
|
expect($filter.is(':visible')).toBeFalsy();
|
|
|
|
for (var i=0; i<names.length; i++) {
|
|
|
|
converse.roster.create({
|
|
|
|
ask: null,
|
|
|
|
fullname: names[i],
|
|
|
|
jid: names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
requesting: 'false',
|
|
|
|
subscription: 'both'
|
|
|
|
});
|
|
|
|
converse.rosterview.update(); // XXX: Will normally called as event handler
|
|
|
|
}
|
|
|
|
});
|
|
|
|
waits(5); // Needed, due to debounce
|
|
|
|
runs(function () {
|
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
2014-10-27 23:06:11 +01:00
|
|
|
if (converse.rosterview.$roster.hasScrollBar()) {
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($filter.is(':visible')).toBeTruthy();
|
|
|
|
} else {
|
|
|
|
expect($filter.is(':visible')).toBeFalsy();
|
|
|
|
}
|
2016-04-02 13:30:54 +02:00
|
|
|
});
|
|
|
|
});
|
2014-08-02 15:05:27 +02:00
|
|
|
|
2014-08-18 20:37:38 +02:00
|
|
|
it("can be used to filter the contacts shown", function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var $filter;
|
|
|
|
var $roster;
|
|
|
|
runs(function () {
|
|
|
|
_clearContacts();
|
|
|
|
converse.roster_groups = true;
|
|
|
|
utils.createGroupedContacts();
|
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
|
|
|
$roster = converse.rosterview.$roster;
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(5); // Needed, due to debounce in "update" method
|
2014-08-18 20:37:38 +02:00
|
|
|
runs(function () {
|
2016-04-02 13:30:54 +02:00
|
|
|
converse.rosterview.filter_view.delegateEvents();
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($roster.find('dd:visible').length).toBe(15);
|
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
|
|
|
$filter.val("candice");
|
|
|
|
expect($roster.find('dd:visible').length).toBe(15); // because no keydown event
|
|
|
|
expect($roster.find('dt:visible').length).toBe(5); // ditto
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-18 20:37:38 +02:00
|
|
|
runs (function () {
|
|
|
|
expect($roster.find('dd:visible').length).toBe(1);
|
|
|
|
expect($roster.find('dd:visible').eq(0).text().trim()).toBe('Candice van der Knijff');
|
|
|
|
expect($roster.find('dt:visible').length).toBe(1);
|
|
|
|
expect($roster.find('dt:visible').eq(0).text()).toBe('colleagues');
|
2016-04-02 13:30:54 +02:00
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
$filter.val("an");
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-18 20:37:38 +02:00
|
|
|
runs (function () {
|
|
|
|
expect($roster.find('dd:visible').length).toBe(5);
|
|
|
|
expect($roster.find('dt:visible').length).toBe(4);
|
2016-04-02 13:30:54 +02:00
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
$filter.val("xxx");
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-18 20:37:38 +02:00
|
|
|
runs (function () {
|
|
|
|
expect($roster.find('dd:visible').length).toBe(0);
|
|
|
|
expect($roster.find('dt:visible').length).toBe(0);
|
2016-04-02 13:30:54 +02:00
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
2014-08-31 21:20:28 +02:00
|
|
|
$filter.val(""); // Check that contacts are shown again, when the filter string is cleared.
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-31 21:20:28 +02:00
|
|
|
runs(function () {
|
|
|
|
expect($roster.find('dd:visible').length).toBe(15);
|
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
2014-08-18 20:37:38 +02:00
|
|
|
});
|
|
|
|
converse.roster_groups = false;
|
2014-08-02 15:05:27 +02:00
|
|
|
});
|
|
|
|
|
2014-08-18 20:37:38 +02:00
|
|
|
it("can be used to filter the groups shown", function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var $filter;
|
|
|
|
var $roster;
|
|
|
|
var $type;
|
|
|
|
runs(function () {
|
|
|
|
converse.roster_groups = true;
|
|
|
|
_clearContacts();
|
|
|
|
utils.createGroupedContacts();
|
2016-04-02 13:30:54 +02:00
|
|
|
converse.rosterview.filter_view.delegateEvents();
|
2014-10-27 23:06:11 +01:00
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
|
|
|
$roster = converse.rosterview.$roster;
|
|
|
|
$type = converse.rosterview.$('.filter-type');
|
|
|
|
$type.val('groups');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-18 20:37:38 +02:00
|
|
|
runs(function () {
|
|
|
|
expect($roster.find('dd:visible').length).toBe(15);
|
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
|
|
|
$filter.val("colleagues");
|
|
|
|
expect($roster.find('dd:visible').length).toBe(15); // because no keydown event
|
|
|
|
expect($roster.find('dt:visible').length).toBe(5); // ditto
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-18 20:37:38 +02:00
|
|
|
runs (function () {
|
|
|
|
expect($roster.find('dt:visible').length).toBe(1);
|
|
|
|
expect($roster.find('dt:visible').eq(0).text()).toBe('colleagues');
|
|
|
|
// Check that all contacts under the group are shown
|
|
|
|
expect($roster.find('dt:visible').nextUntil('dt', 'dd:hidden').length).toBe(0);
|
2016-04-02 13:30:54 +02:00
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
$filter.val("xxx");
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-18 20:37:38 +02:00
|
|
|
runs (function () {
|
|
|
|
expect($roster.find('dt:visible').length).toBe(0);
|
2016-04-02 13:30:54 +02:00
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
2014-08-31 21:20:28 +02:00
|
|
|
$filter.val(""); // Check that groups are shown again, when the filter string is cleared.
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-31 21:20:28 +02:00
|
|
|
runs(function () {
|
|
|
|
expect($roster.find('dd:visible').length).toBe(15);
|
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
2014-08-18 20:37:38 +02:00
|
|
|
});
|
2014-08-02 15:05:27 +02:00
|
|
|
converse.roster_groups = false;
|
|
|
|
});
|
|
|
|
|
2014-08-18 20:37:38 +02:00
|
|
|
it("has a button with which its contents can be cleared", function () {
|
|
|
|
converse.roster_groups = true;
|
|
|
|
_clearContacts();
|
|
|
|
utils.createGroupedContacts();
|
|
|
|
var $filter = converse.rosterview.$('.roster-filter');
|
|
|
|
runs (function () {
|
2016-04-02 13:30:54 +02:00
|
|
|
converse.rosterview.filter_view.delegateEvents();
|
2014-08-18 20:37:38 +02:00
|
|
|
$filter.val("xxx");
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
expect($filter.hasClass("x")).toBeFalsy();
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
waits(550); // Needed, due to debounce
|
2014-08-18 20:37:38 +02:00
|
|
|
runs (function () {
|
2016-04-02 13:30:54 +02:00
|
|
|
$filter = converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($filter.hasClass("x")).toBeTruthy();
|
|
|
|
$filter.addClass("onX").click();
|
|
|
|
expect($filter.val()).toBe("");
|
|
|
|
});
|
|
|
|
converse.roster_groups = false;
|
|
|
|
});
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("A Roster Group", $.proxy(function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
converse.roster_groups = true;
|
|
|
|
});
|
|
|
|
afterEach(function () {
|
|
|
|
converse.roster_groups = false;
|
|
|
|
});
|
2014-07-31 18:20:20 +02:00
|
|
|
|
|
|
|
it("can be used to organize existing contacts", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
_clearContacts();
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
|
|
|
converse.rosterview.render();
|
|
|
|
utils.createContacts('pending');
|
|
|
|
utils.createContacts('requesting');
|
|
|
|
utils.createGroupedContacts();
|
|
|
|
}, this));
|
|
|
|
waits(50); // Needed, due to debounce
|
|
|
|
runs($.proxy(function () {
|
|
|
|
// Check that the groups appear alphabetically and that
|
|
|
|
// requesting and pending contacts are last.
|
|
|
|
var group_titles = $.map(this.rosterview.$el.find('dt'), function (o) { return $(o).text().trim(); });
|
|
|
|
expect(group_titles).toEqual([
|
2016-06-21 19:48:18 +02:00
|
|
|
"Contact requests",
|
2014-10-27 23:06:11 +01:00
|
|
|
"colleagues",
|
|
|
|
"Family",
|
|
|
|
"friends & acquaintences",
|
|
|
|
"ænemies",
|
|
|
|
"Ungrouped",
|
|
|
|
"Pending contacts"
|
|
|
|
]);
|
|
|
|
// Check that usernames appear alphabetically per group
|
|
|
|
_.each(_.keys(mock.groups), $.proxy(function (name) {
|
|
|
|
var $contacts = this.rosterview.$('dt.roster-group[data-group="'+name+'"]').nextUntil('dt', 'dd');
|
|
|
|
var names = $.map($contacts, function (o) { return $(o).text().trim(); });
|
|
|
|
expect(names).toEqual(_.clone(names).sort());
|
|
|
|
}, converse));
|
|
|
|
}, this));
|
2014-07-31 21:50:34 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-08-03 20:48:49 +02:00
|
|
|
it("can share contacts with other roster groups", $.proxy(function () {
|
2014-08-01 21:36:20 +02:00
|
|
|
var groups = ['colleagues', 'friends'];
|
2014-10-27 23:06:11 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
_clearContacts();
|
2015-10-25 18:49:35 +01:00
|
|
|
var i=0;
|
2014-10-27 23:06:11 +01:00
|
|
|
spyOn(converse, 'emit');
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
|
|
|
converse.rosterview.render();
|
|
|
|
for (i=0; i<mock.cur_names.length; i++) {
|
|
|
|
this.roster.create({
|
|
|
|
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
groups: groups,
|
|
|
|
fullname: mock.cur_names[i]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
waits(50); // Needed, due to debounce
|
|
|
|
runs($.proxy(function () {
|
|
|
|
// Check that usernames appear alphabetically per group
|
|
|
|
_.each(groups, $.proxy(function (name) {
|
|
|
|
var $contacts = this.rosterview.$('dt.roster-group[data-group="'+name+'"]').nextUntil('dt', 'dd');
|
|
|
|
var names = $.map($contacts, function (o) { return $(o).text().trim(); });
|
|
|
|
expect(names).toEqual(_.clone(names).sort());
|
|
|
|
expect(names.length).toEqual(mock.cur_names.length);
|
|
|
|
}, this));
|
|
|
|
}, this));
|
2014-07-31 18:20:20 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-08-03 20:48:49 +02:00
|
|
|
it("remembers whether it is closed or opened", $.proxy(function () {
|
2014-08-18 20:37:38 +02:00
|
|
|
var i=0, j=0;
|
2014-08-03 20:48:49 +02:00
|
|
|
var groups = {
|
|
|
|
'colleagues': 3,
|
|
|
|
'friends & acquaintences': 3,
|
|
|
|
'Ungrouped': 2
|
|
|
|
};
|
|
|
|
_.each(_.keys(groups), $.proxy(function (name) {
|
|
|
|
j = i;
|
|
|
|
for (i=j; i<j+groups[name]; i++) {
|
2014-08-03 23:02:25 +02:00
|
|
|
this.roster.create({
|
2014-08-03 20:48:49 +02:00
|
|
|
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
groups: name === 'ungrouped'? [] : [name],
|
2014-08-04 18:00:30 +02:00
|
|
|
fullname: mock.cur_names[i]
|
2014-08-03 20:48:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}, converse));
|
|
|
|
var view = this.rosterview.get('colleagues');
|
|
|
|
var $toggle = view.$el.find('a.group-toggle');
|
|
|
|
expect(view.model.get('state')).toBe('opened');
|
|
|
|
$toggle.click();
|
|
|
|
expect(view.model.get('state')).toBe('closed');
|
|
|
|
$toggle.click();
|
|
|
|
expect(view.model.get('state')).toBe('opened');
|
|
|
|
}, converse));
|
|
|
|
}, converse));
|
2014-07-31 18:20:20 +02:00
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
describe("Pending Contacts", $.proxy(function () {
|
2014-07-25 09:58:42 +02:00
|
|
|
function _clearContacts () {
|
2014-08-18 20:37:38 +02:00
|
|
|
utils.clearBrowserStorage();
|
2014-07-25 09:58:42 +02:00
|
|
|
converse.rosterview.model.reset();
|
2014-08-03 23:07:48 +02:00
|
|
|
}
|
2014-07-25 09:58:42 +02:00
|
|
|
|
|
|
|
function _addContacts () {
|
|
|
|
_clearContacts();
|
|
|
|
// Must be initialized, so that render is called and documentFragment set up.
|
2014-08-18 20:37:38 +02:00
|
|
|
utils.createContacts('pending').openControlBox().openContactsPanel();
|
2014-08-03 23:07:48 +02:00
|
|
|
}
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2014-07-20 20:45:59 +02:00
|
|
|
it("can be collapsed under their own header", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
checkHeaderToggling.apply(this, [this.rosterview.get('Pending contacts').$el]);
|
|
|
|
}, this));
|
2014-07-04 20:37:37 +02:00
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("can be added to the roster", $.proxy(function () {
|
2014-07-25 09:58:42 +02:00
|
|
|
_clearContacts();
|
2013-12-18 15:30:19 +01:00
|
|
|
spyOn(converse, 'emit');
|
2014-08-02 15:05:27 +02:00
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2013-12-18 15:30:19 +01:00
|
|
|
runs($.proxy(function () {
|
2014-08-03 23:02:25 +02:00
|
|
|
this.roster.create({
|
2013-12-18 15:30:19 +01:00
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
2014-08-04 18:00:30 +02:00
|
|
|
fullname: mock.pend_names[0]
|
2013-12-18 15:30:19 +01:00
|
|
|
});
|
|
|
|
}, converse));
|
|
|
|
waits(300);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
expect(this.rosterview.$el.is(':visible')).toEqual(true);
|
2014-08-02 15:05:27 +02:00
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
2013-12-18 15:30:19 +01:00
|
|
|
}, converse));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
2014-12-11 01:32:59 +01:00
|
|
|
it("are shown in the roster when show_only_online_users", $.proxy(function () {
|
2015-04-06 11:10:05 +02:00
|
|
|
converse.show_only_online_users = true;
|
2014-12-11 01:32:59 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
|
|
|
runs($.proxy(function () {
|
|
|
|
expect(this.rosterview.$el.is(':visible')).toEqual(true);
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
}, converse));
|
|
|
|
waits(300); // Needed, due to debounce
|
|
|
|
runs ($.proxy(function () {
|
|
|
|
expect(this.rosterview.$el.find('dd:visible').length).toBe(3);
|
|
|
|
expect(this.rosterview.$el.find('dt:visible').length).toBe(1);
|
|
|
|
}, converse));
|
|
|
|
converse.show_only_online_users = false;
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("are shown in the roster when hide_offline_users", $.proxy(function () {
|
|
|
|
converse.hide_offline_users = true;
|
2015-04-06 11:10:05 +02:00
|
|
|
runs(function () {
|
2014-12-11 01:32:59 +01:00
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
|
|
|
runs($.proxy(function () {
|
|
|
|
expect(this.rosterview.$el.is(':visible')).toEqual(true);
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
}, converse));
|
|
|
|
waits(300); // Needed, due to debounce
|
|
|
|
runs ($.proxy(function () {
|
|
|
|
expect(this.rosterview.$el.find('dd:visible').length).toBe(3);
|
|
|
|
expect(this.rosterview.$el.find('dt:visible').length).toBe(1);
|
|
|
|
}, converse));
|
|
|
|
converse.hide_offline_users = false;
|
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("can be removed by the user", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
_addContacts();
|
|
|
|
}, this));
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var name = mock.pend_names[0];
|
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2015-04-06 11:10:05 +02:00
|
|
|
var contact = this.roster.get(jid);
|
2014-10-27 23:06:11 +01:00
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
2015-04-06 11:10:05 +02:00
|
|
|
spyOn(contact, 'unauthorize').andCallFake(function () { return contact; });
|
|
|
|
spyOn(contact, 'removeFromRoster');
|
|
|
|
spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback) {
|
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2014-10-27 23:06:11 +01:00
|
|
|
converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
|
|
|
|
.siblings('.remove-xmpp-contact').click();
|
2014-08-01 20:09:32 +02:00
|
|
|
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2015-04-06 11:10:05 +02:00
|
|
|
expect(converse.connection.sendIQ).toHaveBeenCalled();
|
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
|
|
|
expect(this.connection.sendIQ).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')").length).toEqual(0);
|
|
|
|
}, this));
|
2014-08-01 20:09:32 +02:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("do not have a header if there aren't any", $.proxy(function () {
|
|
|
|
var name = mock.pend_names[0];
|
2014-10-27 23:06:11 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
_clearContacts();
|
|
|
|
}, this));
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
2015-10-25 18:49:35 +01:00
|
|
|
this.roster.create({
|
2014-10-27 23:06:11 +01:00
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: name
|
|
|
|
});
|
2015-04-06 11:10:05 +02:00
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
|
|
|
spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback) {
|
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(this.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(true);
|
|
|
|
converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
|
|
|
|
.siblings('.remove-xmpp-contact').click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2015-04-06 11:10:05 +02:00
|
|
|
expect(this.connection.sendIQ).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(this.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(false);
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
2014-08-01 20:09:32 +02:00
|
|
|
|
2014-07-20 20:45:59 +02:00
|
|
|
it("will lose their own header once the last one has been removed", $.proxy(function () {
|
2014-07-25 09:58:42 +02:00
|
|
|
_addContacts();
|
2014-08-01 20:09:32 +02:00
|
|
|
var name;
|
2014-07-04 20:37:37 +02:00
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
2015-10-25 18:49:35 +01:00
|
|
|
for (var i=0; i<mock.pend_names.length; i++) {
|
2014-08-01 20:09:32 +02:00
|
|
|
name = mock.pend_names[i];
|
|
|
|
converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
|
|
|
|
.siblings('.remove-xmpp-contact').click();
|
2014-07-04 20:37:37 +02:00
|
|
|
}
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy();
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
2014-07-25 09:58:42 +02:00
|
|
|
_clearContacts();
|
2014-08-04 18:00:30 +02:00
|
|
|
var i, t;
|
2013-12-18 15:30:19 +01:00
|
|
|
spyOn(converse, 'emit');
|
2014-08-02 15:05:27 +02:00
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2013-11-02 12:37:38 +01:00
|
|
|
for (i=0; i<mock.pend_names.length; i++) {
|
2014-08-03 23:02:25 +02:00
|
|
|
this.roster.create({
|
2013-11-02 12:37:38 +01:00
|
|
|
jid: mock.pend_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
2014-08-04 18:00:30 +02:00
|
|
|
fullname: mock.pend_names[i]
|
2013-11-02 12:37:38 +01:00
|
|
|
});
|
2014-08-02 15:05:27 +02:00
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
2013-11-02 12:37:38 +01:00
|
|
|
}
|
2014-07-24 20:48:52 +02:00
|
|
|
// Check that they are sorted alphabetically
|
2014-08-02 15:05:27 +02:00
|
|
|
t = this.rosterview.get('Pending contacts').$el.siblings('dd.pending-xmpp-contact').find('span').text();
|
2014-07-24 20:48:52 +02:00
|
|
|
expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join(''));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("Existing Contacts", $.proxy(function () {
|
2014-07-29 19:53:57 +02:00
|
|
|
function _clearContacts () {
|
2014-08-18 20:37:38 +02:00
|
|
|
utils.clearBrowserStorage();
|
2014-07-29 19:53:57 +02:00
|
|
|
converse.rosterview.model.reset();
|
2014-08-03 23:07:48 +02:00
|
|
|
}
|
2014-07-29 19:53:57 +02:00
|
|
|
|
|
|
|
var _addContacts = function () {
|
|
|
|
_clearContacts();
|
2014-08-18 20:37:38 +02:00
|
|
|
utils.createContacts('current').openControlBox().openContactsPanel();
|
2014-07-29 19:53:57 +02:00
|
|
|
};
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2014-07-20 22:44:50 +02:00
|
|
|
it("can be collapsed under their own header", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]);
|
|
|
|
}, this));
|
2014-07-20 22:44:50 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-08-04 18:48:48 +02:00
|
|
|
it("will be hidden when appearing under a collapsed group", $.proxy(function () {
|
|
|
|
_addContacts();
|
|
|
|
this.rosterview.$el.find('dt.roster-group').find('a.group-toggle').click();
|
|
|
|
var name = "Max Mustermann";
|
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
converse.roster.create({
|
|
|
|
ask: null,
|
|
|
|
fullname: name,
|
|
|
|
jid: jid,
|
|
|
|
requesting: false,
|
|
|
|
subscription: 'both'
|
|
|
|
});
|
|
|
|
var view = this.rosterview.get('My contacts').get(jid);
|
|
|
|
expect(view.$el.is(':visible')).toBe(false);
|
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_clearContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var i, t;
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
|
|
|
for (i=0; i<mock.cur_names.length; i++) {
|
|
|
|
this.roster.create({
|
|
|
|
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
fullname: mock.cur_names[i]
|
|
|
|
});
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
}
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
2014-08-01 20:09:32 +02:00
|
|
|
it("can be removed by the user", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var name = mock.cur_names[0];
|
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2015-04-06 11:10:05 +02:00
|
|
|
var contact = this.roster.get(jid);
|
2014-10-27 23:06:11 +01:00
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
2015-04-06 11:10:05 +02:00
|
|
|
spyOn(contact, 'removeFromRoster');
|
|
|
|
spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback) {
|
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
2014-10-27 23:06:11 +01:00
|
|
|
|
|
|
|
converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
|
|
|
|
.siblings('.remove-xmpp-contact').click();
|
|
|
|
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2015-04-06 11:10:05 +02:00
|
|
|
expect(converse.connection.sendIQ).toHaveBeenCalled();
|
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(converse.rosterview.$el.find(".open-chat:contains('"+name+"')").length).toEqual(0);
|
|
|
|
}, this));
|
2014-08-01 20:09:32 +02:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
|
|
|
|
it("do not have a header if there aren't any", $.proxy(function () {
|
|
|
|
var name = mock.cur_names[0];
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_clearContacts();
|
2014-08-01 20:09:32 +02:00
|
|
|
});
|
2014-10-27 23:06:11 +01:00
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
2015-04-06 11:10:05 +02:00
|
|
|
var contact = this.roster.create({
|
2014-10-27 23:06:11 +01:00
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
fullname: name
|
|
|
|
});
|
2015-04-06 11:10:05 +02:00
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
|
|
|
spyOn(contact, 'removeFromRoster');
|
|
|
|
spyOn(this.connection, 'sendIQ').andCallFake(function (iq, callback) {
|
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
|
|
|
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('block');
|
|
|
|
converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
|
|
|
|
.siblings('.remove-xmpp-contact').click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2015-04-06 11:10:05 +02:00
|
|
|
expect(this.connection.sendIQ).toHaveBeenCalled();
|
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none');
|
|
|
|
}, this));
|
2014-08-01 20:09:32 +02:00
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("can change their status to online and be sorted alphabetically", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var jid, t;
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2015-10-25 18:49:35 +01:00
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
2014-10-27 23:06:11 +01:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'online');
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var jid, t;
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2015-10-25 18:49:35 +01:00
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
2014-10-27 23:06:11 +01:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'dnd');
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can change their status to away and be sorted alphabetically", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var jid, t;
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2015-10-25 18:49:35 +01:00
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
2014-10-27 23:06:11 +01:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'away');
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can change their status to xa and be sorted alphabetically", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var jid, t;
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2015-10-25 18:49:35 +01:00
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
2014-10-27 23:06:11 +01:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'xa');
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text();
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var jid, t;
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2015-10-25 18:49:35 +01:00
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
2014-10-27 23:06:11 +01:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'unavailable');
|
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0, i+1).sort().join(''));
|
|
|
|
}
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("are ordered according to status: online, busy, away, xa, unavailable, offline", $.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
runs(function () {
|
|
|
|
_addContacts();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
2015-10-25 18:49:35 +01:00
|
|
|
var i, jid;
|
2014-10-27 23:06:11 +01:00
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'online');
|
|
|
|
}
|
|
|
|
for (i=3; i<6; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'dnd');
|
|
|
|
}
|
|
|
|
for (i=6; i<9; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'away');
|
|
|
|
}
|
|
|
|
for (i=9; i<12; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'xa');
|
|
|
|
}
|
|
|
|
for (i=12; i<15; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
this.roster.get(jid).set('chat_status', 'unavailable');
|
|
|
|
}
|
2014-06-30 20:26:45 +02:00
|
|
|
|
2014-10-27 23:06:11 +01:00
|
|
|
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
|
|
|
|
for (i=0; i<3; i++) {
|
2015-04-10 01:23:33 +02:00
|
|
|
expect($(contacts[i]).hasClass('online')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('both')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('dnd')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('away')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('xa')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('unavailable')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('offline')).toBeFalsy();
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=3; i<6; i++) {
|
2015-04-10 01:23:33 +02:00
|
|
|
expect($(contacts[i]).hasClass('dnd')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('both')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('online')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('away')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('xa')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('unavailable')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('offline')).toBeFalsy();
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=6; i<9; i++) {
|
2015-04-10 01:23:33 +02:00
|
|
|
expect($(contacts[i]).hasClass('away')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('both')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('online')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('dnd')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('xa')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('unavailable')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('offline')).toBeFalsy();
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=9; i<12; i++) {
|
2015-04-10 01:23:33 +02:00
|
|
|
expect($(contacts[i]).hasClass('xa')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('both')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('online')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('dnd')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('away')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('unavailable')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('offline')).toBeFalsy();
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=12; i<15; i++) {
|
2015-04-10 01:23:33 +02:00
|
|
|
expect($(contacts[i]).hasClass('unavailable')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('both')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('online')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('dnd')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('away')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('xa')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('offline')).toBeFalsy();
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=15; i<mock.cur_names.length; i++) {
|
2015-04-10 01:23:33 +02:00
|
|
|
expect($(contacts[i]).hasClass('offline')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('both')).toBeTruthy();
|
|
|
|
expect($(contacts[i]).hasClass('online')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('dnd')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('away')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('xa')).toBeFalsy();
|
|
|
|
expect($(contacts[i]).hasClass('unavailable')).toBeFalsy();
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("Requesting Contacts", $.proxy(function () {
|
2014-07-04 20:37:37 +02:00
|
|
|
beforeEach($.proxy(function () {
|
|
|
|
runs(function () {
|
2014-08-18 20:37:38 +02:00
|
|
|
utils.clearBrowserStorage();
|
2014-07-04 20:37:37 +02:00
|
|
|
converse.rosterview.model.reset();
|
2014-08-18 20:37:38 +02:00
|
|
|
utils.createContacts('requesting').openControlBox();
|
2014-07-04 20:37:37 +02:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
2014-08-18 20:37:38 +02:00
|
|
|
utils.openContactsPanel();
|
2014-07-04 20:37:37 +02:00
|
|
|
});
|
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
2014-07-04 20:37:37 +02:00
|
|
|
converse.rosterview.model.reset(); // We want to manually create users so that we can spy
|
2014-07-19 15:26:30 +02:00
|
|
|
var i, children;
|
|
|
|
var names = [];
|
2013-12-18 15:30:19 +01:00
|
|
|
spyOn(converse, 'emit');
|
2014-08-02 15:05:27 +02:00
|
|
|
spyOn(this.rosterview, 'update').andCallThrough();
|
2013-11-02 12:37:38 +01:00
|
|
|
spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
|
2014-07-20 19:36:53 +02:00
|
|
|
var addName = function (idx, item) {
|
|
|
|
if (!$(item).hasClass('request-actions')) {
|
|
|
|
names.push($(item).text().replace(/^\s+|\s+$/g, ''));
|
|
|
|
}
|
|
|
|
};
|
2013-11-02 12:37:38 +01:00
|
|
|
for (i=0; i<mock.req_names.length; i++) {
|
2014-08-03 23:02:25 +02:00
|
|
|
this.roster.create({
|
2013-11-02 12:37:38 +01:00
|
|
|
jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
2013-11-06 08:54:58 +01:00
|
|
|
subscription: 'none',
|
|
|
|
ask: null,
|
|
|
|
requesting: true,
|
2014-08-04 18:00:30 +02:00
|
|
|
fullname: mock.req_names[i]
|
2013-11-02 12:37:38 +01:00
|
|
|
});
|
2014-08-02 15:05:27 +02:00
|
|
|
expect(this.rosterview.update).toHaveBeenCalled();
|
2013-11-02 12:37:38 +01:00
|
|
|
// When a requesting contact is added, the controlbox must
|
|
|
|
// be opened.
|
|
|
|
expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
|
|
|
|
}
|
2014-07-24 20:48:52 +02:00
|
|
|
// Check that they are sorted alphabetically
|
2014-08-02 15:05:27 +02:00
|
|
|
children = this.rosterview.get('Contact requests').$el.siblings('dd.requesting-xmpp-contact').children('span');
|
2014-07-24 20:48:52 +02:00
|
|
|
names = [];
|
|
|
|
children.each(addName);
|
|
|
|
expect(names.join('')).toEqual(mock.req_names.slice(0,i+1).sort().join(''));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
2014-08-01 20:09:32 +02:00
|
|
|
it("do not have a header if there aren't any", $.proxy(function () {
|
|
|
|
converse.rosterview.model.reset(); // We want to manually create users so that we can spy
|
|
|
|
var name = mock.req_names[0];
|
2014-10-27 23:06:11 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
|
|
|
this.roster.create({
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: null,
|
|
|
|
requesting: true,
|
|
|
|
fullname: name
|
|
|
|
});
|
|
|
|
}, this));
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
expect(this.rosterview.get('Contact requests').$el.is(':visible')).toEqual(true);
|
|
|
|
converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
|
|
|
.siblings('.request-actions')
|
|
|
|
.find('.decline-xmpp-request').click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(this.rosterview.get('Contact requests').$el.is(':visible')).toEqual(false);
|
|
|
|
}, this));
|
2014-08-01 20:09:32 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-07-20 20:45:59 +02:00
|
|
|
it("can be collapsed under their own header", $.proxy(function () {
|
2014-08-02 15:05:27 +02:00
|
|
|
checkHeaderToggling.apply(this, [this.rosterview.get('Contact requests').$el]);
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can have their requests accepted by the user", $.proxy(function () {
|
|
|
|
// TODO: Testing can be more thorough here, the user is
|
|
|
|
// actually not accepted/authorized because of
|
|
|
|
// mock_connection.
|
2014-08-01 20:09:32 +02:00
|
|
|
var name = mock.req_names.sort()[0];
|
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2015-04-06 12:26:08 +02:00
|
|
|
var contact = this.roster.get(jid);
|
2015-04-08 10:34:14 +02:00
|
|
|
spyOn(converse.roster, 'sendContactAddIQ').andCallFake(function (jid, fullname, groups, callback) {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
spyOn(contact, 'authorize').andCallFake(function () { return contact; });
|
2014-08-01 20:09:32 +02:00
|
|
|
converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
|
|
|
.siblings('.request-actions')
|
|
|
|
.find('.accept-xmpp-request').click();
|
2015-04-08 10:34:14 +02:00
|
|
|
expect(converse.roster.sendContactAddIQ).toHaveBeenCalled();
|
2015-04-06 12:26:08 +02:00
|
|
|
expect(contact.authorize).toHaveBeenCalled();
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can have their requests denied by the user", $.proxy(function () {
|
2014-07-25 08:56:54 +02:00
|
|
|
this.rosterview.model.reset();
|
2014-10-27 23:06:11 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
utils.createContacts('requesting').openControlBox();
|
|
|
|
converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
|
|
|
}, this));
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
var name = mock.req_names.sort()[1];
|
2015-04-06 12:26:08 +02:00
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var contact = this.roster.get(jid);
|
|
|
|
spyOn(window, 'confirm').andReturn(true);
|
|
|
|
spyOn(contact, 'unauthorize').andCallFake(function () { return contact; });
|
2014-10-27 23:06:11 +01:00
|
|
|
converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
|
|
|
.siblings('.request-actions')
|
|
|
|
.find('.decline-xmpp-request').click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2015-04-06 12:26:08 +02:00
|
|
|
expect(contact.unauthorize).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
// There should now be one less contact
|
|
|
|
expect(this.roster.length).toEqual(mock.req_names.length-1);
|
|
|
|
}, this));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
2014-10-24 18:58:42 +02:00
|
|
|
|
|
|
|
it("are persisted even if other contacts' change their presence ", $.proxy(function() {
|
|
|
|
/* This is a regression test.
|
|
|
|
* https://github.com/jcbrand/converse.js/issues/262
|
|
|
|
*/
|
|
|
|
this.rosterview.model.reset();
|
|
|
|
expect(this.roster.pluck('jid').length).toBe(0);
|
|
|
|
|
|
|
|
var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
|
|
|
|
this.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(this.roster.pluck('jid').length).toBe(1);
|
|
|
|
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
|
|
|
|
|
|
|
// Taken from the spec
|
|
|
|
// http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
|
|
|
|
stanza = $iq({
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'result',
|
|
|
|
id: 'roster_1'
|
|
|
|
}).c('query', {
|
|
|
|
xmlns: 'jabber:iq:roster',
|
|
|
|
}).c('item', {
|
|
|
|
jid: 'romeo@example.net',
|
|
|
|
name: 'Romeo',
|
|
|
|
subscription:'both'
|
|
|
|
}).c('group').t('Friends').up().up()
|
|
|
|
.c('item', {
|
|
|
|
jid: 'mercutio@example.org',
|
|
|
|
name: 'Mercutio',
|
|
|
|
subscription:'from'
|
|
|
|
}).c('group').t('Friends').up().up()
|
|
|
|
.c('item', {
|
|
|
|
jid: 'benvolio@example.org',
|
|
|
|
name: 'Benvolio',
|
|
|
|
subscription:'both'
|
|
|
|
}).c('group').t('Friends');
|
2015-04-06 20:55:38 +02:00
|
|
|
this.roster.onReceivedFromServer(stanza.tree());
|
2014-10-24 18:58:42 +02:00
|
|
|
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("All Contacts", $.proxy(function () {
|
2014-07-04 20:37:37 +02:00
|
|
|
beforeEach($.proxy(function () {
|
2015-01-05 07:32:58 +01:00
|
|
|
runs(function () {
|
|
|
|
utils.clearBrowserStorage();
|
|
|
|
converse.rosterview.model.reset();
|
|
|
|
utils.createContacts('all').openControlBox();
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
utils.openContactsPanel();
|
|
|
|
});
|
2014-07-04 20:37:37 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-06-30 19:21:16 +02:00
|
|
|
it("are saved to, and can be retrieved from, browserStorage", $.proxy(function () {
|
2014-10-24 21:45:48 +02:00
|
|
|
var new_attrs, old_attrs, attrs;
|
2014-08-03 23:02:25 +02:00
|
|
|
var num_contacts = this.roster.length;
|
2015-10-25 18:49:35 +01:00
|
|
|
var new_roster = new this.RosterContacts();
|
2014-06-30 19:21:16 +02:00
|
|
|
// Roster items are yet to be fetched from browserStorage
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(new_roster.length).toEqual(0);
|
2014-08-03 23:02:25 +02:00
|
|
|
new_roster.browserStorage = this.roster.browserStorage;
|
2013-11-02 12:37:38 +01:00
|
|
|
new_roster.fetch();
|
2014-06-30 19:21:16 +02:00
|
|
|
expect(new_roster.length).toEqual(num_contacts);
|
|
|
|
// Check that the roster items retrieved from browserStorage
|
2013-11-02 12:37:38 +01:00
|
|
|
// have the same attributes values as the original ones.
|
|
|
|
attrs = ['jid', 'fullname', 'subscription', 'ask'];
|
2015-10-25 18:49:35 +01:00
|
|
|
for (var i=0; i<attrs.length; i++) {
|
2013-11-02 12:37:38 +01:00
|
|
|
new_attrs = _.pluck(_.pluck(new_roster.models, 'attributes'), attrs[i]);
|
2014-08-03 23:02:25 +02:00
|
|
|
old_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]);
|
2013-11-02 12:37:38 +01:00
|
|
|
// Roster items in storage are not necessarily sorted,
|
|
|
|
// so we have to sort them here to do a proper
|
|
|
|
// comparison
|
|
|
|
expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
|
|
|
|
}
|
|
|
|
}, converse));
|
2015-03-01 13:32:53 +01:00
|
|
|
|
2015-01-05 07:32:58 +01:00
|
|
|
it("will show fullname and jid properties on tooltip", $.proxy(function () {
|
2015-10-25 18:49:35 +01:00
|
|
|
var jid, name, i;
|
2015-01-05 07:32:58 +01:00
|
|
|
for (i=0; i<mock.cur_names.length; i++) {
|
|
|
|
name = mock.cur_names[i];
|
|
|
|
jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var $dd = this.rosterview.$el.find("dd:contains('"+name+"')").children().first();
|
|
|
|
var dd_text = $dd.text();
|
|
|
|
var dd_title = $dd.attr('title');
|
|
|
|
expect(dd_text).toBe(name);
|
|
|
|
expect(dd_title).toContain(name);
|
|
|
|
expect(dd_title).toContain(jid);
|
|
|
|
}
|
|
|
|
}, converse));
|
2015-03-01 13:32:53 +01:00
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
2014-08-08 22:06:01 +02:00
|
|
|
}, converse, mock, test_utils));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2014-08-08 22:06:01 +02:00
|
|
|
describe("The 'Add Contact' widget", $.proxy(function (mock, test_utils) {
|
2013-11-02 12:37:38 +01:00
|
|
|
it("opens up an add form when you click on it", $.proxy(function () {
|
2014-03-04 14:54:36 +01:00
|
|
|
var panel = this.chatboxviews.get('controlbox').contactspanel;
|
2013-11-02 12:37:38 +01:00
|
|
|
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));
|
|
|
|
|
2014-08-08 22:06:01 +02:00
|
|
|
}, converse, mock, test_utils));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
|
|
|
describe("The Controlbox Tabs", $.proxy(function () {
|
|
|
|
beforeEach($.proxy(function () {
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeAllChatBoxes();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2014-06-21 11:32:05 +02:00
|
|
|
waits(50);
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
|
2014-03-04 14:54:36 +01:00
|
|
|
var cbview = this.chatboxviews.get('controlbox');
|
2013-11-02 12:37:38 +01:00
|
|
|
var $panels = cbview.$el.find('.controlbox-panes');
|
|
|
|
expect($panels.children().length).toBe(2);
|
|
|
|
expect($panels.children().first().attr('id')).toBe('users');
|
|
|
|
expect($panels.children().first().is(':visible')).toBe(true);
|
|
|
|
expect($panels.children().last().attr('id')).toBe('chatrooms');
|
|
|
|
expect($panels.children().last().is(':visible')).toBe(false);
|
|
|
|
}, converse));
|
|
|
|
|
2014-02-28 03:04:52 +01:00
|
|
|
describe("chatrooms panel", $.proxy(function () {
|
2013-11-02 12:37:38 +01:00
|
|
|
beforeEach($.proxy(function () {
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeAllChatBoxes();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2014-06-30 19:21:16 +02:00
|
|
|
waits(50);
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
|
2014-03-04 14:54:36 +01:00
|
|
|
var cbview = this.chatboxviews.get('controlbox');
|
2013-11-02 12:37:38 +01:00
|
|
|
var $tabs = cbview.$el.find('#controlbox-tabs');
|
|
|
|
var $panels = cbview.$el.find('.controlbox-panes');
|
|
|
|
var $contacts = $panels.children().first();
|
|
|
|
var $chatrooms = $panels.children().last();
|
|
|
|
spyOn(cbview, 'switchTab').andCallThrough();
|
|
|
|
cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2015-03-01 19:09:10 +01:00
|
|
|
$tabs.find('li').last().find('a').click(); // Clicks the chatrooms tab
|
|
|
|
expect($contacts.is(':visible')).toBe(false);
|
|
|
|
expect($chatrooms.is(':visible')).toBe(true);
|
|
|
|
expect(cbview.switchTab).toHaveBeenCalled();
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("contains a form through which a new chatroom can be created", $.proxy(function () {
|
2014-03-04 14:54:36 +01:00
|
|
|
var roomspanel = this.chatboxviews.get('controlbox').roomspanel;
|
2013-11-02 12:37:38 +01:00
|
|
|
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');
|
|
|
|
expect($input.length).toBe(1);
|
|
|
|
expect($server.length).toBe(1);
|
|
|
|
expect($('.chatroom:visible').length).toBe(0); // There shouldn't be any chatrooms open currently
|
|
|
|
spyOn(roomspanel, 'createChatRoom').andCallThrough();
|
|
|
|
roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
runs(function () {
|
|
|
|
$input.val('Lounge');
|
|
|
|
$nick.val('dummy');
|
|
|
|
$server.val('muc.localhost');
|
|
|
|
});
|
|
|
|
waits('250');
|
|
|
|
runs(function () {
|
|
|
|
roomspanel.$el.find('form').submit();
|
|
|
|
expect(roomspanel.createChatRoom).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
waits('250');
|
|
|
|
runs($.proxy(function () {
|
|
|
|
expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
|
|
|
|
}, converse));
|
|
|
|
}, converse));
|
2015-03-01 13:32:53 +01:00
|
|
|
|
2015-03-01 19:09:10 +01:00
|
|
|
it("can list rooms publically available on the server", $.proxy(function () {
|
|
|
|
var panel = this.chatboxviews.get('controlbox').roomspanel;
|
|
|
|
panel.$tabs.find('li').last().find('a').click(); // Click the chatrooms tab
|
|
|
|
panel.model.set({'muc_domain': 'muc.localhost'}); // Make sure the domain is set
|
2015-03-01 13:32:53 +01:00
|
|
|
// See: http://xmpp.org/extensions/xep-0045.html#disco-rooms
|
2015-03-01 19:09:10 +01:00
|
|
|
expect($('#available-chatrooms').children('dt').length).toBe(0);
|
|
|
|
expect($('#available-chatrooms').children('dd').length).toBe(0);
|
|
|
|
|
|
|
|
var iq = $iq({
|
|
|
|
from:'muc.localhost',
|
|
|
|
to:'dummy@localhost/pda',
|
|
|
|
type:'result'
|
|
|
|
}).c('query')
|
|
|
|
.c('item', { jid:'heath@chat.shakespeare.lit', name:'A Lonely Heath'}).up()
|
|
|
|
.c('item', { jid:'coven@chat.shakespeare.lit', name:'A Dark Cave'}).up()
|
|
|
|
.c('item', { jid:'forres@chat.shakespeare.lit', name:'The Palace'}).up()
|
|
|
|
.c('item', { jid:'inverness@chat.shakespeare.lit', name:'Macbeth's Castle'}).nodeTree;
|
|
|
|
|
|
|
|
panel.onRoomsFound(iq);
|
|
|
|
expect(panel.$('#available-chatrooms').children('dt').length).toBe(1);
|
|
|
|
expect(panel.$('#available-chatrooms').children('dt').first().text()).toBe("Rooms on muc.localhost");
|
|
|
|
expect(panel.$('#available-chatrooms').children('dd').length).toBe(4);
|
2015-03-01 13:32:53 +01:00
|
|
|
}, converse));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
2014-08-08 22:06:01 +02:00
|
|
|
}, converse, mock, test_utils));
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|