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:
parent
9e767b46ec
commit
ccf4b9ec69
|
@ -65,9 +65,11 @@
|
||||||
this._toggleHandle.prepend($('<span>').addClass('icon icon-tag'));
|
this._toggleHandle.prepend($('<span>').addClass('icon icon-tag'));
|
||||||
|
|
||||||
this._toggleHandle.on('click', function () {
|
this._toggleHandle.on('click', function () {
|
||||||
self.$el.toggleClass('hidden');
|
if (self.isVisible()) {
|
||||||
if (!self.$el.hasClass('hidden')) {
|
self.hide();
|
||||||
self.$el.find('.systemTagsInputField').select2('open');
|
} else {
|
||||||
|
self.show();
|
||||||
|
self.openDropdown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -144,15 +146,15 @@
|
||||||
self._inputView.setData(appliedTags);
|
self._inputView.setData(appliedTags);
|
||||||
|
|
||||||
if (appliedTags.length !== 0) {
|
if (appliedTags.length !== 0) {
|
||||||
self.$el.removeClass('hidden');
|
self.show();
|
||||||
} else {
|
} else {
|
||||||
self.$el.addClass('hidden');
|
self.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$el.addClass('hidden');
|
this.hide();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,6 +167,22 @@
|
||||||
this._inputView.render();
|
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() {
|
remove: function() {
|
||||||
this._inputView.remove();
|
this._inputView.remove();
|
||||||
this._toggleHandle.remove();
|
this._toggleHandle.remove();
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue