Commit a2f4acdc authored by JC Brand's avatar JC Brand

All tests suites now updated and isolated.

parent 3e409573
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
...@@ -14,7 +13,12 @@ ...@@ -14,7 +13,12 @@
describe("A chat room", function () { describe("A chat room", function () {
it("can be bookmarked", function () { afterEach(function () {
converse_api.user.logout();
test_utils.clearBrowserStorage();
});
it("can be bookmarked", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -23,7 +27,7 @@ ...@@ -23,7 +27,7 @@
}); });
spyOn(converse.connection, 'getUniqueId').andCallThrough(); spyOn(converse.connection, 'getUniqueId').andCallThrough();
test_utils.openChatRoom('theplay', 'conference.shakespeare.lit', 'JC'); test_utils.openChatRoom(converse, 'theplay', 'conference.shakespeare.lit', 'JC');
var jid = 'theplay@conference.shakespeare.lit'; var jid = 'theplay@conference.shakespeare.lit';
var view = converse.chatboxviews.get(jid); var view = converse.chatboxviews.get(jid);
spyOn(view, 'renderBookmarkForm').andCallThrough(); spyOn(view, 'renderBookmarkForm').andCallThrough();
...@@ -121,9 +125,9 @@ ...@@ -121,9 +125,9 @@
converse.connection._dataRecv(test_utils.createRequest(stanza)); converse.connection._dataRecv(test_utils.createRequest(stanza));
// We ignore this IQ stanza... (unless it's an error stanza), so // We ignore this IQ stanza... (unless it's an error stanza), so
// nothing to test for here. // nothing to test for here.
}); }));
it("will be automatically opened if 'autojoin' is set on the bookmark", function () { it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(function (converse) {
var jid = 'lounge@localhost'; var jid = 'lounge@localhost';
converse.bookmarks.create({ converse.bookmarks.create({
'jid': jid, 'jid': jid,
...@@ -141,17 +145,18 @@ ...@@ -141,17 +145,18 @@
'nick': ' Othello' 'nick': ' Othello'
}); });
expect(_.isUndefined(converse.chatboxviews.get(jid))).toBeFalsy(); expect(_.isUndefined(converse.chatboxviews.get(jid))).toBeFalsy();
}); }));
describe("when bookmarked", function () { describe("when bookmarked", function () {
beforeEach(function () {
test_utils.closeAllChatBoxes(); afterEach(function () {
converse.bookmarks.reset(); converse_api.user.logout();
test_utils.clearBrowserStorage();
}); });
it("displays that it's bookmarked through its bookmark icon", function () { it("displays that it's bookmarked through its bookmark icon", mock.initConverse(function (converse) {
runs(function () { runs(function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
}); });
waits(100); waits(100);
runs(function () { runs(function () {
...@@ -163,9 +168,9 @@ ...@@ -163,9 +168,9 @@
view.model.set('bookmarked', false); view.model.set('bookmarked', false);
expect($bookmark_icon.hasClass('button-on')).toBeFalsy(); expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
}); });
}); }));
it("can be unbookmarked", function () { it("can be unbookmarked", mock.initConverse(function (converse) {
var view, sent_stanza, IQ_id; var view, sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -175,7 +180,7 @@ ...@@ -175,7 +180,7 @@
spyOn(converse.connection, 'getUniqueId').andCallThrough(); spyOn(converse.connection, 'getUniqueId').andCallThrough();
runs(function () { runs(function () {
test_utils.openChatRoom('theplay', 'conference.shakespeare.lit', 'JC'); test_utils.openChatRoom(converse, 'theplay', 'conference.shakespeare.lit', 'JC');
}); });
waits(100); waits(100);
runs(function () { runs(function () {
...@@ -229,15 +234,16 @@ ...@@ -229,15 +234,16 @@
"</iq>" "</iq>"
); );
}); });
}); }));
}); });
describe("and when autojoin is set", function () { describe("and when autojoin is set", function () {
beforeEach(function () { afterEach(function () {
converse.bookmarks.reset(); converse_api.user.logout();
test_utils.clearBrowserStorage();
}); });
it("will be be opened and joined automatically upon login", function () { it("will be be opened and joined automatically upon login", mock.initConverse(function (converse) {
spyOn(converse_api.rooms, 'open'); spyOn(converse_api.rooms, 'open');
var jid = 'theplay@conference.shakespeare.lit'; var jid = 'theplay@conference.shakespeare.lit';
var model = converse.bookmarks.create({ var model = converse.bookmarks.create({
...@@ -256,17 +262,18 @@ ...@@ -256,17 +262,18 @@
'nick': '' 'nick': ''
}); });
expect(converse_api.rooms.open).toHaveBeenCalled(); expect(converse_api.rooms.open).toHaveBeenCalled();
}); }));
}); });
}); });
describe("Bookmarks", function () { describe("Bookmarks", function () {
beforeEach(function () { afterEach(function () {
window.sessionStorage.clear(); converse_api.user.logout();
test_utils.clearBrowserStorage();
}); });
it("can be pushed from the XMPP server", function () { it("can be pushed from the XMPP server", mock.initConverse(function (converse) {
// TODO // TODO
/* The stored data is automatically pushed to all of the user's /* The stored data is automatically pushed to all of the user's
* connected resources. * connected resources.
...@@ -311,9 +318,9 @@ ...@@ -311,9 +318,9 @@
* </event> * </event>
* </message> * </message>
*/ */
}); }));
it("can be retrieved from the XMPP server", function () { it("can be retrieved from the XMPP server", mock.initConverse(function (converse) {
var sent_stanza, IQ_id, var sent_stanza, IQ_id,
sendIQ = converse.connection.sendIQ; sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -380,21 +387,21 @@ ...@@ -380,21 +387,21 @@
expect(converse.bookmarks.models.length).toBe(2); 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': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
expect(converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false); expect(converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
}); }));
describe("The rooms panel", function () { describe("The rooms panel", function () {
beforeEach(function () { afterEach(function () {
test_utils.openRoomsPanel(); converse_api.user.logout();
converse.bookmarks.reset(); test_utils.clearBrowserStorage();
converse.chatboxviews.get('controlbox').$('#chatrooms dl.bookmarks').html('');
}); });
it("shows a list of bookmarks", function () { it("shows a list of bookmarks", mock.initConverse(function (converse) {
var IQ_id; var IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
IQ_id = sendIQ.bind(this)(iq, callback, errback); IQ_id = sendIQ.bind(this)(iq, callback, errback);
}); });
converse.chatboxviews.get('controlbox').$('#chatrooms dl.bookmarks').html('');
converse.emit('chatBoxesFetched'); converse.emit('chatBoxesFetched');
var stanza = $iq({'to': converse.connection.jid, 'type':'result', 'id':IQ_id}) var stanza = $iq({'to': converse.connection.jid, 'type':'result', 'id':IQ_id})
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB}) .c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
...@@ -418,7 +425,7 @@ ...@@ -418,7 +425,7 @@
}).c('nick').t('JC').up().up(); }).c('nick').t('JC').up().up();
converse.connection._dataRecv(test_utils.createRequest(stanza)); converse.connection._dataRecv(test_utils.createRequest(stanza));
expect($('#chatrooms dl.bookmarks dd').length).toBe(3); expect($('#chatrooms dl.bookmarks dd').length).toBe(3);
}); }));
}); });
}); });
})); }));
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
afterEach(function () { afterEach(function () {
converse_api.user.logout(); converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage(); test_utils.clearBrowserStorage();
}); });
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
...@@ -12,15 +11,21 @@ ...@@ -12,15 +11,21 @@
"use strict"; "use strict";
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
describe("Service Discovery", $.proxy(function (mock, test_utils) { describe("Service Discovery", function () {
describe("Whenever converse.js discovers a new server feature", $.proxy(function (mock, test_utils) { describe("Whenever converse.js discovers a new server feature", function () {
it("emits the serviceDiscovered event", function () { afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
it("emits the serviceDiscovered event", mock.initConverse(function (converse) {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
converse.features.create({'var': Strophe.NS.MAM}); converse.features.create({'var': Strophe.NS.MAM});
expect(converse.emit).toHaveBeenCalled(); expect(converse.emit).toHaveBeenCalled();
expect(converse.emit.argsForCall[0][1].get('var')).toBe(Strophe.NS.MAM); expect(converse.emit.argsForCall[0][1].get('var')).toBe(Strophe.NS.MAM);
}); }));
}, converse, mock, test_utils)); });
}, converse, mock, test_utils)); });
})); }));
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["mock", "test_utils"], factory);
"jquery", } (this, function (mock, test_utils) {
"mock",
"test_utils"
], function ($, mock, test_utils) {
return factory($, mock, test_utils);
}
);
} (this, function ($, mock, test_utils) {
return describe("The Converse Event Emitter", $.proxy(function(mock, test_utils) {
window.localStorage.clear();
window.sessionStorage.clear();
it("allows you to subscribe to emitted events", function () { return describe("The Converse Event Emitter", function() {
it("allows you to subscribe to emitted events", mock.initConverse(function (converse) {
this.callback = function () {}; this.callback = function () {};
spyOn(this, 'callback'); spyOn(this, 'callback');
converse.on('connected', this.callback); converse.on('connected', this.callback);
...@@ -23,9 +14,9 @@ ...@@ -23,9 +14,9 @@
expect(this.callback.callCount, 2); expect(this.callback.callCount, 2);
converse.emit('connected'); converse.emit('connected');
expect(this.callback.callCount, 3); expect(this.callback.callCount, 3);
}); }));
it("allows you to listen once for an emitted event", function () { it("allows you to listen once for an emitted event", mock.initConverse(function (converse) {
this.callback = function () {}; this.callback = function () {};
spyOn(this, 'callback'); spyOn(this, 'callback');
converse.once('connected', this.callback); converse.once('connected', this.callback);
...@@ -35,9 +26,9 @@ ...@@ -35,9 +26,9 @@
expect(this.callback.callCount, 1); expect(this.callback.callCount, 1);
converse.emit('connected'); converse.emit('connected');
expect(this.callback.callCount, 1); expect(this.callback.callCount, 1);
}); }));
it("allows you to stop listening or subscribing to an event", function () { it("allows you to stop listening or subscribing to an event", mock.initConverse(function (converse) {
this.callback = function () {}; this.callback = function () {};
this.anotherCallback = function () {}; this.anotherCallback = function () {};
this.neverCalled = function () {}; this.neverCalled = function () {};
...@@ -65,6 +56,6 @@ ...@@ -65,6 +56,6 @@
expect(this.callback.callCount, 1); expect(this.callback.callCount, 1);
expect(this.anotherCallback.callCount, 3); expect(this.anotherCallback.callCount, 3);
expect(this.neverCalled).not.toHaveBeenCalled(); expect(this.neverCalled).not.toHaveBeenCalled();
}); }));
}, converse, mock, test_utils)); });
})); }));
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
...@@ -13,12 +12,12 @@ ...@@ -13,12 +12,12 @@
describe("A headlines box", function () { describe("A headlines box", function () {
beforeEach(function () { afterEach(function () {
test_utils.openControlBox(); converse_api.user.logout();
test_utils.openContactsPanel(); test_utils.clearBrowserStorage();
}); });
it("will not open nor display non-headline messages", function () { it("will not open nor display non-headline messages", mock.initConverse(function (converse) {
/* XMPP spam message: /* XMPP spam message:
* *
* <message xmlns="jabber:client" * <message xmlns="jabber:client"
...@@ -29,6 +28,8 @@ ...@@ -29,6 +28,8 @@
* <body>SORRY FOR THIS ADVERT</body * <body>SORRY FOR THIS ADVERT</body
* </message * </message
*/ */
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
sinon.spy(utils, 'isHeadlineMessage'); sinon.spy(utils, 'isHeadlineMessage');
runs(function () { runs(function () {
var stanza = $msg({ var stanza = $msg({
...@@ -47,11 +48,10 @@ ...@@ -47,11 +48,10 @@
expect(utils.isHeadlineMessage.returned(false)).toBeTruthy(); expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
utils.isHeadlineMessage.restore(); utils.isHeadlineMessage.restore();
}); });
}));
});
it("will open and display headline messages", function () { it("will open and display headline messages", mock.initConverse(function (converse) {
/* /*
* <message from='notify.example.com' * <message from='notify.example.com'
* to='romeo@im.example.com' * to='romeo@im.example.com'
...@@ -66,6 +66,8 @@ ...@@ -66,6 +66,8 @@
* </x> * </x>
* </message> * </message>
*/ */
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
sinon.spy(utils, 'isHeadlineMessage'); sinon.spy(utils, 'isHeadlineMessage');
runs(function () { runs(function () {
var stanza = $msg({ var stanza = $msg({
...@@ -91,6 +93,6 @@ ...@@ -91,6 +93,6 @@
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy(); expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
utils.isHeadlineMessage.restore(); // unwraps utils.isHeadlineMessage.restore(); // unwraps
}); });
}); }));
}); });
})); }));
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["mock", "test_utils"], factory);
"jquery", } (this, function (mock, test_utils) {
"underscore",
"mock",
"test_utils"
], function ($, _, mock, test_utils) {
return factory($, _, mock, test_utils);
}
);
} (this, function ($, _, mock, test_utils) {
"use strict"; "use strict";
var _ = converse_api.env._;
var $ = converse_api.env.jQuery;
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
var $msg = converse_api.env.$msg; var $msg = converse_api.env.$msg;
var moment = converse_api.env.moment; var moment = converse_api.env.moment;
// See: https://xmpp.org/rfcs/rfc3921.html // See: https://xmpp.org/rfcs/rfc3921.html
describe("Message Archive Management", $.proxy(function (mock, test_utils) { describe("Message Archive Management", function () {
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config // Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
describe("The archive.query API", $.proxy(function (mock, test_utils) { describe("The archive.query API", function () {
it("can be used to query for all archived messages", function () { afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
it("can be used to query for all archived messages", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -36,9 +35,9 @@ ...@@ -36,9 +35,9 @@
var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
expect(sent_stanza.toString()).toBe( expect(sent_stanza.toString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'><query xmlns='urn:xmpp:mam:0' queryid='"+queryid+"'/></iq>"); "<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'><query xmlns='urn:xmpp:mam:0' queryid='"+queryid+"'/></iq>");
}); }));
it("can be used to query for all messages to/from a particular JID", function () { it("can be used to query for all messages to/from a particular JID", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -64,9 +63,9 @@ ...@@ -64,9 +63,9 @@
"</query>"+ "</query>"+
"</iq>" "</iq>"
); );
}); }));
it("can be used to query for all messages in a certain timespan", function () { it("can be used to query for all messages in a certain timespan", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -101,15 +100,18 @@ ...@@ -101,15 +100,18 @@
"</query>"+ "</query>"+
"</iq>" "</iq>"
); );
}); }));
it("throws a TypeError if an invalid date is provided", function () { it("throws a TypeError if an invalid date is provided", mock.initConverse(function (converse) {
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
}
expect(_.partial(converse_api.archive.query, {'start': 'not a real date'})).toThrow( expect(_.partial(converse_api.archive.query, {'start': 'not a real date'})).toThrow(
new TypeError('archive.query: invalid date provided for: start') new TypeError('archive.query: invalid date provided for: start')
); );
}); }));
it("can be used to query for all messages after a certain time", function () { it("can be used to query for all messages after a certain time", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -136,9 +138,9 @@ ...@@ -136,9 +138,9 @@
"</query>"+ "</query>"+
"</iq>" "</iq>"
); );
}); }));
it("can be used to query for a limited set of results", function () { it("can be used to query for a limited set of results", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -168,9 +170,9 @@ ...@@ -168,9 +170,9 @@
"</query>"+ "</query>"+
"</iq>" "</iq>"
); );
}); }));
it("can be used to page through results", function () { it("can be used to page through results", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -205,9 +207,9 @@ ...@@ -205,9 +207,9 @@
"</query>"+ "</query>"+
"</iq>" "</iq>"
); );
}); }));
it("accepts \"before\" with an empty string as value to reverse the order", function () { it("accepts \"before\" with an empty string as value to reverse the order", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -234,9 +236,9 @@ ...@@ -234,9 +236,9 @@
"</query>"+ "</query>"+
"</iq>" "</iq>"
); );
}); }));
it("accepts a Strophe.RSM object for the query options", function () { it("accepts a Strophe.RSM object for the query options", mock.initConverse(function (converse) {
// Normally the user wouldn't manually make a Strophe.RSM object // Normally the user wouldn't manually make a Strophe.RSM object
// and pass it in. However, in the callback method an RSM object is // and pass it in. However, in the callback method an RSM object is
// returned which can be reused for easy paging. This test is // returned which can be reused for easy paging. This test is
...@@ -276,9 +278,9 @@ ...@@ -276,9 +278,9 @@
"</query>"+ "</query>"+
"</iq>" "</iq>"
); );
}); }));
it("accepts a callback function, which it passes the messages and a Strophe.RSM object", function () { it("accepts a callback function, which it passes the messages and a Strophe.RSM object", mock.initConverse(function (converse) {
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM}); converse.features.create({'var': Strophe.NS.MAM});
} }
...@@ -365,13 +367,19 @@ ...@@ -365,13 +367,19 @@
expect(args[1].count).toBe('16'); expect(args[1].count).toBe('16');
expect(args[1].first).toBe('23452-4534-1'); expect(args[1].first).toBe('23452-4534-1');
expect(args[1].last).toBe('390-2342-22'); expect(args[1].last).toBe('390-2342-22');
}); }));
}, converse, mock, test_utils)); });
describe("The default preference", $.proxy(function (mock, test_utils) { describe("The default preference", function () {
it("is set once server support for MAM has been confirmed", function () { afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
it("is set once server support for MAM has been confirmed", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -443,7 +451,7 @@ ...@@ -443,7 +451,7 @@
// Restore // Restore
converse.message_archiving = 'never'; converse.message_archiving = 'never';
}); }));
}, converse, mock, test_utils)); });
}, converse, mock, test_utils)); });
})); }));
This diff is collapsed.
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["mock", "test_utils"], factory);
"jquery", } (this, function (mock, test_utils) {
"underscore",
"mock",
"test_utils"
], function ($, _, mock, test_utils) {
return factory($, _, mock, test_utils);
}
);
} (this, function ($, _, mock, test_utils) {
"use strict"; "use strict";
var $msg = converse_api.env.$msg; var $msg = converse_api.env.$msg;
describe("Notifications", function () { describe("Notifications", function () {
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config // Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
beforeEach(function () {
runs(function () {
test_utils.closeAllChatBoxes();
test_utils.createContacts('current');
});
});
describe("When show_desktop_notifications is set to true", function () { describe("When show_desktop_notifications is set to true", function () {
describe("And the desktop is not focused", function () { describe("And the desktop is not focused", function () {
describe("an HTML5 Notification", function () { describe("an HTML5 Notification", function () {
afterEach(function () {
converse_api.user.logout();
test_utils.clearBrowserStorage();
});
it("is shown when a new private message is received", function () { it("is shown when a new private message is received", mock.initConverse(function (converse) {
// TODO: not yet testing show_desktop_notifications setting // TODO: not yet testing show_desktop_notifications setting
test_utils.createContacts(converse, 'current');
spyOn(converse, 'showMessageNotification'); spyOn(converse, 'showMessageNotification');
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true); spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
...@@ -43,10 +33,11 @@ ...@@ -43,10 +33,11 @@
converse.chatboxes.onMessage(msg); // This will emit 'message' converse.chatboxes.onMessage(msg); // This will emit 'message'
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled(); expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(converse.showMessageNotification).toHaveBeenCalled(); expect(converse.showMessageNotification).toHaveBeenCalled();
}); }));
it("is shown when you are mentioned in a chat room", function () { it("is shown when you are mentioned in a chat room", mock.initConverse(function (converse) {
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy'); test_utils.createContacts(converse, 'current');
test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost'); var view = converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var no_notification = false; var no_notification = false;
...@@ -75,39 +66,46 @@ ...@@ -75,39 +66,46 @@
if (no_notification) { if (no_notification) {
delete window.Notification; delete window.Notification;
} }
}); }));
it("is shown when a user changes their chat state", function () { it("is shown when a user changes their chat state", mock.initConverse(function (converse) {
// TODO: not yet testing show_desktop_notifications setting // TODO: not yet testing show_desktop_notifications setting
test_utils.createContacts(converse, 'current');
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true); spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(converse, 'showChatStateNotification'); spyOn(converse, 'showChatStateNotification');
var jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost'; var jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
converse.roster.get(jid).set('chat_status', 'busy'); // This will emit 'contactStatusChanged' converse.roster.get(jid).set('chat_status', 'busy'); // This will emit 'contactStatusChanged'
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled(); expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(converse.showChatStateNotification).toHaveBeenCalled(); expect(converse.showChatStateNotification).toHaveBeenCalled();
}); }));
}); });
}); });
describe("When a new contact request is received", function () { describe("When a new contact request is received", function () {
it("an HTML5 Notification is received", function () { it("an HTML5 Notification is received", mock.initConverse(function (converse) {
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true); spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(converse, 'showContactRequestNotification'); spyOn(converse, 'showContactRequestNotification');
converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'}); converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled(); expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(converse.showContactRequestNotification).toHaveBeenCalled(); expect(converse.showContactRequestNotification).toHaveBeenCalled();
}); }));
}); });
}); });
describe("When play_sounds is set to true", function () { describe("When play_sounds is set to true", function () {
describe("A notification sound", function () { describe("A notification sound", function () {
it("is played when the current user is mentioned in a chat room", function () { afterEach(function () {
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy'); converse_api.user.logout();
test_utils.clearBrowserStorage();
});
it("is played when the current user is mentioned in a chat room", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
converse.play_sounds = true; converse.play_sounds = true;
spyOn(converse, 'playSoundNotification'); spyOn(converse, 'playSoundNotification');
var view = this.chatboxviews.get('lounge@localhost'); var view = converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var text = 'This message will play a sound because it mentions dummy'; var text = 'This message will play a sound because it mentions dummy';
var message = $msg({ var message = $msg({
...@@ -140,7 +138,7 @@ ...@@ -140,7 +138,7 @@
view.onChatRoomMessage(message.nodeTree); view.onChatRoomMessage(message.nodeTree);
expect(converse.playSoundNotification, 1); expect(converse.playSoundNotification, 1);
converse.play_sounds = false; converse.play_sounds = false;
}.bind(converse)); }));
}); });
}); });
}); });
......
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["mock","test_utils" ], factory);
"jquery", } (this, function (mock, test_utils) {
"mock", var $ = converse_api.env.jQuery;
"test_utils"
], function ($, mock, test_utils) {
return factory($, mock, test_utils);
}
);
} (this, function ($, mock, test_utils) {
var Strophe = converse_api.env.Strophe; var Strophe = converse_api.env.Strophe;
var b64_sha1 = converse_api.env.b64_sha1; var b64_sha1 = converse_api.env.b64_sha1;
return describe("The OTR module", function() { return describe("The OTR module", function() {
beforeEach(function () { afterEach(function () {
test_utils.openControlBox(); converse_api.user.logout();
test_utils.openContactsPanel(); test_utils.clearBrowserStorage();
test_utils.createContacts('current');
}); });
it("can store a session passphrase in session storage", function () { it("can store a session passphrase in session storage", mock.initConverse(function (converse) {
// With no prebind, the user's XMPP password is used and nothing is // With no prebind, the user's XMPP password is used and nothing is
// stored in session storage. // stored in session storage.
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.createContacts(converse, 'current');
var auth = converse.authentication; var auth = converse.authentication;
var pass = converse.connection.pass; var pass = converse.connection.pass;
converse.authentication = "manual"; converse.authentication = "manual";
...@@ -38,13 +34,17 @@ ...@@ -38,13 +34,17 @@
// Clean up // Clean up
converse.authentication = auth; converse.authentication = auth;
converse.connection.pass = pass; converse.connection.pass = pass;
}); }));
it("will add processing hints to sent out encrypted <message> stanzas", mock.initConverse(function (converse) {
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.createContacts(converse, 'current');
it("will add processing hints to sent out encrypted <message> stanzas", function () {
var UNVERIFIED = 1, UNENCRYPTED = 0; var UNVERIFIED = 1, UNENCRYPTED = 0;
var contact_name = mock.cur_names[0]; var contact_name = mock.cur_names[0];
var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost'; var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(contact_jid); test_utils.openChatBoxFor(converse, contact_jid);
var chatview = converse.chatboxviews.get(contact_jid); var chatview = converse.chatboxviews.get(contact_jid);
chatview.model.set('otr_status', UNVERIFIED); chatview.model.set('otr_status', UNVERIFIED);
var stanza = chatview.createMessageStanza(new converse.Message({ message: 'hello world'})); var stanza = chatview.createMessageStanza(new converse.Message({ message: 'hello world'}));
...@@ -54,11 +54,15 @@ ...@@ -54,11 +54,15 @@
expect($hints.get(1).tagName).toBe('no-permanent-store'); expect($hints.get(1).tagName).toBe('no-permanent-store');
expect($hints.get(2).tagName).toBe('no-copy'); expect($hints.get(2).tagName).toBe('no-copy');
chatview.model.set('otr_status', UNENCRYPTED); // Reset again to UNENCRYPTED chatview.model.set('otr_status', UNENCRYPTED); // Reset again to UNENCRYPTED
}); }));
describe("An OTR Chat Message", function () { describe("An OTR Chat Message", function () {
it("will not be carbon copied when it's sent out", function () { it("will not be carbon copied when it's sent out", mock.initConverse(function (converse) {
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.createContacts(converse, 'current');
var msgtext = "?OTR,1,3,?OTR:AAIDAAAAAAEAAAABAAAAwCQ8HKsag0y0DGKsneo0kzKu1ua5L93M4UKTkCf1I2kbm2RgS5kIxDTxrTj3wVRB+H5Si86E1fKtuBgsDf/bKkGTM0h/49vh5lOD9HkE8cnSrFEn5GN,"; var msgtext = "?OTR,1,3,?OTR:AAIDAAAAAAEAAAABAAAAwCQ8HKsag0y0DGKsneo0kzKu1ua5L93M4UKTkCf1I2kbm2RgS5kIxDTxrTj3wVRB+H5Si86E1fKtuBgsDf/bKkGTM0h/49vh5lOD9HkE8cnSrFEn5GN,";
var sender_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost'; var sender_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
converse_api.chats.open(sender_jid); converse_api.chats.open(sender_jid);
...@@ -71,7 +75,7 @@ ...@@ -71,7 +75,7 @@
expect($sent.find('private').length).toBe(1); expect($sent.find('private').length).toBe(1);
expect($sent.find('private').attr('xmlns')).toBe('urn:xmpp:carbons:2'); expect($sent.find('private').attr('xmlns')).toBe('urn:xmpp:carbons:2');
chatbox.set('otr_status', 0); // Reset again to UNENCRYPTED chatbox.set('otr_status', 0); // Reset again to UNENCRYPTED
}); }));
}); });
}); });
})); }));
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["mock", "test_utils", "converse-ping"], factory);
"jquery", } (this, function (mock, test_utils) {
"converse-ping"
], function ($) {
return factory($);
}
);
} (this, function ($) {
"use strict"; "use strict";
describe("XMPP Ping", function () { describe("XMPP Ping", function () {
describe("Ping and pong handlers", function () { describe("Ping and pong handlers", function () {
it("are registered when converse.js is connected", function () { afterEach(function () {
converse_api.user.logout();
test_utils.clearBrowserStorage();
});
it("are registered when converse.js is connected", mock.initConverse(function (converse) {
spyOn(converse, 'registerPingHandler').andCallThrough(); spyOn(converse, 'registerPingHandler').andCallThrough();
spyOn(converse, 'registerPongHandler').andCallThrough(); spyOn(converse, 'registerPongHandler').andCallThrough();
converse.emit('connected'); converse.emit('connected');
expect(converse.registerPingHandler).toHaveBeenCalled(); expect(converse.registerPingHandler).toHaveBeenCalled();
expect(converse.registerPongHandler).toHaveBeenCalled(); expect(converse.registerPongHandler).toHaveBeenCalled();
}); }));
it("are registered when converse.js reconnected", function () { it("are registered when converse.js reconnected", mock.initConverse(function (converse) {
spyOn(converse, 'registerPingHandler').andCallThrough(); spyOn(converse, 'registerPingHandler').andCallThrough();
spyOn(converse, 'registerPongHandler').andCallThrough(); spyOn(converse, 'registerPongHandler').andCallThrough();
converse.emit('reconnected'); converse.emit('reconnected');
expect(converse.registerPingHandler).toHaveBeenCalled(); expect(converse.registerPingHandler).toHaveBeenCalled();
expect(converse.registerPongHandler).toHaveBeenCalled(); expect(converse.registerPongHandler).toHaveBeenCalled();
}); }));
}); });
describe("An IQ stanza", function () { describe("An IQ stanza", function () {
it("is sent out when converse.js pings a server", function () { afterEach(function () {
converse_api.user.logout();
test_utils.clearBrowserStorage();
});
it("is sent out when converse.js pings a server", mock.initConverse(function (converse) {
var sent_stanza, IQ_id; var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ; var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
...@@ -42,7 +45,7 @@ ...@@ -42,7 +45,7 @@
"<iq type='get' to='localhost' id='"+IQ_id+"' xmlns='jabber:client'>"+ "<iq type='get' to='localhost' id='"+IQ_id+"' xmlns='jabber:client'>"+
"<ping xmlns='urn:xmpp:ping'/>"+ "<ping xmlns='urn:xmpp:ping'/>"+
"</iq>"); "</iq>");
}); }));
}); });
}); });
})); }));
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["mock", "test_utils"], factory);
"jquery", } (this, function (mock, test_utils) {
"underscore", var _ = converse_api.env._;
"mock",
"test_utils"
], function ($, _, mock, test_utils) {
return factory($, _, mock, test_utils);
}
);
} (this, function ($, _, mock, test_utils) {
var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq; var $iq = converse_api.env.$iq;
describe("Profiling", function() { describe("Profiling", function() {
beforeEach(function() { afterEach(function () {
converse_api.user.logout();
test_utils.clearBrowserStorage(); test_utils.clearBrowserStorage();
converse.rosterview.model.reset();
converse.connection._changeConnectStatus(Strophe.Status.CONNECTED);
}); });
xit("adds hundreds of contacts to the roster", $.proxy(function() { xit("adds hundreds of contacts to the roster", mock.initConverse(function(converse) {
converse.roster_groups = false; converse.roster_groups = false;
expect(this.roster.pluck('jid').length).toBe(0); expect(this.roster.pluck('jid').length).toBe(0);
var stanza = $iq({ var stanza = $iq({
...@@ -41,9 +31,9 @@ ...@@ -41,9 +31,9 @@
}); });
this.roster.onReceivedFromServer(stanza.tree()); this.roster.onReceivedFromServer(stanza.tree());
// expect(this.roster.pluck('jid').length).toBe(400); // expect(this.roster.pluck('jid').length).toBe(400);
}, converse)); }));
xit("adds hundreds of contacts to the roster, with roster groups", $.proxy(function() { xit("adds hundreds of contacts to the roster, with roster groups", mock.initConverse(function(converse) {
// converse.show_only_online_users = true; // converse.show_only_online_users = true;
converse.roster_groups = true; converse.roster_groups = true;
expect(this.roster.pluck('jid').length).toBe(0); expect(this.roster.pluck('jid').length).toBe(0);
...@@ -65,6 +55,6 @@ ...@@ -65,6 +55,6 @@
}); });
this.roster.onReceivedFromServer(stanza.tree()); this.roster.onReceivedFromServer(stanza.tree());
//expect(this.roster.pluck('jid').length).toBe(400); //expect(this.roster.pluck('jid').length).toBe(400);
}, converse)); }));
}); });
})); }));
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
afterEach(function () { afterEach(function () {
converse_api.user.logout(); converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage(); test_utils.clearBrowserStorage();
}); });
......
This diff is collapsed.
/*global converse */
(function (root, factory) { (function (root, factory) {
define([ define(["mock", "test_utils"], factory);
"jquery", } (this, function (mock, test_utils) {
"mock", var $ = converse_api.env.jQuery;
"test_utils"
], function ($, mock, test_utils) { return describe("The XMPPStatus model", function() {
return factory($, mock, test_utils); afterEach(function () {
} converse_api.user.logout();
); test_utils.clearBrowserStorage();
} (this, function ($, mock, test_utils) { });
return describe("The XMPPStatus model", $.proxy(function(mock, test_utils) {
beforeEach($.proxy(function () { it("won't send <show>online when setting a custom status message", mock.initConverse(function (converse) {
window.localStorage.clear(); converse.xmppstatus.save({'status': 'online'});
window.sessionStorage.clear(); spyOn(converse.xmppstatus, 'setStatusMessage').andCallThrough();
}, converse));
it("won't send <show>online when setting a custom status message", $.proxy(function () {
this.xmppstatus.save({'status': 'online'});
spyOn(this.xmppstatus, 'setStatusMessage').andCallThrough();
spyOn(converse.connection, 'send'); spyOn(converse.connection, 'send');
this.xmppstatus.setStatusMessage("I'm also happy!"); converse.xmppstatus.setStatusMessage("I'm also happy!");
runs (function () { runs (function () {
expect(converse.connection.send).toHaveBeenCalled(); expect(converse.connection.send).toHaveBeenCalled();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree()); var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children().length).toBe(1); expect($stanza.children().length).toBe(1);
expect($stanza.children('show').length).toBe(0); expect($stanza.children('show').length).toBe(0);
}); });
}, converse)); }));
}, converse, mock, test_utils)); });
})); }));
...@@ -164,11 +164,13 @@ ...@@ -164,11 +164,13 @@
callback = options; callback = options;
errback = callback; errback = callback;
} }
/*
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) { if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.log('This server does not support XEP-0313, Message Archive Management'); converse.log('This server does not support XEP-0313, Message Archive Management');
errback(null); errback(null);
return; return;
} }
*/
var queryid = converse.connection.getUniqueId(); var queryid = converse.connection.getUniqueId();
var attrs = {'type':'set'}; var attrs = {'type':'set'};
if (typeof options !== "undefined" && options.groupchat) { if (typeof options !== "undefined" && options.groupchat) {
......
...@@ -10,6 +10,14 @@ ...@@ -10,6 +10,14 @@
<link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" /> <link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" />
<script src="config.js"></script> <script src="config.js"></script>
<script data-main="tests/main" src="node_modules/requirejs/require.js"></script> <script data-main="tests/main" src="node_modules/requirejs/require.js"></script>
<style>
body {
background-color: lightgoldenrodyellow;
}
h2 {
color: darkgray;
}
</style>
</head> </head>
<body> <body>
......
...@@ -50,13 +50,10 @@ require([ ...@@ -50,13 +50,10 @@ require([
//"spec/transcripts", //"spec/transcripts",
"spec/utils", "spec/utils",
"spec/converse", "spec/converse",
/*
"spec/bookmarks", "spec/bookmarks",
"spec/headline", "spec/headline",
"spec/disco", "spec/disco",
*/
"spec/protocol", "spec/protocol",
/*
"spec/mam", "spec/mam",
"spec/otr", "spec/otr",
"spec/eventemitter", "spec/eventemitter",
...@@ -68,8 +65,7 @@ require([ ...@@ -68,8 +65,7 @@ require([
"spec/profiling", "spec/profiling",
"spec/ping", "spec/ping",
"spec/register", "spec/register",
"spec/xmppstatus", "spec/xmppstatus"
*/
], function () { ], function () {
// Jasmine stuff // Jasmine stuff
var jasmineEnv = jasmine.getEnv(); var jasmineEnv = jasmine.getEnv();
......
...@@ -75,9 +75,9 @@ ...@@ -75,9 +75,9 @@
}; };
}(); }();
mock.initConverse = function (func) { mock.initConverse = function (func, settings) {
return function () { return function () {
var converse = converse_api.initialize({ var converse = converse_api.initialize(_.extend({
i18n: window.locales.en, i18n: window.locales.en,
auto_subscribe: false, auto_subscribe: false,
bosh_service_url: 'localhost', bosh_service_url: 'localhost',
...@@ -86,9 +86,8 @@ ...@@ -86,9 +86,8 @@
no_trimming: true, no_trimming: true,
auto_login: true, auto_login: true,
jid: 'dummy@localhost', jid: 'dummy@localhost',
password: 'secret', password: 'secret'
debug: true }, settings || {}));
});
converse.ChatBoxViews.prototype.trimChat = function () {}; converse.ChatBoxViews.prototype.trimChat = function () {};
return func(converse); return func(converse);
}; };
......
...@@ -79,14 +79,14 @@ ...@@ -79,14 +79,14 @@
$tabs.find('li').first().find('a').click(); $tabs.find('li').first().find('a').click();
}; };
utils.openRoomsPanel = function () { utils.openRoomsPanel = function (converse) {
utils.openControlBox(); utils.openControlBox();
var cbview = converse.chatboxviews.get('controlbox'); var cbview = converse.chatboxviews.get('controlbox');
var $tabs = cbview.$el.find('#controlbox-tabs'); var $tabs = cbview.$el.find('#controlbox-tabs');
$tabs.find('li').last().find('a').click(); $tabs.find('li').last().find('a').click();
}; };
utils.openChatBoxes = function (amount) { utils.openChatBoxes = function (converse, amount) {
var i = 0, jid, views = []; var i = 0, jid, views = [];
for (i; i<amount; i++) { for (i; i<amount; i++) {
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost'; jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
...@@ -99,25 +99,25 @@ ...@@ -99,25 +99,25 @@
return converse.roster.get(jid).trigger("open"); return converse.roster.get(jid).trigger("open");
}; };
utils.openChatRoom = function (room, server, nick) { utils.openChatRoom = function (converse, room, server, nick) {
// Open a new chatroom // Open a new chatroom
this.openControlBox(); this.openControlBox(converse);
this.openRoomsPanel(); this.openRoomsPanel(converse);
var roomspanel = converse.chatboxviews.get('controlbox').roomspanel; var roomspanel = converse.chatboxviews.get('controlbox').roomspanel;
roomspanel.$el.find('input.new-chatroom-name').val(room); roomspanel.$el.find('input.new-chatroom-name').val(room);
roomspanel.$el.find('input.new-chatroom-nick').val(nick); roomspanel.$el.find('input.new-chatroom-nick').val(nick);
roomspanel.$el.find('input.new-chatroom-server').val(server); roomspanel.$el.find('input.new-chatroom-server').val(server);
roomspanel.$el.find('form').submit(); roomspanel.$el.find('form').submit();
this.closeControlBox(); this.closeControlBox(converse);
}; };
utils.openAndEnterChatRoom = function (room, server, nick) { utils.openAndEnterChatRoom = function (converse, room, server, nick) {
var IQ_id, sendIQ = converse.connection.sendIQ; var IQ_id, sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
IQ_id = sendIQ.bind(this)(iq, callback, errback); IQ_id = sendIQ.bind(this)(iq, callback, errback);
}); });
utils.openChatRoom(room, server); utils.openChatRoom(converse, room, server);
var view = converse.chatboxviews.get(room+'@'+server); var view = converse.chatboxviews.get(room+'@'+server);
// The XMPP server returns the reserved nick for this user. // The XMPP server returns the reserved nick for this user.
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
return this; return this;
}; };
utils.clearChatBoxMessages = function (jid) { utils.clearChatBoxMessages = function (converse, jid) {
var view = converse.chatboxviews.get(jid); var view = converse.chatboxviews.get(jid);
view.$el.find('.chat-content').empty(); view.$el.find('.chat-content').empty();
view.model.messages.reset(); view.model.messages.reset();
...@@ -190,7 +190,9 @@ ...@@ -190,7 +190,9 @@
requesting = false; requesting = false;
ask = null; ask = null;
} else if (type === 'all') { } else if (type === 'all') {
this.createContacts('current').createContacts('requesting').createContacts('pending'); this.createContacts(converse, 'current')
.createContacts(converse, 'requesting')
.createContacts(converse, 'pending');
return this; return this;
} else { } else {
throw "Need to specify the type of contact to create"; throw "Need to specify the type of contact to create";
...@@ -214,7 +216,7 @@ ...@@ -214,7 +216,7 @@
return this; return this;
}; };
utils.createGroupedContacts = function () { utils.createGroupedContacts = function (converse) {
/* Create grouped contacts /* Create grouped contacts
*/ */
var i=0, j=0; var i=0, j=0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment