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>
This commit is contained in:
Daniel Calviño Sánchez 2017-06-09 03:34:56 +02:00
parent 365d7918b2
commit 5985ecb66d
2 changed files with 70 additions and 6 deletions

View File

@ -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();

View File

@ -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();
});
});
});