diff --git a/apps/systemtags/js/systemtagsinfoview.js b/apps/systemtags/js/systemtagsinfoview.js index ce5de2048a..d42bf18761 100644 --- a/apps/systemtags/js/systemtagsinfoview.js +++ b/apps/systemtags/js/systemtagsinfoview.js @@ -65,9 +65,11 @@ this._toggleHandle.prepend($('').addClass('icon icon-tag')); this._toggleHandle.on('click', function () { - self.$el.toggleClass('hidden'); - if (!self.$el.hasClass('hidden')) { - self.$el.find('.systemTagsInputField').select2('open'); + if (self.isVisible()) { + self.hide(); + } else { + self.show(); + self.openDropdown(); } }); }, @@ -144,15 +146,15 @@ self._inputView.setData(appliedTags); if (appliedTags.length !== 0) { - self.$el.removeClass('hidden'); + self.show(); } else { - self.$el.addClass('hidden'); + self.hide(); } } }); } - this.$el.addClass('hidden'); + this.hide(); }, /** @@ -165,6 +167,22 @@ this._inputView.render(); }, + isVisible: function() { + return !this.$el.hasClass('hidden'); + }, + + show: function() { + this.$el.removeClass('hidden'); + }, + + hide: function() { + this.$el.addClass('hidden'); + }, + + openDropdown: function() { + this.$el.find('.systemTagsInputField').select2('open'); + }, + remove: function() { this._inputView.remove(); this._toggleHandle.remove(); diff --git a/apps/systemtags/tests/js/systemtagsinfoviewSpec.js b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js index 449dfd859d..2f87468811 100644 --- a/apps/systemtags/tests/js/systemtagsinfoviewSpec.js +++ b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js @@ -201,4 +201,50 @@ describe('OCA.SystemTags.SystemTagsInfoView tests', function() { }); }); + describe('visibility', function() { + it('reports visibility based on the "hidden" class name', function() { + view.$el.addClass('hidden'); + + expect(view.isVisible()).toBeFalsy(); + + view.$el.removeClass('hidden'); + + expect(view.isVisible()).toBeTruthy(); + }); + it('is not visible after rendering', function() { + view.render(); + + expect(view.isVisible()).toBeFalsy(); + }); + it('shows and hides the element', function() { + view.show(); + + expect(view.isVisible()).toBeTruthy(); + + view.hide(); + + expect(view.isVisible()).toBeFalsy(); + + view.show(); + + expect(view.isVisible()).toBeTruthy(); + }); + }); + describe('select2', function() { + var select2Stub; + + beforeEach(function() { + select2Stub = sinon.stub($.fn, 'select2'); + }); + afterEach(function() { + select2Stub.restore(); + }); + it('opens dropdown', function() { + view.openDropdown(); + + expect(select2Stub.calledOnce).toBeTruthy(); + expect(select2Stub.thisValues[0].selector).toEqual('.systemTagsInputField'); + expect(select2Stub.withArgs('open')).toBeTruthy(); + }); + }); });