From 71381e2f22f6302dddd7f6df386f4e663502bf91 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 18 Jul 2016 08:41:06 +0000 Subject: [PATCH] Show requesting contacts when filtering by chat state. Also add an initial test case for filtering by chat state. --- docs/CHANGES.md | 1 + spec/controlbox.js | 111 +++++++++++++++++++++++++------------ src/converse-rosterview.js | 17 +++++- 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 97f9921e3..365b81ef9 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -8,6 +8,7 @@ to make it the same as the method of `ChatRoomView`. [jcbrand] - Render error messages received from the server (for undelivered chat messages). [jcbrand] +- Show requesting contacts when filtering by chat state. [jcbrand] ## 1.0.3 (2016-06-20) diff --git a/spec/controlbox.js b/spec/controlbox.js index d9abb09fb..2ff4ba891 100644 --- a/spec/controlbox.js +++ b/spec/controlbox.js @@ -135,6 +135,7 @@ describe("The live filter", $.proxy(function () { beforeEach(function () { + _clearContacts(); test_utils.openControlBox(); test_utils.openContactsPanel(); }); @@ -143,7 +144,6 @@ var $filter = converse.rosterview.$('.roster-filter'); var names = mock.cur_names; runs(function () { - _clearContacts(); converse.rosterview.update(); // XXX: Will normally called as event handler }); waits(5); // Needed, due to debounce @@ -176,7 +176,6 @@ var $filter; var $roster; runs(function () { - _clearContacts(); converse.roster_groups = true; utils.createGroupedContacts(); $filter = converse.rosterview.$('.roster-filter'); @@ -232,7 +231,6 @@ var $type; runs(function () { converse.roster_groups = true; - _clearContacts(); utils.createGroupedContacts(); converse.rosterview.filter_view.delegateEvents(); $filter = converse.rosterview.$('.roster-filter'); @@ -276,7 +274,6 @@ it("has a button with which its contents can be cleared", function () { converse.roster_groups = true; - _clearContacts(); utils.createGroupedContacts(); var $filter = converse.rosterview.$('.roster-filter'); runs (function () { @@ -294,10 +291,48 @@ }); converse.roster_groups = false; }); + + it("can be used to filter contacts by their chat state", function () { + var $filter; + var $roster; + converse.roster_groups = true; + utils.createGroupedContacts(); + var jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost'; + converse.roster.get(jid).set('chat_status', 'online'); + + runs(function () { + converse.rosterview.filter_view.delegateEvents(); + var $type = converse.rosterview.$('.filter-type'); + $type.val('state').trigger('change'); + }); + waits(300); // Needed, due to debounce in "update" method + runs(function () { + $filter = converse.rosterview.$('.state-type'); + $roster = converse.rosterview.$roster; + expect($roster.find('dd:visible').length).toBe(15); + expect($roster.find('dt:visible').length).toBe(5); + $filter.val("online"); + expect($roster.find('dd:visible').length).toBe(15); // because no change event yet + expect($roster.find('dt:visible').length).toBe(5); // ditto + $filter.trigger('change'); + }); + waits(550); // Needed, due to debounce + runs (function () { + expect($roster.find('dd:visible').length).toBe(1); + expect($roster.find('dd:visible').eq(0).text().trim()).toBe('Rinse Sommer'); + expect($roster.find('dt:visible').length).toBe(1); + + var $type = converse.rosterview.$('.filter-type'); + $type.val('contacts').trigger('change'); + converse.roster_groups = false; + }); + }); + }, converse)); describe("A Roster Group", $.proxy(function () { beforeEach(function () { + _clearContacts(); converse.roster_groups = true; }); afterEach(function () { @@ -306,7 +341,6 @@ it("can be used to organize existing contacts", $.proxy(function () { runs($.proxy(function () { - _clearContacts(); spyOn(converse, 'emit'); spyOn(this.rosterview, 'update').andCallThrough(); converse.rosterview.render(); @@ -340,7 +374,6 @@ it("can share contacts with other roster groups", $.proxy(function () { var groups = ['colleagues', 'friends']; runs($.proxy(function () { - _clearContacts(); var i=0; spyOn(converse, 'emit'); spyOn(this.rosterview, 'update').andCallThrough(); @@ -403,11 +436,14 @@ } function _addContacts () { - _clearContacts(); // Must be initialized, so that render is called and documentFragment set up. utils.createContacts('pending').openControlBox().openContactsPanel(); } + beforeEach(function () { + _clearContacts(); + }); + it("can be collapsed under their own header", $.proxy(function () { runs(function () { _addContacts(); @@ -437,24 +473,24 @@ }, converse)); }, converse)); - it("are shown in the roster when show_only_online_users", $.proxy(function () { + it("are shown in the roster when show_only_online_users", function () { converse.show_only_online_users = true; runs(function () { _addContacts(); }); waits(50); - spyOn(this.rosterview, 'update').andCallThrough(); - runs($.proxy(function () { - expect(this.rosterview.$el.is(':visible')).toEqual(true); - expect(this.rosterview.update).toHaveBeenCalled(); - }, converse)); + spyOn(converse.rosterview, 'update').andCallThrough(); + runs(function () { + expect(converse.rosterview.$el.is(':visible')).toEqual(true); + expect(converse.rosterview.update).toHaveBeenCalled(); + }); waits(300); // Needed, due to debounce - runs ($.proxy(function () { - expect(this.rosterview.$el.find('dd:visible').length).toBe(3); - expect(this.rosterview.$el.find('dt:visible').length).toBe(1); - }, converse)); + runs (function () { + expect(converse.rosterview.$el.find('dd:visible').length).toBe(3); + expect(converse.rosterview.$el.find('dt:visible').length).toBe(1); + }); converse.show_only_online_users = false; - }, converse)); + }); it("are shown in the roster when hide_offline_users", $.proxy(function () { converse.hide_offline_users = true; @@ -541,24 +577,23 @@ expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy(); }, converse)); - it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { - _clearContacts(); + it("can be added to the roster and they will be sorted alphabetically", function () { var i, t; spyOn(converse, 'emit'); - spyOn(this.rosterview, 'update').andCallThrough(); + spyOn(converse.rosterview, 'update').andCallThrough(); for (i=0; i