2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
2017-07-11 10:41:11 +02:00
|
|
|
define(["jquery.noconflict", "jasmine", "mock", "converse-core", "test-utils"], factory);
|
|
|
|
} (this, function ($, jasmine, mock, converse, test_utils) {
|
2016-12-20 10:30:20 +01:00
|
|
|
var _ = converse.env._;
|
|
|
|
var $pres = converse.env.$pres;
|
2017-06-05 21:42:25 +02:00
|
|
|
var $msg = converse.env.$msg;
|
2016-12-20 10:30:20 +01:00
|
|
|
var $iq = converse.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();
|
|
|
|
};
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The Control Box", function () {
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be opened by clicking a DOM element with class 'toggle-controlbox'",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
// This spec will only pass if the controlbox is not currently
|
|
|
|
// open yet.
|
|
|
|
expect($("div#controlbox").is(':visible')).toBe(false);
|
|
|
|
spyOn(_converse.controlboxtoggle, 'onClick').and.callThrough();
|
|
|
|
spyOn(_converse.controlboxtoggle, 'showControlBox').and.callThrough();
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
// Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
|
|
|
|
_converse.controlboxtoggle.delegateEvents();
|
|
|
|
$('.toggle-controlbox').click();
|
|
|
|
expect(_converse.controlboxtoggle.onClick).toHaveBeenCalled();
|
|
|
|
expect(_converse.controlboxtoggle.showControlBox).toHaveBeenCalled();
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object));
|
|
|
|
expect($("div#controlbox").is(':visible')).toBe(true);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The Status Widget", function () {
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows the user's chat status, which is online by default",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.xmppstatusview;
|
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('I am online');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to set the current user's chat status",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.xmppstatusview;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(view, 'toggleOptions').and.callThrough();
|
|
|
|
spyOn(view, 'setStatus').and.callThrough();
|
2016-12-20 10:30:20 +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
|
2017-04-05 11:01:31 +02:00
|
|
|
view.$el.find('a.choose-xmpp-status').click();
|
|
|
|
expect(view.toggleOptions).toHaveBeenCalled();
|
|
|
|
spyOn(view, 'updateStatusUI').and.callThrough();
|
|
|
|
view.initialize(); // Rebind events for spy
|
|
|
|
$(view.$el.find('.dropdown dd ul li a')[1]).click(); // Change status to "dnd"
|
|
|
|
expect(view.setStatus).toHaveBeenCalled();
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('statusChanged', 'dnd');
|
|
|
|
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');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to set a custom status message",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.xmppstatusview;
|
|
|
|
_converse.xmppstatus.save({'status': 'online'});
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(view, 'setStatusMessage').and.callThrough();
|
|
|
|
spyOn(view, 'renderStatusChangeForm').and.callThrough();
|
2016-12-20 10:30:20 +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();
|
|
|
|
var msg = 'I am happy';
|
2017-05-08 21:06:33 +02:00
|
|
|
view.$el.find('input.custom-xmpp-status').val(msg);
|
|
|
|
view.$el.submit();
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(view.setStatusMessage).toHaveBeenCalled();
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('statusMessageChanged', msg);
|
|
|
|
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);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The Contacts Roster", function () {
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The live filter", function () {
|
2016-03-13 18:40:36 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will only appear when roster contacts flow over the visible area",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var $filter = _converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
var names = mock.cur_names;
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
_converse.rosterview.update(); // XXX: Will normally called as event handler
|
|
|
|
expect($filter.length).toBe(1);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return !$filter.is(':visible');
|
|
|
|
}).then(function () {
|
2016-04-02 13:30:54 +02:00
|
|
|
for (var i=0; i<names.length; i++) {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.create({
|
2016-04-02 13:30:54 +02:00
|
|
|
ask: null,
|
|
|
|
fullname: names[i],
|
|
|
|
jid: names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
requesting: 'false',
|
|
|
|
subscription: 'both'
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.update(); // XXX: Will normally called as event handler
|
2016-04-02 13:30:54 +02:00
|
|
|
}
|
2017-04-06 23:21:52 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
if (_converse.rosterview.$roster.hasScrollBar()) {
|
|
|
|
return $filter.is(':visible');
|
|
|
|
} else {
|
|
|
|
return !$filter.is(':visible');
|
|
|
|
}
|
2017-07-11 10:41:11 +02:00
|
|
|
}).then(function () {
|
|
|
|
done();
|
|
|
|
});
|
2016-04-02 13:30:54 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-08-02 15:05:27 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to filter the contacts shown",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2014-10-27 23:06:11 +01:00
|
|
|
var $filter;
|
|
|
|
var $roster;
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.roster_groups = true;
|
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.createGroupedContacts(_converse);
|
|
|
|
$filter = _converse.rosterview.$('.roster-filter');
|
|
|
|
$roster = _converse.rosterview.$roster;
|
|
|
|
_converse.rosterview.filter_view.delegateEvents();
|
|
|
|
|
|
|
|
var promise = test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 15;
|
|
|
|
}, 500)
|
|
|
|
.then(function (contacts) {
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
|
|
|
$filter.val("candice");
|
|
|
|
$filter.trigger('keydown');
|
2017-04-05 11:01:31 +02:00
|
|
|
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 1;
|
|
|
|
}, 500);
|
|
|
|
}).then(function (contacts) {
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($roster.find('dd:visible').eq(0).text().trim()).toBe('Candice van der Knijff');
|
|
|
|
expect($roster.find('dt:visible').length).toBe(1);
|
2017-04-21 17:52:54 +02:00
|
|
|
expect(_.trim($roster.find('dt:visible').eq(0).text())).toBe('colleagues');
|
2016-12-20 10:30:20 +01:00
|
|
|
$filter = _converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
$filter.val("an");
|
|
|
|
$filter.trigger('keydown');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 5;
|
|
|
|
}, 500)
|
|
|
|
}).then(function (contacts) {
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(4);
|
2016-12-20 10:30:20 +01:00
|
|
|
$filter = _converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
$filter.val("xxx");
|
|
|
|
$filter.trigger('keydown');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 0;
|
|
|
|
}, 500)
|
|
|
|
}).then(function () {
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(0);
|
2016-12-20 10:30:20 +01: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');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 15;
|
|
|
|
}, 500)
|
|
|
|
}).then(function () {
|
2014-08-31 21:20:28 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.roster_groups = false;
|
|
|
|
done();
|
2014-08-18 20:37:38 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-08-02 15:05:27 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to filter the groups shown",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2014-10-27 23:06:11 +01:00
|
|
|
var $filter;
|
|
|
|
var $roster;
|
|
|
|
var $type;
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.roster_groups = true;
|
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.createGroupedContacts(_converse);
|
|
|
|
_converse.rosterview.filter_view.delegateEvents();
|
|
|
|
$filter = _converse.rosterview.$('.roster-filter');
|
|
|
|
$roster = _converse.rosterview.$roster;
|
|
|
|
$type = _converse.rosterview.$('.filter-type');
|
|
|
|
$type.val('groups');
|
|
|
|
var promise = test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 15;
|
|
|
|
}, 500);
|
|
|
|
promise.then(function () {
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
|
|
|
$filter.val("colleagues");
|
|
|
|
$filter.trigger('keydown');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dt:visible').length === 1;
|
|
|
|
}, 500);
|
|
|
|
}).then(function () {
|
2017-04-21 17:52:54 +02:00
|
|
|
expect(_.trim($roster.find('dt:visible').eq(0).text())).toBe('colleagues');
|
2017-04-05 11:01:31 +02:00
|
|
|
expect($roster.find('dd:visible').length).toBe(3);
|
2014-08-18 20:37:38 +02:00
|
|
|
// Check that all contacts under the group are shown
|
|
|
|
expect($roster.find('dt:visible').nextUntil('dt', 'dd:hidden').length).toBe(0);
|
2016-12-20 10:30:20 +01:00
|
|
|
$filter = _converse.rosterview.$('.roster-filter');
|
2017-04-05 11:01:31 +02:00
|
|
|
$filter.val("xxx").trigger('keydown');
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 0;
|
|
|
|
}, 700);
|
|
|
|
}).then(function () {
|
2014-08-18 20:37:38 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(0);
|
2016-12-20 10:30:20 +01: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');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 15;
|
|
|
|
}, 500);
|
|
|
|
}).then(function () {
|
2014-08-31 21:20:28 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2014-08-18 20:37:38 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-08-02 15:05:27 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("has a button with which its contents can be cleared",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster_groups = true;
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createGroupedContacts(_converse);
|
|
|
|
var $filter = _converse.rosterview.$('.roster-filter');
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.rosterview.filter_view.delegateEvents();
|
|
|
|
$filter.val("xxx");
|
|
|
|
$filter.trigger('keydown');
|
|
|
|
expect($filter.hasClass("x")).toBeFalsy();
|
|
|
|
$filter = _converse.rosterview.$('.roster-filter');
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$('.roster-filter').hasClass("x");
|
|
|
|
}, 900).then(function () {
|
|
|
|
var $filter = _converse.rosterview.$('.roster-filter');
|
2014-08-18 20:37:38 +02:00
|
|
|
$filter.addClass("onX").click();
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return !_converse.rosterview.$('.roster-filter').hasClass("x");
|
|
|
|
}, 900)
|
|
|
|
}).then(function () {
|
|
|
|
expect(document.querySelector('.roster-filter').value).toBe("");
|
|
|
|
done();
|
2014-08-18 20:37:38 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-07-18 10:41:06 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to filter contacts by their chat state",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-07-18 10:41:06 +02:00
|
|
|
var $filter;
|
|
|
|
var $roster;
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster_groups = true;
|
|
|
|
test_utils.createGroupedContacts(_converse);
|
2016-07-18 10:41:06 +02:00
|
|
|
var jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'online');
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox();
|
2016-07-18 10:41:06 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.rosterview.filter_view.delegateEvents();
|
|
|
|
var $type = _converse.rosterview.$('.filter-type');
|
|
|
|
$type.val('state').trigger('change');
|
|
|
|
$filter = _converse.rosterview.$('.state-type');
|
|
|
|
$roster = _converse.rosterview.$roster;
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 15;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-07-18 10:41:06 +02:00
|
|
|
expect($roster.find('dt:visible').length).toBe(5);
|
|
|
|
$filter.val("online");
|
|
|
|
$filter.trigger('change');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return $roster.find('dd:visible').length === 1;
|
|
|
|
}, 500)
|
|
|
|
}).then(function () {
|
2016-07-18 10:41:06 +02:00
|
|
|
expect($roster.find('dd:visible').eq(0).text().trim()).toBe('Rinse Sommer');
|
|
|
|
expect($roster.find('dt:visible').length).toBe(1);
|
2016-12-20 10:30:20 +01:00
|
|
|
var $type = _converse.rosterview.$('.filter-type');
|
2016-07-18 10:41:06 +02:00
|
|
|
$type.val('contacts').trigger('change');
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-07-18 10:41:06 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2014-08-18 20:37:38 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("A Roster Group", function () {
|
2014-07-31 18:20:20 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to organize existing contacts",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.roster_groups = true;
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
_converse.rosterview.render();
|
|
|
|
test_utils.createContacts(_converse, 'pending');
|
|
|
|
test_utils.createContacts(_converse, 'requesting');
|
|
|
|
test_utils.createGroupedContacts(_converse);
|
|
|
|
// Check that the groups appear alphabetically and that
|
|
|
|
// requesting and pending contacts are last.
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
var group_titles = $.map(_converse.rosterview.$el.find('dt'), function (o) { return $(o).text().trim(); });
|
2014-10-27 23:06:11 +01:00
|
|
|
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
|
2016-11-03 11:01:09 +01:00
|
|
|
_.each(_.keys(mock.groups), function (name) {
|
2016-12-20 10:30:20 +01:00
|
|
|
var $contacts = _converse.rosterview.$('dt.roster-group[data-group="'+name+'"]').nextUntil('dt', 'dd');
|
2014-10-27 23:06:11 +01:00
|
|
|
var names = $.map($contacts, function (o) { return $(o).text().trim(); });
|
|
|
|
expect(names).toEqual(_.clone(names).sort());
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-07-31 21:50:34 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can share contacts with other roster groups",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster_groups = true;
|
2014-08-01 21:36:20 +02:00
|
|
|
var groups = ['colleagues', 'friends'];
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
_converse.rosterview.render();
|
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
|
|
|
_converse.roster.create({
|
|
|
|
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
groups: groups,
|
|
|
|
fullname: mock.cur_names[i]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
// Check that usernames appear alphabetically per group
|
2016-11-03 11:01:09 +01:00
|
|
|
_.each(groups, function (name) {
|
2016-12-20 10:30:20 +01:00
|
|
|
var $contacts = _converse.rosterview.$('dt.roster-group[data-group="'+name+'"]').nextUntil('dt', 'dd');
|
2014-10-27 23:06:11 +01:00
|
|
|
var names = $.map($contacts, function (o) { return $(o).text().trim(); });
|
|
|
|
expect(names).toEqual(_.clone(names).sort());
|
|
|
|
expect(names.length).toEqual(mock.cur_names.length);
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-07-31 18:20:20 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("remembers whether it is closed or opened",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster_groups = true;
|
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
|
|
|
|
};
|
2016-11-03 11:01:09 +01:00
|
|
|
_.each(_.keys(groups), function (name) {
|
2014-08-03 20:48:49 +02:00
|
|
|
j = i;
|
|
|
|
for (i=j; i<j+groups[name]; i++) {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.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
|
|
|
});
|
|
|
|
}
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.rosterview.get('colleagues');
|
2014-08-03 20:48:49 +02:00
|
|
|
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');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2014-07-31 18:20:20 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("Pending Contacts", function () {
|
2014-07-25 09:58:42 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
function _addContacts (_converse) {
|
2014-07-25 09:58:42 +02:00
|
|
|
// Must be initialized, so that render is called and documentFragment set up.
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'pending').openControlBox().openContactsPanel(_converse);
|
2014-08-03 23:07:48 +02:00
|
|
|
}
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be collapsed under their own header",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
checkHeaderToggling.apply(_converse, [_converse.rosterview.get('Pending contacts').$el]);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-07-04 20:37:37 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be added to the roster",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
test_utils.openControlBox();
|
|
|
|
_converse.roster.create({
|
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("are shown in the roster when show_only_online_users",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.show_only_online_users = true;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.$el.is(':visible')).toEqual(true);
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
expect(_converse.rosterview.$el.find('dd:visible').length).toBe(3);
|
|
|
|
expect(_converse.rosterview.$el.find('dt:visible').length).toBe(1);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-07-18 10:41:06 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-12-11 01:32:59 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("are shown in the roster when hide_offline_users",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.hide_offline_users = true;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd:visible').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.rosterview.$el.is(':visible')).toBe(true);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.$el.find('dd:visible').length).toBe(3);
|
|
|
|
expect(_converse.rosterview.$el.find('dt:visible').length).toBe(1);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-12-11 01:32:59 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be removed by the user",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
var name = mock.pend_names[0];
|
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var contact = _converse.roster.get(jid);
|
|
|
|
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(contact, 'unauthorize').and.callFake(function () { return contact; });
|
|
|
|
spyOn(contact, 'removeFromRoster');
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
|
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')").length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().siblings('.remove-xmpp-contact').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')").length === 0
|
|
|
|
}, 500)
|
|
|
|
}).then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
2015-04-06 11:10:05 +02:00
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("do not have a header if there aren't any",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
var name = mock.pend_names[0];
|
|
|
|
_converse.roster.create({
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: name
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
|
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.get('Pending contacts').$el.is(':visible');
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().siblings('.remove-xmpp-contact').click();
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
|
|
|
expect(_converse.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(false);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-08-01 20:09:32 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("is shown when a new private message is received",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_addContacts(_converse);
|
2014-08-01 20:09:32 +02:00
|
|
|
var name;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(window, 'confirm').and.returnValue(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];
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().siblings('.remove-xmpp-contact').click();
|
2014-07-04 20:37:37 +02:00
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be added to the roster and they will be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2014-08-04 18:00:30 +02:00
|
|
|
var i, t;
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2013-11-02 12:37:38 +01:00
|
|
|
for (i=0; i<mock.pend_names.length; i++) {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.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
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.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
|
2017-04-21 12:11:33 +02:00
|
|
|
t = _.reduce(_converse.rosterview.get('Pending contacts').$el.siblings('dd.pending-xmpp-contact').find('span'), function (result, value) {
|
|
|
|
return result + _.trim(value.textContent);
|
|
|
|
}, '');
|
2014-07-24 20:48:52 +02:00
|
|
|
expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join(''));
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2014-07-29 19:53:57 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("Existing Contacts", function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
var _addContacts = function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current').openControlBox().openContactsPanel(_converse);
|
2014-07-29 19:53:57 +02:00
|
|
|
};
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be collapsed under their own header",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd:visible').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
checkHeaderToggling.apply(_converse, [_converse.rosterview.$el.find('dt.roster-group')]);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will be hidden when appearing under a collapsed group",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-02-17 10:45:34 +01:00
|
|
|
_converse.roster_groups = false;
|
2016-12-20 10:30:20 +01:00
|
|
|
_addContacts(_converse);
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd:visible').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
_converse.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 = _converse.rosterview.get('My contacts').get(jid);
|
|
|
|
expect(view.$el.is(':visible')).toBe(false);
|
|
|
|
done();
|
2014-08-04 18:48:48 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-08-04 18:48:48 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be added to the roster and they will be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
for (var i=0; i<mock.cur_names.length; i++) {
|
|
|
|
_converse.roster.create({
|
|
|
|
jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
fullname: mock.cur_names[i]
|
|
|
|
});
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
}
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd').length;
|
|
|
|
}).then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2017-04-21 12:11:33 +02:00
|
|
|
var t = _.reduce(_converse.rosterview.$('dt.roster-group').siblings('dd.current-xmpp-contact.offline').find('a.open-chat'), function (result, value) {
|
|
|
|
return result + _.trim(value.textContent);
|
|
|
|
}, '');
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be removed by the user",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dd').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var name = mock.cur_names[0];
|
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
var contact = _converse.roster.get(jid);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
2015-04-06 11:10:05 +02:00
|
|
|
spyOn(contact, 'removeFromRoster');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
|
2015-04-06 11:10:05 +02:00
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().find('.remove-xmpp-contact').click();
|
2014-10-27 23:06:11 +01:00
|
|
|
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
2015-04-06 11:10:05 +02:00
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.$el.find(".open-chat:contains('"+name+"')").length).toEqual(0);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-08-01 20:09:32 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("do not have a header if there aren't any",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2014-08-01 20:09:32 +02:00
|
|
|
var name = mock.cur_names[0];
|
2016-11-03 11:01:09 +01:00
|
|
|
var contact;
|
2017-04-05 11:01:31 +02:00
|
|
|
contact = _converse.roster.create({
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
fullname: name
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
2015-04-06 11:10:05 +02:00
|
|
|
spyOn(contact, 'removeFromRoster');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
|
2015-04-06 11:10:05 +02:00
|
|
|
if (typeof callback === "function") { return callback(); }
|
|
|
|
});
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.$el.find('dt.roster-group').css('display')).toEqual('block');
|
|
|
|
_converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().find('.remove-xmpp-contact').click();
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
2015-04-06 11:10:05 +02:00
|
|
|
expect(contact.removeFromRoster).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none');
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-08-01 20:09:32 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can change their status to online and be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var jid, t;
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2017-04-21 12:11:33 +02:00
|
|
|
var $roster = _converse.rosterview.$el;
|
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';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'online');
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2017-04-21 12:11:33 +02:00
|
|
|
t = _.reduce($roster.find('dt.roster-group').siblings('dd.current-xmpp-contact.online').find('a.open-chat'), function (result, value) {
|
|
|
|
return result + _.trim(value.textContent);
|
|
|
|
}, '');
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can change their status to busy and be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var jid, t;
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2017-04-21 12:11:33 +02:00
|
|
|
var $roster = _converse.rosterview.$el;
|
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';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'dnd');
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2017-04-21 12:11:33 +02:00
|
|
|
t = _.reduce($roster.find('dt.roster-group').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat'), function (result, value) {
|
|
|
|
return result + _.trim(value.textContent);
|
|
|
|
}, '');
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can change their status to away and be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var jid, t;
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2017-04-21 12:11:33 +02:00
|
|
|
var $roster = _converse.rosterview.$el;
|
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';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'away');
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2017-04-21 12:11:33 +02:00
|
|
|
t = _.reduce($roster.find('dt.roster-group').siblings('dd.current-xmpp-contact.away').find('a.open-chat'), function (result, value) {
|
|
|
|
return result + _.trim(value.textContent);
|
|
|
|
}, '');
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can change their status to xa and be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var jid, t;
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2017-04-21 12:11:33 +02:00
|
|
|
var $roster = _converse.rosterview.$el;
|
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';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'xa');
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2017-04-21 12:11:33 +02:00
|
|
|
t = _.reduce($roster.find('dt.roster-group').siblings('dd.current-xmpp-contact.xa').find('a.open-chat'), function (result, value) {
|
|
|
|
return result + _.trim(value.textContent);
|
|
|
|
}, '');
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can change their status to unavailable and be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
var jid, t;
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
2017-04-21 12:11:33 +02:00
|
|
|
var $roster = _converse.rosterview.$el;
|
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';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'unavailable');
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2017-04-21 12:11:33 +02:00
|
|
|
t = _.reduce($roster.find('dt.roster-group').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat'), function (result, value) {
|
|
|
|
return result + _.trim(value.textContent);
|
|
|
|
}, '');
|
|
|
|
expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("are ordered according to status: online, busy, away, xa, unavailable, offline",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
_addContacts(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(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';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'online');
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=3; i<6; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'dnd');
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=6; i<9; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'away');
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=9; i<12; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'xa');
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
|
|
|
for (i=12; i<15; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.get(jid).set('chat_status', 'unavailable');
|
2014-10-27 23:06:11 +01:00
|
|
|
}
|
2014-06-30 20:26:45 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var contacts = _converse.rosterview.$el.find('dd.current-xmpp-contact');
|
2014-10-27 23:06:11 +01:00
|
|
|
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
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2014-07-04 20:37:37 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Requesting Contacts", function () {
|
2014-07-04 20:37:37 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be added to the roster and they will be sorted alphabetically",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2014-07-19 15:26:30 +02:00
|
|
|
var i, children;
|
|
|
|
var names = [];
|
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, ''));
|
|
|
|
}
|
|
|
|
};
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
spyOn(_converse.controlboxtoggle, 'showControlBox').and.callThrough();
|
|
|
|
for (i=0; i<mock.req_names.length; i++) {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.create({
|
2017-04-05 11:01:31 +02:00
|
|
|
jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
2014-10-27 23:06:11 +01:00
|
|
|
subscription: 'none',
|
|
|
|
ask: null,
|
|
|
|
requesting: true,
|
2017-04-05 11:01:31 +02:00
|
|
|
fullname: mock.req_names[i]
|
2014-10-27 23:06:11 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
}
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
// Check that they are sorted alphabetically
|
|
|
|
children = _converse.rosterview.get('Contact requests').$el.siblings('dd.requesting-xmpp-contact').find('span');
|
|
|
|
names = [];
|
|
|
|
children.each(addName);
|
|
|
|
expect(names.join('')).toEqual(mock.req_names.slice(0,mock.req_names.length+1).sort().join(''));
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-04-05 11:01:31 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("do not have a header if there aren't any",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
var name = mock.req_names[0];
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
_converse.roster.create({
|
|
|
|
jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: null,
|
|
|
|
requesting: true,
|
|
|
|
fullname: name
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.get('Contact requests').$el.is(':visible')).toEqual(true);
|
|
|
|
_converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().siblings('.request-actions')
|
2014-10-27 23:06:11 +01:00
|
|
|
.find('.decline-xmpp-request').click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.rosterview.get('Contact requests').$el.is(':visible')).toEqual(false);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be collapsed under their own header",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.createContacts(_converse, 'requesting').openControlBox();
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
checkHeaderToggling.apply(_converse, [_converse.rosterview.get('Contact requests').$el]);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can have their requests accepted by the user",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.createContacts(_converse, 'requesting').openControlBox();
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
// TODO: Testing can be more thorough here, the user is
|
|
|
|
// actually not accepted/authorized because of
|
|
|
|
// mock_connection.
|
|
|
|
var name = mock.req_names.sort()[0];
|
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
var contact = _converse.roster.get(jid);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.roster, 'sendContactAddIQ').and.callFake(function (jid, fullname, groups, callback) {
|
2016-11-03 11:01:09 +01:00
|
|
|
callback();
|
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(contact, 'authorize').and.callFake(function () { return contact; });
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().siblings('.request-actions')
|
2016-11-03 11:01:09 +01:00
|
|
|
.find('.accept-xmpp-request').click();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
|
2016-11-03 11:01:09 +01:00
|
|
|
expect(contact.authorize).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can have their requests denied by the user",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.createContacts(_converse, 'requesting').openControlBox();
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
2014-10-27 23:06:11 +01:00
|
|
|
var name = mock.req_names.sort()[1];
|
2015-04-06 12:26:08 +02:00
|
|
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
var contact = _converse.roster.get(jid);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
spyOn(contact, 'unauthorize').and.callFake(function () { return contact; });
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
|
2017-02-02 16:37:41 +01:00
|
|
|
.parent().siblings('.request-actions')
|
2014-10-27 23:06:11 +01:00
|
|
|
.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
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.roster.length).toEqual(mock.req_names.length-1);
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2014-10-24 18:58:42 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("are persisted even if other contacts' change their presence ", mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
|
|
|
|
|
2014-10-24 18:58:42 +02:00
|
|
|
/* This is a regression test.
|
2016-12-20 10:30:20 +01:00
|
|
|
* https://github.com/jcbrand/_converse.js/issues/262
|
2014-10-24 18:58:42 +02:00
|
|
|
*/
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.roster.pluck('jid').length).toBe(0);
|
2014-10-24 18:58:42 +02:00
|
|
|
|
|
|
|
var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
expect(_converse.roster.pluck('jid').length).toBe(1);
|
|
|
|
expect(_.includes(_converse.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
2014-10-24 18:58:42 +02:00
|
|
|
|
|
|
|
// Taken from the spec
|
|
|
|
// http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
|
|
|
|
stanza = $iq({
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2014-10-24 18:58:42 +02:00
|
|
|
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');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.roster.onReceivedFromServer(stanza.tree());
|
|
|
|
expect(_.includes(_converse.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("All Contacts", function () {
|
2014-07-04 20:37:37 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("are saved to, and can be retrieved from browserStorage",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-10-24 21:45:48 +02:00
|
|
|
var new_attrs, old_attrs, attrs;
|
2016-12-20 10:30:20 +01:00
|
|
|
var num_contacts = _converse.roster.length;
|
|
|
|
var new_roster = new _converse.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);
|
2016-12-20 10:30:20 +01:00
|
|
|
new_roster.browserStorage = _converse.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++) {
|
2017-01-26 15:49:02 +01:00
|
|
|
new_attrs = _.map(_.map(new_roster.models, 'attributes'), attrs[i]);
|
2016-12-20 10:30:20 +01:00
|
|
|
old_attrs = _.map(_.map(_converse.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);
|
|
|
|
}
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will show fullname and jid properties on tooltip",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
var jid, name, i;
|
|
|
|
for (i=0; i<mock.cur_names.length; i++) {
|
|
|
|
name = mock.cur_names[i];
|
|
|
|
jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
var $dd = _converse.rosterview.$el.find("dd:contains('"+name+"')").children().first();
|
2016-11-03 11:01:09 +01:00
|
|
|
var dd_text = $dd.text();
|
|
|
|
var dd_title = $dd.attr('title');
|
2017-04-21 12:11:33 +02:00
|
|
|
expect(_.trim(dd_text)).toBe(name);
|
2016-11-03 11:01:09 +01:00
|
|
|
expect(dd_title).toContain(name);
|
|
|
|
expect(dd_title).toContain(jid);
|
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The 'Add Contact' widget", function () {
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("opens up an add form when you click on it",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(panel, 'toggleContactForm').and.callThrough();
|
2013-11-02 12:37:38 +01:00
|
|
|
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();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-03-08 15:33:00 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to add contact and it checks for case-sensivity",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-03-08 15:33:00 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
test_utils.openControlBox();
|
|
|
|
// Adding two contacts one with Capital initials and one with small initials of same JID (Case sensitive check)
|
|
|
|
_converse.roster.create({
|
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
2017-03-08 15:33:00 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.roster.create({
|
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.') + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
|
|
|
});
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.rosterview.$el.find('dt').length;
|
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
2017-03-08 15:33:00 +01:00
|
|
|
// Checking that only one entry is created because both JID is same (Case sensitive check)
|
|
|
|
expect(_converse.rosterview.$el.find('dd:visible').length).toBe(1);
|
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2017-03-08 15:33:00 +01:00
|
|
|
});
|
|
|
|
}));
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("The Controlbox Tabs", function () {
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("contains two tabs, 'Contacts' and 'ChatRooms'",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
var cbview = _converse.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);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("remembers which tab was open last",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 15:10:08 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
2016-11-03 15:10:08 +01:00
|
|
|
var $tabs = cbview.$el.find('#controlbox-tabs');
|
|
|
|
expect(cbview.model.get('active-panel')).toBe('users');
|
|
|
|
$tabs.find('li').last().find('a').click();
|
|
|
|
expect(cbview.model.get('active-panel')).toBe('chatrooms');
|
|
|
|
$tabs.find('li').first().find('a').click();
|
|
|
|
expect(cbview.model.get('active-panel')).toBe('users');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 15:10:08 +01:00
|
|
|
}));
|
|
|
|
|
2017-06-05 21:42:25 +02:00
|
|
|
describe("The \"Contacts\" Panel", function () {
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows the number of unread mentions received",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-06-05 21:42:25 +02:00
|
|
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
|
|
|
test_utils.openContactsPanel(_converse);
|
2017-02-27 22:09:17 +01:00
|
|
|
|
2017-06-07 00:55:25 +02:00
|
|
|
var contacts_panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
|
|
|
expect(_.isNull(contacts_panel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
|
|
|
|
2017-06-05 21:42:25 +02:00
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('hello').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(contacts_panel.tab_el.querySelector('.msgs-indicator').textContent).toBe('1');
|
|
|
|
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('hello again').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(contacts_panel.tab_el.querySelector('.msgs-indicator').textContent).toBe('2');
|
|
|
|
|
2017-06-07 00:55:25 +02:00
|
|
|
var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
|
|
|
|
expect(_.isNull(roomspanel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
|
|
|
|
2017-06-05 21:42:25 +02:00
|
|
|
chatview.model.set({'minimized': false});
|
|
|
|
expect(_.includes(contacts_panel.tab_el.firstChild.classList, 'unread-msgs')).toBeFalsy();
|
2017-06-07 00:55:25 +02:00
|
|
|
expect(_.isNull(contacts_panel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|