2
0
Эх сурвалжийг харах

Some refactoring of RosterView and skeleton for groups test

JC Brand 11 жил өмнө
parent
commit
ce617f1f31
2 өөрчлөгдсөн 57 нэмэгдсэн , 30 устгасан
  1. 9 9
      converse.js
  2. 48 21
      spec/controlbox.js

+ 9 - 9
converse.js

@@ -3221,7 +3221,7 @@
 
             initialize: function () {
                 this.model.on("add", function (item) {
-                    this.addRosterItemView(item).render(item);
+                    this.addRosterItemView(item).updateRoster(item);
                     if (item.get('is_last')) {
                         this.sortRoster().showRoster();
                     }
@@ -3235,19 +3235,19 @@
                     if ((_.size(item.changed) === 1) && _.contains(_.keys(item.changed), 'sorted')) {
                         return;
                     }
-                    this.updateChatBox(item).render(item);
+                    this.updateChatBox(item).updateRoster(item);
                     if (item.changed.chat_status) { // A changed chat status implies a new sort order
                         this.sortRoster();
                     }
                 }, this);
                 this.model.on("remove", function (item) { this.removeRosterItemView(item); }, this);
                 this.model.on("destroy", function (item) { this.removeRosterItemView(item); }, this);
-                this.model.on("reset", function () { this.removeAllRosterItemViewss(); }, this);
-                this.initRender();
+                this.model.on("reset", function () { this.removeAllRosterItemViews(); }, this);
+                this.render();
                 this.model.fetch({add: true}); // Get the cached roster items from localstorage
             },
 
