|
@@ -23,6 +23,137 @@
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ describe("The \"rooms\" API", function () {
|
|
|
|
+ beforeEach(function () {
|
|
|
|
+ test_utils.closeAllChatBoxes();
|
|
|
|
+ test_utils.clearBrowserStorage();
|
|
|
|
+ converse.rosterview.model.reset();
|
|
|
|
+ test_utils.createContacts('current');
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it("has a method 'close' which closes rooms by JID or all rooms when called with no arguments", function () {
|
|
|
|
+ runs(function () {
|
|
|
|
+ test_utils.openChatRoom('lounge', 'localhost', 'dummy');
|
|
|
|
+ test_utils.openChatRoom('leisure', 'localhost', 'dummy');
|
|
|
|
+ test_utils.openChatRoom('news', 'localhost', 'dummy');
|
|
|
|
+ expect(converse.chatboxviews.get('lounge@localhost').$el.is(':visible')).toBeTruthy();
|
|
|
|
+ expect(converse.chatboxviews.get('leisure@localhost').$el.is(':visible')).toBeTruthy();
|
|
|
|
+ expect(converse.chatboxviews.get('news@localhost').$el.is(':visible')).toBeTruthy();
|
|
|
|
+ });
|
|
|
|
+ waits('100');
|
|
|
|
+ runs(function () {
|
|
|
|
+ converse_api.rooms.close('lounge@localhost');
|
|
|
|
+ expect(converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
|
|
|
|
+ expect(converse.chatboxviews.get('leisure@localhost').$el.is(':visible')).toBeTruthy();
|
|
|
|
+ expect(converse.chatboxviews.get('news@localhost').$el.is(':visible')).toBeTruthy();
|
|
|
|
+ converse_api.rooms.close(['leisure@localhost', 'news@localhost']);
|
|
|
|
+ expect(converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
|
|
|
|
+ expect(converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
|
|
|
|
+ expect(converse.chatboxviews.get('news@localhost')).toBeUndefined();
|
|
|
|
+
|
|
|
|
+ test_utils.openChatRoom('lounge', 'localhost', 'dummy');
|
|
|
|
+ test_utils.openChatRoom('leisure', 'localhost', 'dummy');
|
|
|
|
+ expect(converse.chatboxviews.get('lounge@localhost').$el.is(':visible')).toBeTruthy();
|
|
|
|
+ expect(converse.chatboxviews.get('leisure@localhost').$el.is(':visible')).toBeTruthy();
|
|
|
|
+ });
|
|
|
|
+ waits('100');
|
|
|
|
+ runs(function () {
|
|
|
|
+ converse_api.rooms.close();
|
|
|
|
+ expect(converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
|
|
|
|
+ expect(converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it("has a method 'get' which returns a wrapped chat room (if it exists)", function () {
|
|
|
|
+ waits('300'); // ChatBox.show() is debounced for 250ms
|
|
|
|
+ runs(function () {
|
|
|
|
+ test_utils.openChatRoom('lounge', 'localhost', 'dummy');
|
|
|
|
+ var jid = 'lounge@localhost';
|
|
|
|
+ var room = converse_api.rooms.get(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ expect(room.is_chatroom).toBeTruthy();
|
|
|
|
+ var chatroomview = converse.chatboxviews.get(jid);
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+ chatroomview.close();
|
|
|
|
+ });
|
|
|
|
+ waits('300'); // ChatBox.show() is debounced for 250ms
|
|
|
|
+ runs(function () {
|
|
|
|
+ // Test with mixed case
|
|
|
|
+ test_utils.openChatRoom('Leisure', 'localhost', 'dummy');
|
|
|
|
+ var jid = 'Leisure@localhost';
|
|
|
|
+ var room = converse_api.rooms.get(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ var chatroomview = converse.chatboxviews.get(jid.toLowerCase());
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+ });
|
|
|
|
+ waits('300'); // ChatBox.show() is debounced for 250ms
|
|
|
|
+ runs(function () {
|
|
|
|
+ var jid = 'leisure@localhost';
|
|
|
|
+ var room = converse_api.rooms.get(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ var chatroomview = converse.chatboxviews.get(jid.toLowerCase());
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+
|
|
|
|
+ jid = 'leiSure@localhost';
|
|
|
|
+ room = converse_api.rooms.get(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ chatroomview = converse.chatboxviews.get(jid.toLowerCase());
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+ chatroomview.close();
|
|
|
|
+
|
|
|
|
+ // Non-existing room
|
|
|
|
+ jid = 'lounge2@localhost';
|
|
|
|
+ room = converse_api.rooms.get(jid);
|
|
|
|
+ expect(typeof room === 'undefined').toBeTruthy();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it("has a method 'open' which opens and returns a wrapped chat box", function () {
|
|
|
|
+ var chatroomview;
|
|
|
|
+ var jid = 'lounge@localhost';
|
|
|
|
+ var room = converse_api.rooms.open(jid);
|
|
|
|
+ runs(function () {
|
|
|
|
+ // Test on chat room that doesn't exist.
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ expect(room.is_chatroom).toBeTruthy();
|
|
|
|
+ chatroomview = converse.chatboxviews.get(jid);
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+ });
|
|
|
|
+ waits('300'); // ChatBox.show() is debounced for 250ms
|
|
|
|
+ runs(function () {
|
|
|
|
+ // Test again, now that the room exists.
|
|
|
|
+ room = converse_api.rooms.open(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ expect(room.is_chatroom).toBeTruthy();
|
|
|
|
+ chatroomview = converse.chatboxviews.get(jid);
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+ });
|
|
|
|
+ waits('300'); // ChatBox.show() is debounced for 250ms
|
|
|
|
+ runs(function () {
|
|
|
|
+ // Test with mixed case in JID
|
|
|
|
+ jid = 'Leisure@localhost';
|
|
|
|
+ room = converse_api.rooms.open(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ chatroomview = converse.chatboxviews.get(jid.toLowerCase());
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+
|
|
|
|
+ jid = 'leisure@localhost';
|
|
|
|
+ room = converse_api.rooms.open(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ chatroomview = converse.chatboxviews.get(jid.toLowerCase());
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+
|
|
|
|
+ jid = 'leiSure@localhost';
|
|
|
|
+ room = converse_api.rooms.open(jid);
|
|
|
|
+ expect(room instanceof Object).toBeTruthy();
|
|
|
|
+ chatroomview = converse.chatboxviews.get(jid.toLowerCase());
|
|
|
|
+ expect(chatroomview.$el.is(':visible')).toBeTruthy();
|
|
|
|
+ chatroomview.close();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
describe("A Chat Room", function () {
|
|
describe("A Chat Room", function () {
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
runs(function () {
|
|
runs(function () {
|