2016-06-27 23:50:38 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
|
|
|
"jquery",
|
2016-11-30 13:18:58 +01:00
|
|
|
"converse-api",
|
2016-06-27 23:50:38 +02:00
|
|
|
"utils",
|
|
|
|
"mock",
|
|
|
|
"test_utils"
|
|
|
|
], factory);
|
2016-12-20 10:30:20 +01:00
|
|
|
} (this, function ($, 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,
|
|
|
|
Strophe = converse.env.Strophe,
|
|
|
|
_ = converse.env._;
|
2016-06-27 23:50:38 +02:00
|
|
|
|
|
|
|
describe("A chat room", function () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be bookmarked", mock.initConverse(function (_converse) {
|
2016-06-27 23:50:38 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2016-06-27 23:50:38 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'getUniqueId').andCallThrough();
|
2016-06-27 23:50:38 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
|
2016-06-27 23:50:38 +02:00
|
|
|
var jid = 'theplay@conference.shakespeare.lit';
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.chatboxviews.get(jid);
|
2016-06-27 23:50:38 +02:00
|
|
|
spyOn(view, 'renderBookmarkForm').andCallThrough();
|
|
|
|
spyOn(view, 'cancelConfiguration').andCallThrough();
|
|
|
|
|
|
|
|
var $bookmark = view.$el.find('.icon-pushpin');
|
|
|
|
$bookmark.click();
|
|
|
|
expect(view.renderBookmarkForm).toHaveBeenCalled();
|
|
|
|
|
|
|
|
view.$el.find('.button-cancel').click();
|
|
|
|
expect(view.cancelConfiguration).toHaveBeenCalled();
|
|
|
|
expect($bookmark.hasClass('on-button'), false);
|
|
|
|
|
|
|
|
$bookmark.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>
|
|
|
|
*/
|
2016-09-22 11:30:06 +02:00
|
|
|
expect(view.model.get('bookmarked')).toBeFalsy();
|
2016-06-27 23:50:38 +02:00
|
|
|
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');
|
|
|
|
$form.submit();
|
2016-09-22 11:30:06 +02:00
|
|
|
expect(view.model.get('bookmarked')).toBeTruthy();
|
2016-06-27 23:50:38 +02:00
|
|
|
expect($bookmark.hasClass('on-button'), true);
|
|
|
|
|
|
|
|
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'>"+
|
|
|
|
"<conference name='Play&apos;s the Thing' autojoin='true' jid='theplay@conference.shakespeare.lit'>"+
|
|
|
|
"<nick>JC</nick>"+
|
|
|
|
"</conference>"+
|
|
|
|
"</storage>"+
|
|
|
|
"</item>"+
|
|
|
|
"</publish>"+
|
2016-08-13 08:57:59 +02:00
|
|
|
"<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>"+
|
2016-06-27 23:50:38 +02:00
|
|
|
"</pubsub>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Server acknowledges successful storage
|
|
|
|
*
|
|
|
|
* <iq to='juliet@capulet.lit/balcony' type='result' id='pip1'/>
|
|
|
|
*/
|
|
|
|
var stanza = $iq({
|
2016-12-20 10:30:20 +01:00
|
|
|
'to':_converse.connection.jid,
|
2016-06-27 23:50:38 +02:00
|
|
|
'type':'result',
|
|
|
|
'id':IQ_id
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-09-22 11:30:06 +02:00
|
|
|
// We ignore this IQ stanza... (unless it's an error stanza), so
|
|
|
|
// nothing to test for here.
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-27 23:50:38 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(function (_converse) {
|
2016-09-22 14:03:42 +02:00
|
|
|
var jid = 'lounge@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.bookmarks.create({
|
2016-09-22 14:03:42 +02:00
|
|
|
'jid': jid,
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Lounge',
|
|
|
|
'nick': ' Othello'
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeTruthy();
|
2016-09-22 14:03:42 +02:00
|
|
|
|
|
|
|
jid = 'theplay@conference.shakespeare.lit';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.bookmarks.create({
|
2016-09-22 14:03:42 +02:00
|
|
|
'jid': jid,
|
|
|
|
'autojoin': true,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ' Othello'
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeFalsy();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-09-22 14:03:42 +02:00
|
|
|
|
2016-06-27 23:50:38 +02:00
|
|
|
describe("when bookmarked", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("displays that it's bookmarked through its bookmark icon", mock.initConverse(function (_converse) {
|
2016-09-22 11:30:06 +02:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
|
2016-09-22 11:30:06 +02:00
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.chatboxviews.get('lounge@localhost');
|
2016-09-22 11:30:06 +02:00
|
|
|
var $bookmark_icon = view.$('.icon-pushpin');
|
|
|
|
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
|
|
|
|
view.model.set('bookmarked', true);
|
|
|
|
expect($bookmark_icon.hasClass('button-on')).toBeTruthy();
|
|
|
|
view.model.set('bookmarked', false);
|
|
|
|
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-27 23:50:38 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be unbookmarked", mock.initConverse(function (_converse) {
|
2016-09-22 14:03:42 +02:00
|
|
|
var view, sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2016-09-22 13:02:16 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'getUniqueId').andCallThrough();
|
2016-09-22 13:02:16 +02:00
|
|
|
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
|
2016-09-22 13:02:16 +02:00
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function () {
|
|
|
|
var jid = 'theplay@conference.shakespeare.lit';
|
2016-12-20 10:30:20 +01:00
|
|
|
view = _converse.chatboxviews.get(jid);
|
2016-09-22 13:02:16 +02:00
|
|
|
spyOn(view, 'toggleBookmark').andCallThrough();
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.bookmarks, 'sendBookmarkStanza').andCallThrough();
|
2016-09-22 13:02:16 +02:00
|
|
|
view.delegateEvents();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.bookmarks.create({
|
2016-09-22 13:02:16 +02:00
|
|
|
'jid': view.model.get('jid'),
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ' Othello'
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.bookmarks.length).toBe(1);
|
2016-09-22 14:03:42 +02:00
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('bookmarked')).toBeTruthy();
|
2016-09-22 13:02:16 +02:00
|
|
|
var $bookmark_icon = view.$('.icon-pushpin');
|
|
|
|
expect($bookmark_icon.hasClass('button-on')).toBeTruthy();
|
|
|
|
$bookmark_icon.click();
|
|
|
|
expect(view.toggleBookmark).toHaveBeenCalled();
|
2016-10-06 09:02:29 +02:00
|
|
|
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.bookmarks.length).toBe(0);
|
2016-09-22 13:02:16 +02:00
|
|
|
// 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>"
|
|
|
|
);
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-27 23:50:38 +02:00
|
|
|
});
|
2016-09-23 09:41:55 +02:00
|
|
|
|
|
|
|
describe("and when autojoin is set", function () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will be be opened and joined automatically upon login", mock.initConverse(function (_converse) {
|
|
|
|
spyOn(_converse.api.rooms, 'open');
|
2016-09-23 09:41:55 +02:00
|
|
|
var jid = 'theplay@conference.shakespeare.lit';
|
2016-12-20 10:30:20 +01:00
|
|
|
var model = _converse.bookmarks.create({
|
2016-09-23 09:41:55 +02:00
|
|
|
'jid': jid,
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ''
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.api.rooms.open).not.toHaveBeenCalled();
|
|
|
|
_converse.bookmarks.remove(model);
|
2016-09-23 09:41:55 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.bookmarks.create({
|
2016-09-23 09:41:55 +02:00
|
|
|
'jid': jid,
|
|
|
|
'autojoin': true,
|
|
|
|
'name': 'Hamlet',
|
|
|
|
'nick': ''
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.api.rooms.open).toHaveBeenCalled();
|
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 () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be pushed from the XMPP server", mock.initConverse(function (_converse) {
|
2016-06-27 23:50:38 +02:00
|
|
|
// TODO
|
|
|
|
/* 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>
|
|
|
|
|
|
|
|
* <message from='juliet@capulet.lit'
|
|
|
|
* to='juliet@capulet.lit/chamber'
|
|
|
|
* type='headline'
|
|
|
|
* id='rnfoo2'>
|
|
|
|
* <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>
|
|
|
|
*/
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-27 23:50:38 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be retrieved from the XMPP server", mock.initConverse(function (_converse) {
|
2016-06-27 23:50:38 +02:00
|
|
|
var sent_stanza, IQ_id,
|
2016-12-20 10:30:20 +01:00
|
|
|
sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2016-06-27 23:50:38 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.emit('chatBoxesFetched');
|
2016-06-27 23:50:38 +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>
|
|
|
|
*/
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<iq from='dummy@localhost/resource' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
|
|
|
"<pubsub xmlns='http://jabber.org/protocol/pubsub'>"+
|
|
|
|
"<items node='storage:bookmarks'/>"+
|
|
|
|
"</pubsub>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
*/
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.bookmarks.models.length).toBe(0);
|
|
|
|
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
|
2016-06-27 23:50:38 +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'
|
2016-09-23 09:41:55 +02:00
|
|
|
}).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));
|
|
|
|
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);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-10-06 09:02:29 +02:00
|
|
|
|
|
|
|
describe("The rooms panel", function () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("shows a list of bookmarks", mock.initConverse(function (_converse) {
|
2016-10-06 09:02:29 +02:00
|
|
|
var IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2016-10-06 09:02:29 +02:00
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxviews.get('controlbox').$('#chatrooms dl.bookmarks').html('');
|
|
|
|
_converse.emit('chatBoxesFetched');
|
|
|
|
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',
|
|
|
|
'autojoin': 'false',
|
|
|
|
'jid': 'theplay@conference.shakespeare.lit'
|
|
|
|
}).c('nick').t('JC').up().up()
|
2016-10-06 12:48:16 +02:00
|
|
|
.c('conference', {
|
|
|
|
'name': 'Bookmark with a very very long name that will be shortened',
|
|
|
|
'autojoin': 'false',
|
|
|
|
'jid': 'theplay@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'
|
|
|
|
}).c('nick').t('JC').up().up();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-10-18 11:05:02 +02:00
|
|
|
expect($('#chatrooms dl.bookmarks dd').length).toBe(3);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-11-03 16:12:52 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("remembers the toggle state of the bookmarks list", mock.initConverse(function (_converse) {
|
2016-11-03 16:12:52 +01:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.bookmarks.create({
|
2016-11-03 16:12:52 +01:00
|
|
|
'jid': 'theplay@conference.shakespeare.lit',
|
|
|
|
'autojoin': false,
|
|
|
|
'name': 'The Play',
|
|
|
|
'nick': ''
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.emit('chatBoxesFetched');
|
|
|
|
test_utils.openControlBox().openRoomsPanel(_converse);
|
2016-11-03 16:12:52 +01:00
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function () {
|
|
|
|
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
|
2016-11-03 16:12:52 +01:00
|
|
|
$('#chatrooms .bookmarks-toggle').click();
|
|
|
|
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(0);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.CLOSED);
|
2016-11-03 16:12:52 +01:00
|
|
|
$('#chatrooms .bookmarks-toggle').click();
|
|
|
|
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
|
2016-11-03 16:12:52 +01:00
|
|
|
});
|
|
|
|
}));
|
2016-10-06 09:02:29 +02:00
|
|
|
});
|
2016-06-27 23:50:38 +02:00
|
|
|
});
|
|
|
|
}));
|