2017-04-05 11:01:31 +02:00
|
|
|
|
/*global waitUntilPromise */
|
|
|
|
|
|
2016-06-27 23:50:38 +02:00
|
|
|
|
(function (root, factory) {
|
|
|
|
|
define([
|
2017-06-19 11:08:57 +02:00
|
|
|
|
"jasmine",
|
2016-06-27 23:50:38 +02:00
|
|
|
|
"jquery",
|
2017-02-14 15:08:39 +01:00
|
|
|
|
"converse-core",
|
2016-06-27 23:50:38 +02:00
|
|
|
|
"utils",
|
|
|
|
|
"mock",
|
2017-04-05 11:01:31 +02:00
|
|
|
|
"test-utils"
|
2016-06-27 23:50:38 +02:00
|
|
|
|
], factory);
|
2017-06-19 11:08:57 +02:00
|
|
|
|
} (this, function (jasmine, $, converse, utils, mock, test_utils) {
|
2016-06-27 23:50:38 +02:00
|
|
|
|
"use strict";
|
2016-12-20 10:30:20 +01:00
|
|
|
|
var $iq = converse.env.$iq,
|
2018-02-07 21:59:45 +01:00
|
|
|
|
$msg = converse.env.$msg,
|
2018-02-07 17:30:44 +01:00
|
|
|
|
Backbone = converse.env.Backbone,
|
2016-12-20 10:30:20 +01:00
|
|
|
|
Strophe = converse.env.Strophe,
|
2018-01-04 22:51:42 +01:00
|
|
|
|
_ = converse.env._,
|
|
|
|
|
u = converse.env.utils;
|
2016-06-27 23:50:38 +02:00
|
|
|
|
|
|
|
|
|
describe("A chat room", function () {
|
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
|
it("can be bookmarked", mock.initConverseWithPromises(
|
|
|
|
|
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
|
2018-02-07 17:30:44 +01:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2018-02-08 09:49:05 +01:00
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
|
sent_stanza = iq;
|
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
|
});
|
|
|
|
|
spyOn(_converse.connection, 'getUniqueId').and.callThrough();
|
2018-02-07 17:30:44 +01:00
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
|
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
|
|
|
|
|
var jid = 'theplay@conference.shakespeare.lit';
|
|
|
|
|
var view = _converse.chatboxviews.get(jid);
|
2018-02-08 09:49:05 +01:00
|
|
|
|
spyOn(view, 'renderBookmarkForm').and.callThrough();
|
|
|
|
|
spyOn(view, 'closeForm').and.callThrough();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
|
2018-02-07 17:30:44 +01:00
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
|
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
|
|
|
|
|
}, 300).then(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
var $bookmark = $(view.el).find('.toggle-bookmark');
|
2018-02-08 09:49:05 +01:00
|
|
|
|
$bookmark[0].click();
|
|
|
|
|
expect(view.renderBookmarkForm).toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
view.el.querySelector('.button-cancel').click();
|
|
|
|
|
expect(view.closeForm).toHaveBeenCalled();
|
|
|
|
|
expect($bookmark.hasClass('on-button'), false);
|
|
|
|
|
|
|
|
|
|
$bookmark[0].click();
|
|
|
|
|
expect(view.renderBookmarkForm).toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
/* Client uploads data:
|
|
|
|
|
* --------------------
|
|
|
|
|
* <iq from='juliet@capulet.lit/balcony' type='set' id='pip1'>
|
|
|
|
|
* <pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
|
|
|
* <publish node='storage:bookmarks'>
|
|
|
|
|
* <item id='current'>
|
|
|
|
|
* <storage xmlns='storage:bookmarks'>
|
|
|
|
|
* <conference name='The Play's the Thing'
|
|
|
|
|
* autojoin='true'
|
|
|
|
|
* jid='theplay@conference.shakespeare.lit'>
|
|
|
|
|
* <nick>JC</nick>
|
|
|
|
|
* </conference>
|
|
|
|
|
* </storage>
|
|
|
|
|
* </item>
|
|
|
|
|
* </publish>
|
|
|
|
|
* <publish-options>
|
|
|
|
|
* <x xmlns='jabber:x:data' type='submit'>
|
|
|
|
|
* <field var='FORM_TYPE' type='hidden'>
|
|
|
|
|
* <value>http://jabber.org/protocol/pubsub#publish-options</value>
|
|
|
|
|
* </field>
|
|
|
|
|
* <field var='pubsub#persist_items'>
|
|
|
|
|
* <value>true</value>
|
|
|
|
|
* </field>
|
|
|
|
|
* <field var='pubsub#access_model'>
|
|
|
|
|
* <value>whitelist</value>
|
|
|
|
|
* </field>
|
|
|
|
|
* </x>
|
|
|
|
|
* </publish-options>
|
|
|
|
|
* </pubsub>
|
|
|
|
|
* </iq>
|
|
|
|
|
*/
|
|
|
|
|
expect(view.model.get('bookmarked')).toBeFalsy();
|
|
|
|
|
var $form = $(view.el).find('.chatroom-form');
|
|
|
|
|
$form.find('input[name="name"]').val('Play's the Thing');
|
|
|
|
|
$form.find('input[name="autojoin"]').prop('checked', true);
|
|
|
|
|
$form.find('input[name="nick"]').val('JC');
|
2018-03-16 12:49:39 +01:00
|
|
|
|
view.el.querySelector('.btn-primary').click();
|
2018-02-07 17:30:44 +01:00
|
|
|
|
|
|
|
|
|
expect(view.model.get('bookmarked')).toBeTruthy();
|
2018-02-08 09:49:05 +01:00
|
|
|
|
expect($bookmark.hasClass('on-button'), true);
|
2018-02-07 17:30:44 +01:00
|
|
|
|
|
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
|
"<iq type='set' from='dummy@localhost/resource' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
|
"<pubsub xmlns='http://jabber.org/protocol/pubsub'>"+
|
|
|
|
|
"<publish node='storage:bookmarks'>"+
|
|
|
|
|
"<item id='current'>"+
|
2018-02-08 09:49:05 +01:00
|
|
|
|
"<storage xmlns='storage:bookmarks'>"+
|
|
|
|
|
"<conference name='Play&apos;s the Thing' autojoin='true' jid='theplay@conference.shakespeare.lit'>"+
|
|
|
|
|
"<nick>JC</nick>"+
|
|
|
|
|
"</conference>"+
|
|
|
|
|
"</storage>"+
|
2018-02-07 17:30:44 +01:00
|
|
|
|
"</item>"+
|
|
|
|
|
"</publish>"+
|
|
|
|
|
"<publish-options>"+
|
|
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
|
|
|
|
"<value>http://jabber.org/protocol/pubsub#publish-options</value>"+
|
|
|
|
|
"</field>"+
|
|
|
|
|
"<field var='pubsub#persist_items'>"+
|
|
|
|
|
"<value>true</value>"+
|
|
|
|
|
"</field>"+
|
|
|
|
|
"<field var='pubsub#access_model'>"+
|
|
|
|
|
"<value>whitelist</value>"+
|
|
|
|
|
"</field>"+
|
|
|
|
|
"</x>"+
|
|
|
|
|
"</publish-options>"+
|
|
|
|
|
"</pubsub>"+
|
|
|
|
|
"</iq>"
|
|
|
|
|
);
|
2018-02-08 09:49:05 +01:00
|
|
|
|
|
|
|
|
|
/* Server acknowledges successful storage
|
|
|
|
|
*
|
|
|
|
|
* <iq to='juliet@capulet.lit/balcony' type='result' id='pip1'/>
|
|
|
|
|
*/
|
|
|
|
|
var stanza = $iq({
|
|
|
|
|
'to':_converse.connection.jid,
|
|
|
|
|
'type':'result',
|
|
|
|
|
'id':IQ_id
|
|
|
|
|
});
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
// We ignore this IQ stanza... (unless it's an error stanza), so
|
|
|
|
|
// nothing to test for here.
|
2018-02-07 17:30:44 +01:00
|
|
|
|
done();
|
2016-09-22 13:02:16 +02:00
|
|
|
|
});
|
2018-02-08 09:49:05 +01:00
|
|
|
|
});
|
|
|
|
|
}));
|
2016-09-23 09:41:55 +02:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverseWithPromises(
|
|
|
|
|
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
|
2016-09-23 09:41:55 +02:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
|
|
|
|
var jid = 'lounge@localhost';
|
|
|
|
|
_converse.bookmarks.create({
|
2016-09-23 09:41:55 +02:00
|
|
|
|
'jid': jid,
|
|
|
|
|
'autojoin': false,
|
2018-02-08 09:49:05 +01:00
|
|
|
|
'name': 'The Lounge',
|
|
|
|
|
'nick': ' Othello'
|
2016-09-23 09:41:55 +02:00
|
|
|
|
});
|
2018-02-08 09:49:05 +01:00
|
|
|
|
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeTruthy();
|
2016-09-23 09:41:55 +02:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
jid = 'theplay@conference.shakespeare.lit';
|
2016-12-20 10:30:20 +01:00
|
|
|
|
_converse.bookmarks.create({
|
2016-09-23 09:41:55 +02:00
|
|
|
|
'jid': jid,
|
|
|
|
|
'autojoin': true,
|
2018-02-08 09:49:05 +01:00
|
|
|
|
'name': 'The Play',
|
|
|
|
|
'nick': ' Othello'
|
|
|
|
|
});
|
|
|
|
|
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeFalsy();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe("when bookmarked", function () {
|
|
|
|
|
|
|
|
|
|
it("displays that it's bookmarked through its bookmark icon", mock.initConverseWithPromises(
|
|
|
|
|
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
|
|
|
|
|
|
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
|
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
|
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
|
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
|
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
|
|
|
|
|
}, 300).then(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
var bookmark_icon = view.el.querySelector('.toggle-bookmark');
|
2018-02-08 09:49:05 +01:00
|
|
|
|
expect(_.includes(bookmark_icon.classList, 'button-on')).toBeFalsy();
|
|
|
|
|
view.model.set('bookmarked', true);
|
|
|
|
|
expect(_.includes(bookmark_icon.classList, 'button-on')).toBeTruthy();
|
|
|
|
|
view.model.set('bookmarked', false);
|
|
|
|
|
expect(_.includes(bookmark_icon.classList, 'button-on')).toBeFalsy();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
it("can be unbookmarked", mock.initConverseWithPromises(
|
|
|
|
|
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
|
|
|
|
|
|
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
|
|
|
|
var sent_stanza, IQ_id;
|
|
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
|
|
|
|
|
|
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
|
|
|
|
|
var jid = 'theplay@conference.shakespeare.lit';
|
|
|
|
|
var view = _converse.chatboxviews.get(jid);
|
|
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
|
return !_.isNull(view.el.querySelector('.toggle-bookmark'));
|
|
|
|
|
}, 300).then(function () {
|
|
|
|
|
spyOn(view, 'toggleBookmark').and.callThrough();
|
|
|
|
|
spyOn(_converse.bookmarks, 'sendBookmarkStanza').and.callThrough();
|
|
|
|
|
view.delegateEvents();
|
|
|
|
|
|
|
|
|
|
_converse.bookmarks.create({
|
|
|
|
|
'jid': view.model.get('jid'),
|
|
|
|
|
'autojoin': false,
|
|
|
|
|
'name': 'The Play',
|
|
|
|
|
'nick': ' Othello'
|
|
|
|
|
});
|
|
|
|
|
expect(_converse.bookmarks.length).toBe(1);
|
|
|
|
|
expect(view.model.get('bookmarked')).toBeTruthy();
|
2018-03-16 12:49:39 +01:00
|
|
|
|
var $bookmark_icon = $(view.el.querySelector('.toggle-bookmark'));
|
2018-02-08 09:49:05 +01:00
|
|
|
|
expect($bookmark_icon.hasClass('button-on')).toBeTruthy();
|
|
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
|
sent_stanza = iq;
|
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
|
});
|
|
|
|
|
spyOn(_converse.connection, 'getUniqueId').and.callThrough();
|
|
|
|
|
$bookmark_icon[0].click();
|
|
|
|
|
expect(view.toggleBookmark).toHaveBeenCalled();
|
|
|
|
|
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
|
|
|
|
|
expect(_converse.bookmarks.length).toBe(0);
|
|
|
|
|
|
|
|
|
|
// Check that an IQ stanza is sent out, containing no
|
|
|
|
|
// conferences to bookmark (since we removed the one and
|
|
|
|
|
// only bookmark).
|
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
|
"<iq type='set' from='dummy@localhost/resource' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
|
"<pubsub xmlns='http://jabber.org/protocol/pubsub'>"+
|
|
|
|
|
"<publish node='storage:bookmarks'>"+
|
|
|
|
|
"<item id='current'>"+
|
|
|
|
|
"<storage xmlns='storage:bookmarks'/>"+
|
|
|
|
|
"</item>"+
|
|
|
|
|
"</publish>"+
|
|
|
|
|
"<publish-options>"+
|
|
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
|
|
|
|
"<value>http://jabber.org/protocol/pubsub#publish-options</value>"+
|
|
|
|
|
"</field>"+
|
|
|
|
|
"<field var='pubsub#persist_items'>"+
|
|
|
|
|
"<value>true</value>"+
|
|
|
|
|
"</field>"+
|
|
|
|
|
"<field var='pubsub#access_model'>"+
|
|
|
|
|
"<value>whitelist</value>"+
|
|
|
|
|
"</field>"+
|
|
|
|
|
"</x>"+
|
|
|
|
|
"</publish-options>"+
|
|
|
|
|
"</pubsub>"+
|
|
|
|
|
"</iq>"
|
|
|
|
|
);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("and when autojoin is set", function () {
|
|
|
|
|
|
|
|
|
|
it("will be be opened and joined automatically upon login", mock.initConverseWithPromises(
|
|
|
|
|
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
|
|
|
|
|
|
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
2018-03-16 20:48:31 +01:00
|
|
|
|
spyOn(_converse.api.rooms, 'create').and.callThrough();
|
2018-02-08 09:49:05 +01:00
|
|
|
|
var jid = 'theplay@conference.shakespeare.lit';
|
|
|
|
|
var model = _converse.bookmarks.create({
|
|
|
|
|
'jid': jid,
|
|
|
|
|
'autojoin': false,
|
|
|
|
|
'name': 'The Play',
|
|
|
|
|
'nick': ''
|
|
|
|
|
});
|
2018-03-16 20:48:31 +01:00
|
|
|
|
expect(_converse.api.rooms.create).not.toHaveBeenCalled();
|
2018-02-08 09:49:05 +01:00
|
|
|
|
_converse.bookmarks.remove(model);
|
|
|
|
|
|
|
|
|
|
_converse.bookmarks.create({
|
|
|
|
|
'jid': jid,
|
|
|
|
|
'autojoin': true,
|
|
|
|
|
'name': 'Hamlet',
|
|
|
|
|
'nick': ''
|
|
|
|
|
});
|
2018-03-16 20:48:31 +01:00
|
|
|
|
expect(_converse.api.rooms.create).toHaveBeenCalled();
|
2018-02-08 09:49:05 +01:00
|
|
|
|
done();
|
2016-09-23 09:41:55 +02:00
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
|
}));
|
2016-09-23 09:41:55 +02:00
|
|
|
|
});
|
2016-06-27 23:50:38 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("Bookmarks", function () {
|
|
|
|
|
|
2018-02-07 21:59:45 +01:00
|
|
|
|
it("can be pushed from the XMPP server", mock.initConverseWithPromises(
|
|
|
|
|
['send'], ['rosterGroupsFetched', 'connected'], {},
|
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
|
return _converse.bookmarks;
|
|
|
|
|
}, 300).then(function () {
|
|
|
|
|
/* The stored data is automatically pushed to all of the user's
|
|
|
|
|
* connected resources.
|
|
|
|
|
*
|
|
|
|
|
* Publisher receives event notification
|
|
|
|
|
* -------------------------------------
|
|
|
|
|
* <message from='juliet@capulet.lit'
|
|
|
|
|
* to='juliet@capulet.lit/balcony'
|
|
|
|
|
* type='headline'
|
|
|
|
|
* id='rnfoo1'>
|
|
|
|
|
* <event xmlns='http://jabber.org/protocol/pubsub#event'>
|
|
|
|
|
* <items node='storage:bookmarks'>
|
|
|
|
|
* <item id='current'>
|
|
|
|
|
* <storage xmlns='storage:bookmarks'>
|
|
|
|
|
* <conference name='The Play's the Thing'
|
|
|
|
|
* autojoin='true'
|
|
|
|
|
* jid='theplay@conference.shakespeare.lit'>
|
|
|
|
|
* <nick>JC</nick>
|
|
|
|
|
* </conference>
|
|
|
|
|
* </storage>
|
|
|
|
|
* </item>
|
|
|
|
|
* </items>
|
|
|
|
|
* </event>
|
|
|
|
|
* </message>
|
|
|
|
|
*/
|
|
|
|
|
var stanza = $msg({
|
|
|
|
|
'from': 'dummy@localhost',
|
|
|
|
|
'to': 'dummy@localhost/resource',
|
|
|
|
|
'type': 'headline',
|
|
|
|
|
'id': 'rnfoo1'
|
|
|
|
|
}).c('event', {'xmlns': 'http://jabber.org/protocol/pubsub#event'})
|
|
|
|
|
.c('items', {'node': 'storage:bookmarks'})
|
|
|
|
|
.c('item', {'id': 'current'})
|
|
|
|
|
.c('storage', {'xmlns': 'storage:bookmarks'})
|
|
|
|
|
.c('conference', {'name': 'The Play's the Thing',
|
|
|
|
|
'autojoin': 'true',
|
|
|
|
|
'jid':'theplay@conference.shakespeare.lit'})
|
|
|
|
|
.c('nick').t('JC');
|
2018-02-07 21:59:45 +01:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
expect(_converse.bookmarks.length).toBe(1);
|
|
|
|
|
expect(_converse.chatboxviews.get('theplay@conference.shakespeare.lit')).not.toBeUndefined();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2018-02-07 21:59:45 +01:00
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
|
}));
|
2016-06-27 23:50:38 +02:00
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
|
it("can be retrieved from the XMPP server", mock.initConverseWithPromises(
|
2018-02-07 17:30:44 +01:00
|
|
|
|
['send'], ['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {},
|
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
2018-02-07 17:30:44 +01:00
|
|
|
|
/* Client requests all items
|
|
|
|
|
* -------------------------
|
|
|
|
|
*
|
|
|
|
|
* <iq from='juliet@capulet.lit/randomID' type='get' id='retrieve1'>
|
|
|
|
|
* <pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
|
|
|
* <items node='storage:bookmarks'/>
|
|
|
|
|
* </pubsub>
|
|
|
|
|
* </iq>
|
|
|
|
|
*/
|
2016-10-06 09:02:29 +02:00
|
|
|
|
var IQ_id;
|
2017-05-09 09:45:12 +02:00
|
|
|
|
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
|
2017-06-12 20:30:58 +02:00
|
|
|
|
var stanza = call.args[0];
|
2017-05-09 09:45:12 +02:00
|
|
|
|
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// XXX: Wrapping in a div is a workaround for PhantomJS
|
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.appendChild(stanza);
|
|
|
|
|
if (div.innerHTML ===
|
|
|
|
|
'<iq from="dummy@localhost/resource" type="get" '+
|
|
|
|
|
'xmlns="jabber:client" id="'+stanza.getAttribute('id')+'">'+
|
|
|
|
|
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
|
|
|
|
|
'<items node="storage:bookmarks"></items>'+
|
|
|
|
|
'</pubsub>'+
|
|
|
|
|
'</iq>') {
|
|
|
|
|
IQ_id = stanza.getAttribute('id');
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}).length).toBe(1);
|
|
|
|
|
|
2018-02-07 17:30:44 +01:00
|
|
|
|
/*
|
|
|
|
|
* Server returns all items
|
|
|
|
|
* ------------------------
|
|
|
|
|
* <iq type='result'
|
|
|
|
|
* to='juliet@capulet.lit/randomID'
|
|
|
|
|
* id='retrieve1'>
|
|
|
|
|
* <pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
|
|
|
* <items node='storage:bookmarks'>
|
|
|
|
|
* <item id='current'>
|
|
|
|
|
* <storage xmlns='storage:bookmarks'>
|
|
|
|
|
* <conference name='The Play's the Thing'
|
|
|
|
|
* autojoin='true'
|
|
|
|
|
* jid='theplay@conference.shakespeare.lit'>
|
|
|
|
|
* <nick>JC</nick>
|
|
|
|
|
* </conference>
|
|
|
|
|
* </storage>
|
|
|
|
|
* </item>
|
|
|
|
|
* </items>
|
|
|
|
|
* </pubsub>
|
|
|
|
|
* </iq>
|
|
|
|
|
*/
|
|
|
|
|
expect(_converse.bookmarks.models.length).toBe(0);
|
2016-12-20 10:30:20 +01:00
|
|
|
|
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
|
2016-10-06 09:02:29 +02:00
|
|
|
|
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
|
|
|
|
.c('items', {'node': 'storage:bookmarks'})
|
|
|
|
|
.c('item', {'id': 'current'})
|
|
|
|
|
.c('storage', {'xmlns': 'storage:bookmarks'})
|
|
|
|
|
.c('conference', {
|
|
|
|
|
'name': 'The Play's the Thing',
|
2018-02-07 17:30:44 +01:00
|
|
|
|
'autojoin': 'true',
|
2016-10-06 09:02:29 +02:00
|
|
|
|
'jid': 'theplay@conference.shakespeare.lit'
|
|
|
|
|
}).c('nick').t('JC').up().up()
|
|
|
|
|
.c('conference', {
|
|
|
|
|
'name': 'Another room',
|
|
|
|
|
'autojoin': 'false',
|
|
|
|
|
'jid': 'another@conference.shakespeare.lit'
|
|
|
|
|
}).c('nick').t('JC').up().up();
|
2016-12-20 10:30:20 +01:00
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2018-02-07 17:30:44 +01:00
|
|
|
|
expect(_converse.bookmarks.models.length).toBe(2);
|
|
|
|
|
expect(_converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
|
|
|
|
|
expect(_converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe("The rooms panel", function () {
|
|
|
|
|
|
|
|
|
|
it("shows a list of bookmarks", mock.initConverseWithPromises(
|
|
|
|
|
['send'], ['rosterGroupsFetched'], {}, function (done, _converse) {
|
2017-07-11 17:21:13 +02:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
test_utils.openControlBox();
|
2018-02-07 17:30:44 +01:00
|
|
|
|
|
|
|
|
|
var IQ_id;
|
|
|
|
|
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
|
|
|
|
|
var stanza = call.args[0];
|
|
|
|
|
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// XXX: Wrapping in a div is a workaround for PhantomJS
|
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.appendChild(stanza);
|
|
|
|
|
if (div.innerHTML ===
|
|
|
|
|
'<iq from="dummy@localhost/resource" type="get" '+
|
|
|
|
|
'xmlns="jabber:client" id="'+stanza.getAttribute('id')+'">'+
|
|
|
|
|
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
|
|
|
|
|
'<items node="storage:bookmarks"></items>'+
|
|
|
|
|
'</pubsub>'+
|
|
|
|
|
'</iq>') {
|
|
|
|
|
IQ_id = stanza.getAttribute('id');
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}).length).toBe(1);
|
|
|
|
|
|
|
|
|
|
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
|
|
|
|
|
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
|
|
|
|
.c('items', {'node': 'storage:bookmarks'})
|
|
|
|
|
.c('item', {'id': 'current'})
|
|
|
|
|
.c('storage', {'xmlns': 'storage:bookmarks'})
|
|
|
|
|
.c('conference', {
|
|
|
|
|
'name': 'The Play's the Thing',
|
|
|
|
|
'autojoin': 'false',
|
|
|
|
|
'jid': 'theplay@conference.shakespeare.lit'
|
|
|
|
|
}).c('nick').t('JC').up().up()
|
|
|
|
|
.c('conference', {
|
|
|
|
|
'name': '1st Bookmark',
|
|
|
|
|
'autojoin': 'false',
|
|
|
|
|
'jid': 'first@conference.shakespeare.lit'
|
|
|
|
|
}).c('nick').t('JC').up().up()
|
|
|
|
|
.c('conference', {
|
|
|
|
|
'name': 'Bookmark with a very very long name that will be shortened',
|
|
|
|
|
'autojoin': 'false',
|
|
|
|
|
'jid': 'longname@conference.shakespeare.lit'
|
|
|
|
|
}).c('nick').t('JC').up().up()
|
|
|
|
|
.c('conference', {
|
|
|
|
|
'name': 'Another room',
|
|
|
|
|
'autojoin': 'false',
|
|
|
|
|
'jid': 'another@conference.shakespeare.lit'
|
|
|
|
|
}).c('nick').t('JC').up().up();
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
return $('#chatrooms div.bookmarks.rooms-list .room-item').length;
|
2018-02-07 17:30:44 +01:00
|
|
|
|
}, 300).then(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
expect($('#chatrooms div.bookmarks.rooms-list .room-item').length).toBe(4);
|
|
|
|
|
expect($('#chatrooms div.bookmarks.rooms-list .room-item a').text().trim()).toBe(
|
|
|
|
|
"1st Bookmark Another room Bookmark with a very very long name that will be shortened The Play's the Thing")
|
2018-02-07 17:30:44 +01:00
|
|
|
|
|
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
2018-03-16 12:49:39 +01:00
|
|
|
|
$('#chatrooms .bookmarks.rooms-list .room-item:nth-child(2) a:nth-child(2)')[0].click();
|
2018-02-07 17:30:44 +01:00
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
|
return test_utils.waitUntil(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
return $('#chatrooms .bookmarks.rooms-list .room-item a').text().trim() ===
|
|
|
|
|
"1st Bookmark Bookmark with a very very long name that will be shortened The Play's the Thing";
|
2018-02-07 17:30:44 +01:00
|
|
|
|
}, 300)
|
|
|
|
|
}).then(done);
|
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
|
}));
|
2016-11-03 16:12:52 +01:00
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
|
it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises(
|
|
|
|
|
['send'], ['rosterGroupsFetched'], {}, function (done, _converse) {
|
|
|
|
|
|
2018-03-16 12:49:39 +01:00
|
|
|
|
test_utils.openControlBox();
|
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
2018-02-07 17:30:44 +01:00
|
|
|
|
var IQ_id;
|
|
|
|
|
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
|
|
|
|
|
var stanza = call.args[0];
|
|
|
|
|
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// XXX: Wrapping in a div is a workaround for PhantomJS
|
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.appendChild(stanza);
|
|
|
|
|
if (div.innerHTML ===
|
|
|
|
|
'<iq from="dummy@localhost/resource" type="get" '+
|
|
|
|
|
'xmlns="jabber:client" id="'+stanza.getAttribute('id')+'">'+
|
|
|
|
|
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
|
|
|
|
|
'<items node="storage:bookmarks"></items>'+
|
|
|
|
|
'</pubsub>'+
|
|
|
|
|
'</iq>') {
|
|
|
|
|
IQ_id = stanza.getAttribute('id');
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}).length).toBe(1);
|
|
|
|
|
|
|
|
|
|
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
|
|
|
|
|
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
|
|
|
|
.c('items', {'node': 'storage:bookmarks'})
|
|
|
|
|
.c('item', {'id': 'current'})
|
|
|
|
|
.c('storage', {'xmlns': 'storage:bookmarks'});
|
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
|
|
_converse.bookmarks.create({
|
|
|
|
|
'jid': 'theplay@conference.shakespeare.lit',
|
|
|
|
|
'autojoin': false,
|
|
|
|
|
'name': 'The Play',
|
|
|
|
|
'nick': ''
|
|
|
|
|
});
|
|
|
|
|
test_utils.waitUntil(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
return $('#chatrooms .bookmarks.rooms-list .room-item:visible').length;
|
2018-02-07 17:30:44 +01:00
|
|
|
|
}, 300).then(function () {
|
2018-03-16 12:49:39 +01:00
|
|
|
|
expect($('#chatrooms .bookmarks.rooms-list').hasClass('collapsed')).toBeFalsy();
|
|
|
|
|
expect($('#chatrooms .bookmarks.rooms-list .room-item:visible').length).toBe(1);
|
2018-02-07 17:30:44 +01:00
|
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
|
|
|
|
|
$('#chatrooms .bookmarks-toggle')[0].click();
|
2018-03-16 12:49:39 +01:00
|
|
|
|
expect($('#chatrooms .bookmarks.rooms-list').hasClass('collapsed')).toBeTruthy();
|
2018-02-07 17:30:44 +01:00
|
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.CLOSED);
|
|
|
|
|
$('#chatrooms .bookmarks-toggle')[0].click();
|
2018-03-16 12:49:39 +01:00
|
|
|
|
expect($('#chatrooms .bookmarks.rooms-list').hasClass('collapsed')).toBeFalsy();
|
|
|
|
|
expect($('#chatrooms .bookmarks.rooms-list .room-item:visible').length).toBe(1);
|
2018-02-07 17:30:44 +01:00
|
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-07-11 17:21:13 +02:00
|
|
|
|
});
|
2016-11-03 16:12:52 +01:00
|
|
|
|
}));
|
2016-10-06 09:02:29 +02:00
|
|
|
|
});
|
2016-06-27 23:50:38 +02:00
|
|
|
|
});
|
2017-05-23 14:59:37 +02:00
|
|
|
|
|
|
|
|
|
describe("When hide_open_bookmarks is true and a bookmarked room is opened", function () {
|
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
|
it("can be closed", mock.initConverseWithPromises(
|
|
|
|
|
null, ['rosterGroupsFetched'],
|
|
|
|
|
{ hide_open_bookmarks: true },
|
|
|
|
|
function (done, _converse) {
|
2017-05-23 14:59:37 +02:00
|
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
|
test_utils.waitUntilDiscoConfirmed(
|
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
|
).then(function () {
|
2018-02-07 17:30:44 +01:00
|
|
|
|
// XXX Create bookmarks view here, otherwise we need to mock stanza
|
|
|
|
|
// traffic for it to get created.
|
|
|
|
|
_converse.bookmarksview = new _converse.BookmarksView(
|
|
|
|
|
{'model': _converse.bookmarks}
|
|
|
|
|
);
|
|
|
|
|
_converse.emit('bookmarksInitialized');
|
2017-05-23 14:59:37 +02:00
|
|
|
|
|
2018-02-07 17:30:44 +01:00
|
|
|
|
// Check that it's there
|
|
|
|
|
var jid = 'room@conference.example.org';
|
|
|
|
|
_converse.bookmarks.create({
|
|
|
|
|
'jid': jid,
|
|
|
|
|
'autojoin': false,
|
|
|
|
|
'name': 'The Play',
|
|
|
|
|
'nick': ' Othello'
|
|
|
|
|
});
|
2017-05-23 14:59:37 +02:00
|
|
|
|
|
2018-02-07 17:30:44 +01:00
|
|
|
|
expect(_converse.bookmarks.length).toBe(1);
|
|
|
|
|
var room_els = _converse.bookmarksview.el.querySelectorAll(".open-room");
|
|
|
|
|
expect(room_els.length).toBe(1);
|
|
|
|
|
|
|
|
|
|
// Check that it disappears once the room is opened
|
|
|
|
|
var bookmark = _converse.bookmarksview.el.querySelector(".open-room");
|
|
|
|
|
bookmark.click();
|
|
|
|
|
expect(u.hasClass('hidden', _converse.bookmarksview.el.querySelector(".available-chatroom"))).toBeTruthy();
|
|
|
|
|
// Check that it reappears once the room is closed
|
|
|
|
|
var view = _converse.chatboxviews.get(jid);
|
|
|
|
|
view.close();
|
|
|
|
|
expect(u.hasClass('hidden', _converse.bookmarksview.el.querySelector(".available-chatroom"))).toBeFalsy();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-05-23 14:59:37 +02:00
|
|
|
|
}));
|
|
|
|
|
});
|
2016-06-27 23:50:38 +02:00
|
|
|
|
}));
|