summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-06-09 03:34:56 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-06-09 09:04:24 +0200
commitccf4b9ec69c3a9d33cc02b5cf01f2ff0a866efdd (patch)
tree4752b300530184087c37a293053cfd24452d8167 /apps
parent9e767b46ec24cf9ff559339950fdfd2f7f6bd1bf (diff)
downloadnextcloud-server-ccf4b9ec69c3a9d33cc02b5cf01f2ff0a866efdd.tar.gz
nextcloud-server-ccf4b9ec69c3a9d33cc02b5cf01f2ff0a866efdd.zip
Add visibility related methods
SystemTagsInfoView now provides public methods related to its visibility in preparation to be used by external objects. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/systemtags/js/systemtagsinfoview.js30
-rw-r--r--apps/systemtags/tests/js/systemtagsinfoviewSpec.js46
2 files changed, 70 insertions, 6 deletions
diff --git a/apps/systemtags/js/systemtagsinfoview.js b/apps/systemtags/js/systemtagsinfoview.js
index ce5de2048ab..d42bf18761b 100644
--- a/apps/systemtags/js/systemtagsinfoview.js
+++ b/apps/systemtags/js/systemtagsinfoview.js
@@ -65,9 +65,11 @@
this._toggleHandle.prepend($('<span>').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 449dfd859d7..2f874688112 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();
+ });
+ });
});