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
|
|
|
"mock",
|
2017-04-05 11:01:31 +02:00
|
|
|
"test-utils"
|
2016-06-27 23:50:38 +02:00
|
|
|
], factory);
|
2019-04-06 16:31:42 +02:00
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2016-06-27 23:50:38 +02:00
|
|
|
"use strict";
|
2018-10-26 10:15:01 +02:00
|
|
|
const $iq = converse.env.$iq,
|
|
|
|
$msg = converse.env.$msg,
|
|
|
|
Strophe = converse.env.Strophe,
|
|
|
|
sizzle = converse.env.sizzle,
|
|
|
|
_ = converse.env._,
|
|
|
|
u = converse.env.utils;
|
2016-06-27 23:50:38 +02:00
|
|
|
|
2019-10-11 23:33:30 +02:00
|
|
|
|
2016-06-27 23:50:38 +02:00
|
|
|
describe("A chat room", function () {
|
|
|
|
|
2020-01-21 12:45:34 +01:00
|
|
|
it("can be bookmarked", mock.initConverse(['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2019-05-21 12:05:47 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-02-08 09:49:05 +01:00
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
2018-11-22 12:15:35 +01:00
|
|
|
);
|
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2018-02-08 09:49:05 +01:00
|
|
|
});
|
2018-11-22 12:15:35 +01:00
|
|
|
spyOn(_converse.connection, 'getUniqueId').and.callThrough();
|
|
|
|
|
|
|
|
await test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
|
|
|
|
var jid = 'theplay@conference.shakespeare.lit';
|
|
|
|
const view = _converse.chatboxviews.get(jid);
|
|
|
|
spyOn(view, 'renderBookmarkForm').and.callThrough();
|
|
|
|
spyOn(view, 'closeForm').and.callThrough();
|
2020-02-10 11:23:55 +01:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.toggle-bookmark') !== null);
|
2020-04-06 14:27:44 +02:00
|
|
|
const toggle = view.el.querySelector('.toggle-bookmark');
|
2019-02-26 12:08:48 +01:00
|
|
|
expect(toggle.title).toBe('Bookmark this groupchat');
|
|
|
|
toggle.click();
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(view.renderBookmarkForm).toHaveBeenCalled();
|
|
|
|
|
|
|
|
view.el.querySelector('.button-cancel').click();
|
|
|
|
expect(view.closeForm).toHaveBeenCalled();
|
2019-02-26 12:08:48 +01:00
|
|
|
expect(u.hasClass('on-button', toggle), false);
|
|
|
|
expect(toggle.title).toBe('Bookmark this groupchat');
|
2018-11-22 12:15:35 +01:00
|
|
|
|
2019-02-26 12:08:48 +01:00
|
|
|
toggle.click();
|
2018-11-22 12:15:35 +01:00
|
|
|
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();
|
|
|
|
const form = view.el.querySelector('.chatroom-form');
|
|
|
|
form.querySelector('input[name="name"]').value = 'Play's the Thing';
|
|
|
|
form.querySelector('input[name="autojoin"]').checked = 'checked';
|
|
|
|
form.querySelector('input[name="nick"]').value = 'JC';
|
|
|
|
|
|
|
|
_converse.connection.IQ_stanzas = [];
|
|
|
|
view.el.querySelector('.btn-primary').click();
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sent_stanza);
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
2019-06-03 07:58:51 +02:00
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
2018-11-22 12:15:35 +01:00
|
|
|
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
|
|
|
|
`<publish node="storage:bookmarks">`+
|
|
|
|
`<item id="current">`+
|
|
|
|
`<storage xmlns="storage:bookmarks">`+
|
|
|
|
`<conference autojoin="true" jid="theplay@conference.shakespeare.lit" name="Play&apos;s the Thing">`+
|
|
|
|
`<nick>JC</nick>`+
|
|
|
|
`</conference>`+
|
|
|
|
`</storage>`+
|
|
|
|
`</item>`+
|
|
|
|
`</publish>`+
|
|
|
|
`<publish-options>`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<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>`
|
|
|
|
);
|
|
|
|
/* Server acknowledges successful storage
|
|
|
|
*
|
|
|
|
* <iq to='juliet@capulet.lit/balcony' type='result' id='pip1'/>
|
|
|
|
*/
|
|
|
|
const stanza = $iq({
|
|
|
|
'to':_converse.connection.jid,
|
|
|
|
'type':'result',
|
|
|
|
'id':IQ_id
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.get('bookmarked'));
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(view.model.get('bookmarked')).toBeTruthy();
|
2020-04-06 14:27:44 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.toggle-bookmark')?.title === 'Unbookmark this groupchat');
|
|
|
|
expect(u.hasClass('on-button', view.el.querySelector('.toggle-bookmark')), true);
|
2018-11-22 12:15:35 +01:00
|
|
|
// We ignore this IQ stanza... (unless it's an error stanza), so
|
|
|
|
// nothing to test for here.
|
|
|
|
done();
|
2018-02-08 09:49:05 +01:00
|
|
|
}));
|
2016-09-23 09:41:55 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(
|
2019-12-18 12:42:40 +01:00
|
|
|
['rosterGroupsFetched'], {},
|
|
|
|
async function (done, _converse) {
|
2016-09-23 09:41:55 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-02-08 09:49:05 +01:00
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
2018-11-22 12:15:35 +01:00
|
|
|
);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.bookmarks);
|
2019-06-03 07:58:51 +02:00
|
|
|
let jid = 'lounge@montague.lit';
|
2018-11-22 12:15:35 +01:00
|
|
|
_converse.bookmarks.create({
|
|
|
|
'jid': jid,
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Lounge',
|
|
|
|
'nick': ' Othello'
|
|
|
|
});
|
2019-07-29 10:19:05 +02:00
|
|
|
expect(_converse.chatboxviews.get(jid) === undefined).toBeTruthy();
|
2018-11-22 12:15:35 +01:00
|
|
|
|
|
|
|
jid = 'theplay@conference.shakespeare.lit';
|
|
|
|
_converse.bookmarks.create({
|
|
|
|
'jid': jid,
|
|
|
|
'autojoin': true,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ' Othello'
|
2018-02-08 09:49:05 +01:00
|
|
|
});
|
2019-12-18 12:42:40 +01:00
|
|
|
await new Promise(resolve => _converse.api.listen.once('chatRoomViewInitialized', resolve));
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeFalsy();
|
2019-03-27 08:34:36 +01:00
|
|
|
|
|
|
|
// Check that we don't auto-join if muc_respect_autojoin is false
|
|
|
|
_converse.muc_respect_autojoin = false;
|
|
|
|
jid = 'balcony@conference.shakespeare.lit';
|
|
|
|
_converse.bookmarks.create({
|
|
|
|
'jid': jid,
|
|
|
|
'autojoin': true,
|
|
|
|
'name': 'Balcony',
|
|
|
|
'nick': ' Othello'
|
|
|
|
});
|
2019-07-29 10:19:05 +02:00
|
|
|
expect(_converse.chatboxviews.get(jid) === undefined).toBe(true);
|
2018-11-22 12:15:35 +01:00
|
|
|
done();
|
2018-02-08 09:49:05 +01:00
|
|
|
}));
|
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
|
2018-02-08 09:49:05 +01:00
|
|
|
describe("when bookmarked", function () {
|
|
|
|
|
2019-05-21 12:05:47 +02:00
|
|
|
it("will use the nickname from the bookmark", mock.initConverse(
|
2019-10-11 23:33:30 +02:00
|
|
|
['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2019-10-24 14:29:15 +02:00
|
|
|
|
2019-10-11 23:33:30 +02:00
|
|
|
await test_utils.waitUntilBookmarksReturned(_converse);
|
2019-12-08 20:42:09 +01:00
|
|
|
const muc_jid = 'coven@chat.shakespeare.lit';
|
2019-05-21 12:05:47 +02:00
|
|
|
_converse.bookmarks.create({
|
2019-12-08 20:42:09 +01:00
|
|
|
'jid': muc_jid,
|
2019-05-21 12:05:47 +02:00
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': 'Othello'
|
|
|
|
});
|
2019-12-08 20:42:09 +01:00
|
|
|
spyOn(_converse.ChatRoom.prototype, 'getAndPersistNickname').and.callThrough();
|
|
|
|
const room_creation_promise = _converse.api.rooms.open(muc_jid);
|
|
|
|
await test_utils.getRoomFeatures(_converse, muc_jid);
|
|
|
|
const room = await room_creation_promise;
|
|
|
|
await u.waitUntil(() => room.getAndPersistNickname.calls.count());
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(room.get('nick')).toBe('Othello');
|
2019-05-21 12:05:47 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("displays that it's bookmarked through its bookmark icon", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-22 12:15:35 +01:00
|
|
|
async 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']
|
2018-11-22 12:15:35 +01:00
|
|
|
);
|
2019-06-03 07:58:51 +02:00
|
|
|
await _converse.api.rooms.open(`lounge@montague.lit`);
|
|
|
|
const view = _converse.chatboxviews.get('lounge@montague.lit');
|
2020-02-10 11:23:55 +01:00
|
|
|
expect(view.el.querySelector('.chatbox-title__text .fa-bookmark')).toBe(null);
|
2019-05-29 12:57:54 +02:00
|
|
|
_converse.bookmarks.create({
|
|
|
|
'jid': view.model.get('jid'),
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The lounge',
|
|
|
|
'nick': ' some1'
|
|
|
|
});
|
2018-11-22 12:15:35 +01:00
|
|
|
view.model.set('bookmarked', true);
|
2020-03-31 17:22:05 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') !== null);
|
2018-11-22 12:15:35 +01:00
|
|
|
view.model.set('bookmarked', false);
|
2020-03-31 17:22:05 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') === null);
|
2018-11-22 12:15:35 +01:00
|
|
|
done();
|
2018-02-08 09:49:05 +01:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("can be unbookmarked", mock.initConverse(
|
2019-10-24 14:29:15 +02:00
|
|
|
['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2018-11-22 12:15:35 +01:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitUntilBookmarksReturned(_converse);
|
|
|
|
const muc_jid = 'theplay@conference.shakespeare.lit';
|
|
|
|
await _converse.api.rooms.open(muc_jid);
|
|
|
|
const view = _converse.chatboxviews.get(muc_jid);
|
|
|
|
await u.waitUntil(() => view.el.querySelector('.toggle-bookmark'));
|
2018-11-22 12:15:35 +01:00
|
|
|
|
|
|
|
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'
|
|
|
|
});
|
2019-10-24 14:29:15 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(_converse.bookmarks.length).toBe(1);
|
2019-10-04 18:26:33 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length >= 1);
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(view.model.get('bookmarked')).toBeTruthy();
|
2020-03-31 17:22:05 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') !== null);
|
2018-11-22 12:15:35 +01:00
|
|
|
spyOn(_converse.connection, 'getUniqueId').and.callThrough();
|
2020-02-10 11:23:55 +01:00
|
|
|
const bookmark_icon = view.el.querySelector('.toggle-bookmark');
|
2018-11-22 12:15:35 +01:00
|
|
|
bookmark_icon.click();
|
|
|
|
expect(view.toggleBookmark).toHaveBeenCalled();
|
2020-03-31 17:22:05 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') === null);
|
2018-11-22 12:15:35 +01:00
|
|
|
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).
|
2019-10-24 14:29:15 +02:00
|
|
|
const sent_stanza = _converse.connection.IQ_stanzas.pop();
|
|
|
|
expect(Strophe.serialize(sent_stanza)).toBe(
|
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
2018-11-22 12:15:35 +01:00
|
|
|
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
|
|
|
|
`<publish node="storage:bookmarks">`+
|
|
|
|
`<item id="current">`+
|
|
|
|
`<storage xmlns="storage:bookmarks"/>`+
|
|
|
|
`</item>`+
|
|
|
|
`</publish>`+
|
|
|
|
`<publish-options>`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<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();
|
2018-02-08 09:49:05 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("and when autojoin is set", function () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("will be be opened and joined automatically upon login", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-22 12:15:35 +01:00
|
|
|
async function (done, _converse) {
|
2018-02-08 09:49:05 +01:00
|
|
|
|
2019-07-12 10:37:10 +02:00
|
|
|
await test_utils.waitUntilBookmarksReturned(_converse);
|
2018-11-22 12:15:35 +01:00
|
|
|
spyOn(_converse.api.rooms, 'create').and.callThrough();
|
|
|
|
const jid = 'theplay@conference.shakespeare.lit';
|
|
|
|
const model = _converse.bookmarks.create({
|
|
|
|
'jid': jid,
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ''
|
2016-09-23 09:41:55 +02:00
|
|
|
});
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(_converse.api.rooms.create).not.toHaveBeenCalled();
|
|
|
|
_converse.bookmarks.remove(model);
|
|
|
|
_converse.bookmarks.create({
|
|
|
|
'jid': jid,
|
|
|
|
'autojoin': true,
|
|
|
|
'name': 'Hamlet',
|
|
|
|
'nick': ''
|
|
|
|
});
|
|
|
|
expect(_converse.api.rooms.create).toHaveBeenCalled();
|
|
|
|
done();
|
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 () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("can be pushed from the XMPP server", mock.initConverse(
|
2019-10-11 23:33:30 +02:00
|
|
|
['rosterGroupsFetched', 'connected'], {}, async function (done, _converse) {
|
2018-02-07 21:59:45 +01:00
|
|
|
|
2019-10-11 23:33:30 +02:00
|
|
|
await test_utils.waitUntilBookmarksReturned(_converse);
|
2018-11-22 12:15:35 +01:00
|
|
|
|
|
|
|
/* 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>
|
|
|
|
*/
|
2019-10-11 23:33:30 +02:00
|
|
|
const stanza = $msg({
|
2019-06-03 07:58:51 +02:00
|
|
|
'from': 'romeo@montague.lit',
|
|
|
|
'to': 'romeo@montague.lit/orchard',
|
2018-11-22 12:15:35 +01:00
|
|
|
'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');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.bookmarks.length);
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(_converse.bookmarks.length).toBe(1);
|
|
|
|
expect(_converse.chatboxviews.get('theplay@conference.shakespeare.lit')).not.toBeUndefined();
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-27 23:50:38 +02:00
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("can be retrieved from the XMPP server", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {},
|
2018-11-18 19:14:22 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-02-08 09:49:05 +01:00
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
2018-10-26 10:15:01 +02: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>
|
|
|
|
*/
|
2018-11-18 19:14:22 +01:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
const sent_stanza = await u.waitUntil(
|
|
|
|
() => IQ_stanzas.filter(s => sizzle('items[node="storage:bookmarks"]', s).length).pop());
|
2018-10-26 10:15:01 +02:00
|
|
|
|
2018-11-18 19:14:22 +01:00
|
|
|
expect(Strophe.serialize(sent_stanza)).toBe(
|
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${sent_stanza.getAttribute('id')}" type="get" xmlns="jabber:client">`+
|
2018-10-26 10:15:01 +02:00
|
|
|
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
|
|
|
|
'<items node="storage:bookmarks"/>'+
|
|
|
|
'</pubsub>'+
|
|
|
|
'</iq>');
|
2019-07-12 10:37:10 +02:00
|
|
|
|
2018-10-26 10:15:01 +02: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);
|
|
|
|
|
|
|
|
spyOn(_converse.bookmarks, 'onBookmarksReceived').and.callThrough();
|
2018-11-18 19:14:22 +01:00
|
|
|
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':sent_stanza.getAttribute('id')})
|
2018-10-26 10:15:01 +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',
|
|
|
|
'autojoin': 'true',
|
|
|
|
'jid': 'theplay@conference.shakespeare.lit'
|
|
|
|
}).c('nick').t('JC').up().up()
|
|
|
|
.c('conference', {
|
|
|
|
'name': 'Another room',
|
|
|
|
'autojoin': 'false',
|
|
|
|
'jid': 'another@conference.shakespeare.lit'
|
|
|
|
}); // Purposefully exclude the <nick> element to test #1043
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.bookmarks.onBookmarksReceived.calls.count());
|
2019-10-11 23:33:30 +02:00
|
|
|
await _converse.api.waitUntil('bookmarksInitialized');
|
2018-10-26 10:15:01 +02: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 () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("shows a list of bookmarks", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-26 10:15:01 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
|
|
|
);
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
2018-10-26 10:15:01 +02:00
|
|
|
|
2018-11-18 19:14:22 +01:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
const sent_stanza = await u.waitUntil(
|
|
|
|
() => IQ_stanzas.filter(s => sizzle('items[node="storage:bookmarks"]', s).length).pop());
|
|
|
|
|
|
|
|
expect(Strophe.serialize(sent_stanza)).toBe(
|
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${sent_stanza.getAttribute('id')}" type="get" xmlns="jabber:client">`+
|
2018-10-26 10:15:01 +02:00
|
|
|
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
|
|
|
|
'<items node="storage:bookmarks"/>'+
|
|
|
|
'</pubsub>'+
|
|
|
|
'</iq>'
|
|
|
|
);
|
|
|
|
|
2018-11-18 19:14:22 +01:00
|
|
|
const stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':sent_stanza.getAttribute('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-10-26 10:15:01 +02:00
|
|
|
'autojoin': 'false',
|
2016-10-06 09:02:29 +02:00
|
|
|
'jid': 'theplay@conference.shakespeare.lit'
|
|
|
|
}).c('nick').t('JC').up().up()
|
2018-10-26 10:15:01 +02:00
|
|
|
.c('conference', {
|
|
|
|
'name': '1st Bookmark',
|
|
|
|
'autojoin': 'false',
|
|
|
|
'jid': 'first@conference.shakespeare.lit'
|
|
|
|
}).c('nick').t('JC').up().up()
|
|
|
|
.c('conference', {
|
|
|
|
'autojoin': 'false',
|
|
|
|
'jid': 'noname@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()
|
2016-10-06 09:02:29 +02:00
|
|
|
.c('conference', {
|
|
|
|
'name': 'Another room',
|
|
|
|
'autojoin': 'false',
|
|
|
|
'jid': 'another@conference.shakespeare.lit'
|
2018-10-26 10:15:01 +02:00
|
|
|
}).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
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length);
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length).toBe(5);
|
|
|
|
let els = document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item a.list-item-link');
|
|
|
|
expect(els[0].textContent).toBe("1st Bookmark");
|
|
|
|
expect(els[1].textContent).toBe("Another room");
|
|
|
|
expect(els[2].textContent).toBe("Bookmark with a very very long name that will be shortened");
|
|
|
|
expect(els[3].textContent).toBe("noname@conference.shakespeare.lit");
|
|
|
|
expect(els[4].textContent).toBe("The Play's the Thing");
|
|
|
|
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
document.querySelector('#chatrooms .bookmarks.rooms-list .room-item:nth-child(2) a:nth-child(2)').click();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item').length === 4)
|
2018-10-26 10:15:01 +02:00
|
|
|
els = document.querySelectorAll('#chatrooms div.bookmarks.rooms-list .room-item a.list-item-link');
|
|
|
|
expect(els[0].textContent).toBe("1st Bookmark");
|
|
|
|
expect(els[1].textContent).toBe("Bookmark with a very very long name that will be shortened");
|
|
|
|
expect(els[2].textContent).toBe("noname@conference.shakespeare.lit");
|
|
|
|
expect(els[3].textContent).toBe("The Play's the Thing");
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-11-03 16:12:52 +01:00
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("remembers the toggle state of the bookmarks list", mock.initConverse(
|
2019-10-24 14:29:15 +02:00
|
|
|
['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-10-26 10:15:01 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(
|
2018-02-08 09:49:05 +01:00
|
|
|
_converse, _converse.bare_jid,
|
|
|
|
[{'category': 'pubsub', 'type': 'pep'}],
|
|
|
|
['http://jabber.org/protocol/pubsub#publish-options']
|
2018-10-26 10:15:01 +02:00
|
|
|
);
|
|
|
|
|
2018-11-18 19:14:22 +01:00
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
|
|
|
const sent_stanza = await u.waitUntil(
|
2019-10-24 14:29:15 +02:00
|
|
|
() => IQ_stanzas.filter(s => sizzle('iq items[node="storage:bookmarks"]', s).length).pop());
|
2018-11-18 19:14:22 +01:00
|
|
|
|
|
|
|
expect(Strophe.serialize(sent_stanza)).toBe(
|
|
|
|
`<iq from="romeo@montague.lit/orchard" id="${sent_stanza.getAttribute('id')}" type="get" xmlns="jabber:client">`+
|
2018-10-26 10:15:01 +02:00
|
|
|
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
|
|
|
|
'<items node="storage:bookmarks"/>'+
|
|
|
|
'</pubsub>'+
|
|
|
|
'</iq>'
|
|
|
|
);
|
2019-10-24 14:29:15 +02:00
|
|
|
const stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id': sent_stanza.getAttribute('id')})
|
2018-10-26 10:15:01 +02:00
|
|
|
.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));
|
2019-10-24 14:29:15 +02:00
|
|
|
await _converse.api.waitUntil('bookmarksInitialized');
|
2018-02-07 17:30:44 +01:00
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
_converse.bookmarks.create({
|
|
|
|
'jid': 'theplay@conference.shakespeare.lit',
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ''
|
2017-07-11 17:21:13 +02:00
|
|
|
});
|
2019-04-06 16:31:42 +02:00
|
|
|
const el = _converse.chatboxviews.el
|
|
|
|
const selector = '#chatrooms .bookmarks.rooms-list .room-item';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle(selector, el).filter(u.isVisible).length);
|
2019-04-06 16:31:42 +02:00
|
|
|
expect(u.hasClass('collapsed', sizzle('#chatrooms .bookmarks.rooms-list', el).pop())).toBeFalsy();
|
|
|
|
expect(sizzle(selector, el).filter(u.isVisible).length).toBe(1);
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
|
2019-04-06 16:31:42 +02:00
|
|
|
sizzle('#chatrooms .bookmarks-toggle', el).pop().click();
|
|
|
|
expect(u.hasClass('collapsed', sizzle('#chatrooms .bookmarks.rooms-list', el).pop())).toBeTruthy();
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.CLOSED);
|
2019-04-06 16:31:42 +02:00
|
|
|
sizzle('#chatrooms .bookmarks-toggle', el).pop().click();
|
|
|
|
expect(u.hasClass('collapsed', sizzle('#chatrooms .bookmarks.rooms-list', el).pop())).toBeFalsy();
|
|
|
|
expect(sizzle(selector, el).filter(u.isVisible).length).toBe(1);
|
2018-10-26 10:15:01 +02:00
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
|
|
|
|
done();
|
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 () {
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("can be closed", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'],
|
2017-07-11 10:41:11 +02:00
|
|
|
{ hide_open_bookmarks: true },
|
2018-11-22 12:15:35 +01:00
|
|
|
async function (done, _converse) {
|
2017-05-23 14:59:37 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-10-11 23:33:30 +02:00
|
|
|
await test_utils.waitUntilBookmarksReturned(_converse);
|
2018-11-22 12:15:35 +01:00
|
|
|
|
|
|
|
// Check that it's there
|
2019-10-11 23:33:30 +02:00
|
|
|
const jid = 'room@conference.example.org';
|
2018-11-22 12:15:35 +01:00
|
|
|
_converse.bookmarks.create({
|
|
|
|
'jid': jid,
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ' Othello'
|
2018-02-07 17:30:44 +01:00
|
|
|
});
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(_converse.bookmarks.length).toBe(1);
|
2019-06-27 11:27:05 +02:00
|
|
|
|
|
|
|
const bmarks_view = _converse.bookmarksview;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => bmarks_view.el.querySelectorAll(".open-room").length, 500);
|
2019-06-27 11:27:05 +02:00
|
|
|
const room_els = bmarks_view.el.querySelectorAll(".open-room");
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(room_els.length).toBe(1);
|
|
|
|
|
|
|
|
const bookmark = _converse.bookmarksview.el.querySelector(".open-room");
|
|
|
|
bookmark.click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxviews.get(jid));
|
2019-06-27 11:27:05 +02:00
|
|
|
|
2018-11-22 12:15:35 +01:00
|
|
|
expect(u.hasClass('hidden', _converse.bookmarksview.el.querySelector(".available-chatroom"))).toBeTruthy();
|
|
|
|
// Check that it reappears once the room is closed
|
|
|
|
const view = _converse.chatboxviews.get(jid);
|
|
|
|
view.close();
|
2019-10-11 23:33:30 +02:00
|
|
|
await u.waitUntil(() => !u.hasClass('hidden', _converse.bookmarksview.el.querySelector(".available-chatroom")));
|
2018-11-22 12:15:35 +01:00
|
|
|
done();
|
2017-05-23 14:59:37 +02:00
|
|
|
}));
|
|
|
|
});
|
2016-06-27 23:50:38 +02:00
|
|
|
}));
|