From 9ea432f88c47a8e387e6f8144ef1d8bd663d03dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 6 Dec 2016 17:50:57 +0100 Subject: [PATCH] Adjust the JS unit tests Signed-off-by: Joas Schilling --- .../systemtags/systemtagsinputfieldSpec.js | 87 +++++++++++++++---- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js b/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js index 503bef7cf2..8d3f67bfa0 100644 --- a/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js +++ b/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js @@ -267,20 +267,6 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() { 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() { it('sets value when calling setValues', function() { @@ -299,12 +285,18 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() { }); describe('as admin', function() { + var $dropdown; + beforeEach(function() { view = new OC.SystemTags.SystemTagsInputField({ isAdmin: true }); - view.render(); $('.testInputContainer').append(view.$el); + $dropdown = $('
'); + select2Stub.withArgs('dropdown').returns($dropdown); + $('#testArea').append($dropdown); + + view.render(); }); it('formatResult renders tag name with visibility', function() { 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() { + var $dropdown; + beforeEach(function() { view = new OC.SystemTags.SystemTagsInputField({ isAdmin: false }); - view.render(); $('.testInputContainer').append(view.$el); + $dropdown = $('
'); + select2Stub.withArgs('dropdown').returns($dropdown); + $('#testArea').append($dropdown); + + view.render(); }); it('formatResult renders tag name only', function() { 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(); + }); + }); }); });