-            initRender: function () {
+            render: function () {
                 var desc_group_toggle = __('Click to hide these contacts'),
                     toggle_state = 'opened',
                     roster_markup = converse.templates.group_header({
@@ -3292,16 +3292,16 @@
                 return this;
             },
 
-            removeAllRosterItemViewss: function () {
+            removeAllRosterItemViews: function () {
                 var views = this.removeAll();
-                this.render();
+                this.updateRoster();
                 return this;
             },
 
             removeRosterItemView: function (item) {
                 if (this.get(item.id)) {
                     this.get(item.id).remove();
-                    this.render();
+                    this.updateRoster();
                 }
                 return this;
             },
@@ -3320,7 +3320,7 @@
                 }
             },
 
-            render: function (item) {
+            updateRoster: function (item) {
                 var $contact_requests = this.$el.find('#xmpp-contact-requests'),
                     $pending_contacts = this.$el.find('#pending-xmpp-contacts');
                 if (item) {

+ 48 - 21
spec/controlbox.js

@@ -152,7 +152,7 @@
             it("can be added to the roster", $.proxy(function () {
                 converse.rosterview.model.reset(); // We want to manually create users so that we can spy
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 runs($.proxy(function () {
                     this.roster.create({
                         jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
@@ -166,7 +166,7 @@
                 runs($.proxy(function () {
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                     expect(this.rosterview.$el.is(':visible')).toEqual(true);
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                 }, converse));
             }, converse));
 
@@ -203,7 +203,7 @@
                 converse.rosterview.model.reset(); // We want to manually create users so that we can spy
                 var i, t, is_last;
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 for (i=0; i<mock.pend_names.length; i++) {
                     is_last = i===(mock.pend_names.length-1);
                     this.roster.create({
@@ -213,7 +213,7 @@
                         fullname: mock.pend_names[i],
                         is_last: is_last
                     });
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                     // Check that they are sorted alphabetically
                     t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').find('span').text();
@@ -240,11 +240,15 @@
                 expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none');
             }, converse));
 
+            it("can be collapsed under their own header", $.proxy(function () {
+                checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]);
+            }, converse));
+
             it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
                 var i, t;
                 converse.rosterview.model.reset();
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 for (i=0; i<mock.cur_names.length; i++) {
                     this.roster.create({
                         jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
@@ -253,7 +257,7 @@
                         fullname: mock.cur_names[i],
                         is_last: i===(mock.cur_names.length-1)
                     });
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                 }
                 // Check that they are sorted alphabetically
@@ -261,14 +265,37 @@
                 expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
             }, converse));
 
-            it("can be collapsed under their own header", $.proxy(function () {
-                checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]);
+            it("can be assigned to groups inside the roster", $.proxy(function () {
+                var i=0, j=0, t;
+                converse.rosterview.model.reset();
+                spyOn(converse, 'emit');
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
+                converse.roster_groups = true;
+                converse.rosterview.render();
+                var groups = {
+                    colleagues: 3,
+                    friends: 8,
+                    family: 4
+                };
+                _.each(_.keys(groups), $.proxy(function (name) {
+                    j = i;
+                    for (i=j; i<j+groups[name]; i++) {
+                        this.roster.create({
+                            jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
+                            subscription: 'both',
+                            ask: null,
+                            groups: [name],
+                            fullname: mock.cur_names[i],
+                            is_last: i===(mock.cur_names.length-1)
+                        });
+                    }
+                }, converse));
             }, converse));
 
             it("can change their status to online and be sorted alphabetically", $.proxy(function () {
                 var item, view, jid, t;
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 for (i=0; i<mock.cur_names.length; i++) {
                     jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
                     view = this.rosterview.get(jid);
@@ -276,7 +303,7 @@
                     item = view.model;
                     item.set('chat_status', 'online');
                     expect(view.render).toHaveBeenCalled();
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                     // Check that they are sorted alphabetically
                     t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
@@ -287,7 +314,7 @@
             it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
                 var item, view, jid, t;
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 for (i=0; i<mock.cur_names.length; i++) {
                     jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
                     view = this.rosterview.get(jid);
@@ -295,7 +322,7 @@
                     item = view.model;
                     item.set('chat_status', 'dnd');
                     expect(view.render).toHaveBeenCalled();
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                     // Check that they are sorted alphabetically
                     t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
@@ -306,7 +333,7 @@
             it("can change their status to away and be sorted alphabetically", $.proxy(function () {
                 var item, view, jid, t;
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 for (i=0; i<mock.cur_names.length; i++) {
                     jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
                     view = this.rosterview.get(jid);
@@ -314,7 +341,7 @@
                     item = view.model;
                     item.set('chat_status', 'away');
                     expect(view.render).toHaveBeenCalled();
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                     // Check that they are sorted alphabetically
                     t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
@@ -325,7 +352,7 @@
             it("can change their status to xa and be sorted alphabetically", $.proxy(function () {
                 var item, view, jid, t;
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 for (i=0; i<mock.cur_names.length; i++) {
                     jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
                     view = this.rosterview.get(jid);
@@ -333,7 +360,7 @@
                     item = view.model;
                     item.set('chat_status', 'xa');
                     expect(view.render).toHaveBeenCalled();
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                     // Check that they are sorted alphabetically
                     t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text();
@@ -344,7 +371,7 @@
             it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
                 var item, view, jid, t;
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 for (i=0; i<mock.cur_names.length; i++) {
                     jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
                     view = this.rosterview.get(jid);
@@ -352,7 +379,7 @@
                     item = view.model;
                     item.set('chat_status', 'unavailable');
                     expect(view.render).toHaveBeenCalled();
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated');
                     // Check that they are sorted alphabetically
                     t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
@@ -434,7 +461,7 @@
                 var i, children;
                 var names = [];
                 spyOn(converse, 'emit');
-                spyOn(this.rosterview, 'render').andCallThrough();
+                spyOn(this.rosterview, 'updateRoster').andCallThrough();
                 spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
                 var addName = function (idx, item) {
                     if (!$(item).hasClass('request-actions')) {
@@ -450,7 +477,7 @@
                         fullname: mock.req_names[i],
                         is_last: i===(mock.req_names.length-1)
                     });
-                    expect(this.rosterview.render).toHaveBeenCalled();
+                    expect(this.rosterview.updateRoster).toHaveBeenCalled();
                     // Check that they are sorted alphabetically
                     children = this.rosterview.$el.find('dt#xmpp-contact-requests').siblings('dd.requesting-xmpp-contact').children('span');
                     names = [];
@@ -540,7 +567,7 @@
                     // comparison
                     expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
                 }
-                this.rosterview.render();
+                this.rosterview.updateRoster();
             }, converse));
 
             afterEach($.proxy(function () {