|
@@ -54,15 +54,29 @@
|
|
|
test_utils.createContacts('current');
|
|
|
}, converse));
|
|
|
|
|
|
- it("has a method 'get' which returns a wrapped contact", $.proxy(function () {
|
|
|
- // TODO: test multiple JIDs passed in
|
|
|
- var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
+ it("has a method 'get' which returns wrapped contacts", $.proxy(function () {
|
|
|
+ // Check that it returns nothing if a non-existing JID is given
|
|
|
expect(converse_api.contacts.get('non-existing@jabber.org')).toBeFalsy();
|
|
|
+
|
|
|
+ // Check when a single jid is given
|
|
|
+ var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
var attrs = converse_api.contacts.get(jid);
|
|
|
expect(typeof attrs).toBe('object');
|
|
|
expect(attrs.fullname).toBe(mock.cur_names[0]);
|
|
|
expect(attrs.jid).toBe(jid);
|
|
|
+
|
|
|
+ // You can retrieve multiple contacts by passing in an array
|
|
|
+ var jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
+ var list = converse_api.contacts.get([jid, jid2]);
|
|
|
+ expect(Array.isArray(list)).toBeTruthy();
|
|
|
+ expect(list[0].fullname).toBe(mock.cur_names[0]);
|
|
|
+ expect(list[1].fullname).toBe(mock.cur_names[1]);
|
|
|
+
|
|
|
+ // Check that all JIDs are returned if you call without any parameters
|
|
|
+ list = converse_api.contacts.get();
|
|
|
+ expect(list.length).toBe(mock.cur_names.length);
|
|
|
}, converse));
|
|
|
+
|
|
|
}, converse));
|
|
|
|
|
|
describe("The \"chats\" API", $.proxy(function() {
|
|
@@ -73,17 +87,49 @@
|
|
|
test_utils.createContacts('current');
|
|
|
}, converse));
|
|
|
|
|
|
- it("has a method 'get' which returns a wrapped chat box object", $.proxy(function () {
|
|
|
- // TODO: test multiple JIDs passed in
|
|
|
- // FIXME: when a non-existing chat box is "get(ted)", it's
|
|
|
- // opened, which we don't want...
|
|
|
- expect(converse_api.chats.get('non-existing@jabber.org')).toBeFalsy(); // test on user that doesn't exist.
|
|
|
+ it("has a method 'get' which returns a wrapped chat box if it's already open", $.proxy(function () {
|
|
|
+ // Test on chat that doesn't exist.
|
|
|
+ expect(converse_api.chats.get('non-existing@jabber.org')).toBeFalsy();
|
|
|
+
|
|
|
+ // Test on chat that's not open
|
|
|
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
var box = converse_api.chats.get(jid);
|
|
|
+ expect(box).toBe(null);
|
|
|
+
|
|
|
+ // Test for single JID
|
|
|
+ test_utils.openChatBoxFor(jid);
|
|
|
+ box = converse_api.chats.get(jid);
|
|
|
+ expect(box instanceof Object).toBeTruthy();
|
|
|
+ expect(box.get('box_id')).toBe(b64_sha1(jid));
|
|
|
+ var chatboxview = this.chatboxviews.get(jid);
|
|
|
+ expect(chatboxview.$el.is(':visible')).toBeTruthy();
|
|
|
+
|
|
|
+ // Test for multiple JIDs
|
|
|
+ var jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
+ test_utils.openChatBoxFor(jid2);
|
|
|
+ var list = converse_api.chats.get([jid, jid2]);
|
|
|
+ expect(Array.isArray(list)).toBeTruthy();
|
|
|
+ expect(list[0].get('box_id')).toBe(b64_sha1(jid));
|
|
|
+ expect(list[1].get('box_id')).toBe(b64_sha1(jid2));
|
|
|
+ }, converse));
|
|
|
+
|
|
|
+ it("has a method 'open' which opens and returns a wrapped chat box", $.proxy(function () {
|
|
|
+ // Test on chat that doesn't exist.
|
|
|
+ expect(converse_api.chats.get('non-existing@jabber.org')).toBeFalsy();
|
|
|
+
|
|
|
+ var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
+ var box = converse_api.chats.open(jid);
|
|
|
expect(box instanceof Object).toBeTruthy();
|
|
|
expect(box.get('box_id')).toBe(b64_sha1(jid));
|
|
|
var chatboxview = this.chatboxviews.get(jid);
|
|
|
expect(chatboxview.$el.is(':visible')).toBeTruthy();
|
|
|
+
|
|
|
+ // Test for multiple JIDs
|
|
|
+ var jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
+ var list = converse_api.chats.open([jid, jid2]);
|
|
|
+ expect(Array.isArray(list)).toBeTruthy();
|
|
|
+ expect(list[0].get('box_id')).toBe(b64_sha1(jid));
|
|
|
+ expect(list[1].get('box_id')).toBe(b64_sha1(jid2));
|
|
|
}, converse));
|
|
|
}, converse));
|
|
|
|