Adjust the JS unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
b8e9d255d3
commit
9ea432f88c
|
@ -267,20 +267,6 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() {
|
||||||
|
|
||||||
saveStub.restore();
|
saveStub.restore();
|
||||||
});
|
});
|
||||||
it('deletes model and submits change when clicking delete', function() {
|
|
||||||
var destroyStub = sinon.stub(OC.SystemTags.SystemTagModel.prototype, 'destroy');
|
|
||||||
|
|
||||||
expect($dropdown.find('.delete').length).toEqual(0);
|
|
||||||
$dropdown.find('.rename').mouseup();
|
|
||||||
// delete button appears
|
|
||||||
expect($dropdown.find('.delete').length).toEqual(1);
|
|
||||||
$dropdown.find('.delete').mouseup();
|
|
||||||
|
|
||||||
expect(destroyStub.calledOnce).toEqual(true);
|
|
||||||
expect(destroyStub.calledOn(view.collection.get('1')));
|
|
||||||
|
|
||||||
destroyStub.restore();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('setting data', function() {
|
describe('setting data', function() {
|
||||||
it('sets value when calling setValues', function() {
|
it('sets value when calling setValues', function() {
|
||||||
|
@ -299,12 +285,18 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('as admin', function() {
|
describe('as admin', function() {
|
||||||
|
var $dropdown;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
view = new OC.SystemTags.SystemTagsInputField({
|
view = new OC.SystemTags.SystemTagsInputField({
|
||||||
isAdmin: true
|
isAdmin: true
|
||||||
});
|
});
|
||||||
view.render();
|
|
||||||
$('.testInputContainer').append(view.$el);
|
$('.testInputContainer').append(view.$el);
|
||||||
|
$dropdown = $('<div class="select2-dropdown"></div>');
|
||||||
|
select2Stub.withArgs('dropdown').returns($dropdown);
|
||||||
|
$('#testArea').append($dropdown);
|
||||||
|
|
||||||
|
view.render();
|
||||||
});
|
});
|
||||||
it('formatResult renders tag name with visibility', function() {
|
it('formatResult renders tag name with visibility', function() {
|
||||||
var opts = select2Stub.getCall(0).args[0];
|
var opts = select2Stub.getCall(0).args[0];
|
||||||
|
@ -431,15 +423,50 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('tag actions', function() {
|
||||||
|
var opts;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
|
||||||
|
opts = select2Stub.getCall(0).args[0];
|
||||||
|
|
||||||
|
view.collection.add([
|
||||||
|
new OC.SystemTags.SystemTagModel({id: '1', name: 'abc'}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dropdown.append(opts.formatResult(view.collection.get('1').toJSON()));
|
||||||
|
|
||||||
|
});
|
||||||
|
it('deletes model and submits change when clicking delete', function() {
|
||||||
|
var destroyStub = sinon.stub(OC.SystemTags.SystemTagModel.prototype, 'destroy');
|
||||||
|
|
||||||
|
expect($dropdown.find('.delete').length).toEqual(0);
|
||||||
|
$dropdown.find('.rename').mouseup();
|
||||||
|
// delete button appears
|
||||||
|
expect($dropdown.find('.delete').length).toEqual(1);
|
||||||
|
$dropdown.find('.delete').mouseup();
|
||||||
|
|
||||||
|
expect(destroyStub.calledOnce).toEqual(true);
|
||||||
|
expect(destroyStub.calledOn(view.collection.get('1')));
|
||||||
|
|
||||||
|
destroyStub.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('as user', function() {
|
describe('as user', function() {
|
||||||
|
var $dropdown;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
view = new OC.SystemTags.SystemTagsInputField({
|
view = new OC.SystemTags.SystemTagsInputField({
|
||||||
isAdmin: false
|
isAdmin: false
|
||||||
});
|
});
|
||||||
view.render();
|
|
||||||
$('.testInputContainer').append(view.$el);
|
$('.testInputContainer').append(view.$el);
|
||||||
|
$dropdown = $('<div class="select2-dropdown"></div>');
|
||||||
|
select2Stub.withArgs('dropdown').returns($dropdown);
|
||||||
|
$('#testArea').append($dropdown);
|
||||||
|
|
||||||
|
view.render();
|
||||||
});
|
});
|
||||||
it('formatResult renders tag name only', function() {
|
it('formatResult renders tag name only', function() {
|
||||||
var opts = select2Stub.getCall(0).args[0];
|
var opts = select2Stub.getCall(0).args[0];
|
||||||
|
@ -570,5 +597,33 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('tag actions', function() {
|
||||||
|
var opts;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
|
||||||
|
opts = select2Stub.getCall(0).args[0];
|
||||||
|
|
||||||
|
view.collection.add([
|
||||||
|
new OC.SystemTags.SystemTagModel({id: '1', name: 'abc'}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dropdown.append(opts.formatResult(view.collection.get('1').toJSON()));
|
||||||
|
|
||||||
|
});
|
||||||
|
it('deletes model and submits change when clicking delete', function() {
|
||||||
|
var destroyStub = sinon.stub(OC.SystemTags.SystemTagModel.prototype, 'destroy');
|
||||||
|
|
||||||
|
expect($dropdown.find('.delete').length).toEqual(0);
|
||||||
|
$dropdown.find('.rename').mouseup();
|
||||||
|
// delete button appears only for admins
|
||||||
|
expect($dropdown.find('.delete').length).toEqual(0);
|
||||||
|
$dropdown.find('.delete').mouseup();
|
||||||
|
|
||||||
|
expect(destroyStub.notCalled).toEqual(true);
|
||||||
|
|
||||||
|
destroyStub.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue