Commit da0c858f authored by JC Brand's avatar JC Brand

Used debounce ineffectually. Fixed now.

The ChatBox.show() method was being called for every invocation, 100ms after
the fact, instead of it being called only once.

Fixed that and also changed to call it at the start.
parent e94904e4
This diff is collapsed.
......@@ -265,15 +265,15 @@
test_utils.createContacts('current');
}, converse));
it("has a method 'get' which returns a wrapped chat box", $.proxy(function () {
it("has a method 'get' which returns a wrapped chat box", 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';
// 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 instanceof Object).toBeTruthy();
var chatboxview = this.chatboxviews.get(jid);
var chatboxview = converse.chatboxviews.get(jid);
expect(chatboxview.$el.is(':visible')).toBeFalsy();
// Test for single JID
......@@ -281,9 +281,8 @@
box = converse_api.chats.get(jid);
expect(box instanceof Object).toBeTruthy();
expect(box.get('box_id')).toBe(b64_sha1(jid));
chatboxview = this.chatboxviews.get(jid);
chatboxview = converse.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);
......@@ -291,13 +290,15 @@
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 () {
it("has a method 'open' which opens and returns a wrapped chat box", function () {
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
var chatboxview;
waits('300'); // ChatBox.show() is debounced for 250ms
runs(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));
......@@ -305,16 +306,16 @@
Object.keys(box),
['close', 'endOTR', 'focus', 'get', 'initiateOTR', 'is_chatroom', 'maximize', 'minimize', 'open', 'set']
);
var chatboxview = this.chatboxviews.get(jid);
chatboxview = converse.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));
describe("The \"rooms\" API", function () {
......@@ -326,6 +327,8 @@
});
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);
......@@ -334,19 +337,23 @@
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');
jid = 'Leisure@localhost';
room = converse_api.rooms.get(jid);
var jid = 'Leisure@localhost';
var room = converse_api.rooms.get(jid);
expect(room instanceof Object).toBeTruthy();
chatroomview = converse.chatboxviews.get(jid.toLowerCase());
var chatroomview = converse.chatboxviews.get(jid.toLowerCase());
expect(chatroomview.$el.is(':visible')).toBeTruthy();
jid = 'leisure@localhost';
room = converse_api.rooms.get(jid);
});
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();
chatroomview = converse.chatboxviews.get(jid.toLowerCase());
var chatroomview = converse.chatboxviews.get(jid.toLowerCase());
expect(chatroomview.$el.is(':visible')).toBeTruthy();
jid = 'leiSure@localhost';
......@@ -361,23 +368,30 @@
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 () {
// Test on chat room that doesn't exist.
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();
var chatroomview = converse.chatboxviews.get(jid);
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);
......@@ -399,6 +413,7 @@
chatroomview.close();
});
});
});
describe("The \"settings\" API", $.proxy(function() {
beforeEach($.proxy(function () {
......
......@@ -1429,7 +1429,7 @@
converse.incrementMsgCounter();
}
if (!this.model.get('minimized') && !this.$el.is(':visible')) {
_.debounce(this.show.bind(this), 100)();
this.show();
}
},
......@@ -1830,7 +1830,7 @@
return this;
},
show: function (focus) {
show: _.debounce(function (callback) {
if (this.$el.is(':visible') && this.$el.css('opacity') === "1") {
if (focus) { this.focus(); }
return this;
......@@ -1849,7 +1849,7 @@
}
}.bind(this));
return this;
},
}, 250, true),
scrollDownMessageHeight: function ($message) {
if (this.$content.is(':visible')) {
......
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