summaryrefslogtreecommitdiffstats
path: root/core/js/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-12-06 17:50:57 +0100
committerJoas Schilling <coding@schilljs.com>2016-12-06 17:50:57 +0100
commit9ea432f88c47a8e387e6f8144ef1d8bd663d03dd (patch)
tree2a295b077b7dbcd85cb1ed6c4f40421a568197cb /core/js/tests
parentb8e9d255d30a6b3429d94655608cbe02b634c9f1 (diff)
downloadnextcloud-server-9ea432f88c47a8e387e6f8144ef1d8bd663d03dd.tar.gz
nextcloud-server-9ea432f88c47a8e387e6f8144ef1d8bd663d03dd.zip
Adjust the JS unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/js/tests')
-rw-r--r--core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js87
1 files changed, 71 insertions, 16 deletions
diff --git a/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js b/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js
index 503bef7cf2b..8d3f67bfa0d 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 = $('<div class="select2-dropdown"></div>');
+ 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 = $('<div class="select2-dropdown"></div>');
+ 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();
+ });
+ });
});
});