Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-11-30 17:40:17 +0300
committerVincent Petry <pvince81@owncloud.com>2016-01-19 18:24:26 +0300
commitffba6d0a7e1988bed1c0f0dfa2334092a65c568d (patch)
tree02e0daa2bf915983f6ec40f574b0ca8640c205d1 /apps/systemtags/tests
parent8d41cbb97a7a1fa750db520dc8879da4402f31e3 (diff)
Added system tags GUI in sidebar
Added files details sidebar panel to assign/unassign/rename/delete system tags.
Diffstat (limited to 'apps/systemtags/tests')
-rw-r--r--apps/systemtags/tests/js/systemtagsinfoviewSpec.js149
1 files changed, 149 insertions, 0 deletions
diff --git a/apps/systemtags/tests/js/systemtagsinfoviewSpec.js b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js
new file mode 100644
index 00000000000..971ad8fc17e
--- /dev/null
+++ b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js
@@ -0,0 +1,149 @@
+/**
+* ownCloud
+*
+* @author Vincent Petry
+* @copyright 2016 Vincent Petry <pvince81@owncloud.com>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+describe('OCA.SystemTags.SystemTagsInfoView tests', function() {
+ var view;
+
+ beforeEach(function() {
+ view = new OCA.SystemTags.SystemTagsInfoView();
+ $('#testArea').append(view.$el);
+ });
+ afterEach(function() {
+ view.remove();
+ view = undefined;
+ });
+ describe('rendering', function() {
+ it('renders input field view', function() {
+ view.render();
+ expect(view.$el.find('input[name=tags]').length).toEqual(1);
+ });
+ it('fetches selected tags then renders when setting file info', function() {
+ var fetchStub = sinon.stub(OC.SystemTags.SystemTagsMappingCollection.prototype, 'fetch');
+ var setDataStub = sinon.stub(OC.SystemTags.SystemTagsInputField.prototype, 'setData');
+
+ expect(view.$el.hasClass('hidden')).toEqual(true);
+
+ view.setFileInfo({id: '123'});
+ expect(view.$el.find('input[name=tags]').length).toEqual(1);
+
+ expect(fetchStub.calledOnce).toEqual(true);
+ expect(view.selectedTagsCollection.url())
+ .toEqual(OC.linkToRemote('dav') + '/systemtags-relations/files/123');
+
+ view.selectedTagsCollection.add([
+ {id: '1', name: 'test1'},
+ {id: '3', name: 'test3'}
+ ]);
+
+ fetchStub.yieldTo('success', view.selectedTagsCollection);
+ expect(setDataStub.calledOnce).toEqual(true);
+ expect(setDataStub.getCall(0).args[0]).toEqual([{
+ id: '1', name: 'test1', userVisible: true, userAssignable: true
+ }, {
+ id: '3', name: 'test3', userVisible: true, userAssignable: true
+ }]);
+
+ expect(view.$el.hasClass('hidden')).toEqual(false);
+
+ fetchStub.restore();
+ setDataStub.restore();
+ });
+ it('overrides initSelection to use the local collection', function() {
+ var inputViewSpy = sinon.spy(OC.SystemTags, 'SystemTagsInputField');
+ var element = $('<input type="hidden" val="1,3"/>');
+ view.remove();
+ view = new OCA.SystemTags.SystemTagsInfoView();
+ view.selectedTagsCollection.add([
+ {id: '1', name: 'test1'},
+ {id: '3', name: 'test3'}
+ ]);
+
+ var callback = sinon.stub();
+ inputViewSpy.getCall(0).args[0].initSelection(element, callback);
+
+ expect(callback.calledOnce).toEqual(true);
+ expect(callback.getCall(0).args[0]).toEqual([{
+ id: '1', name: 'test1', userVisible: true, userAssignable: true
+ }, {
+ id: '3', name: 'test3', userVisible: true, userAssignable: true
+ }]);
+
+ inputViewSpy.restore();
+ });
+ });
+ describe('events', function() {
+ var allTagsCollection;
+ beforeEach(function() {
+ allTagsCollection = view._inputView.collection;
+
+ allTagsCollection.add([
+ {id: '1', name: 'test1'},
+ {id: '2', name: 'test2'},
+ {id: '3', name: 'test3'}
+ ]);
+
+ view.selectedTagsCollection.add([
+ {id: '1', name: 'test1'},
+ {id: '3', name: 'test3'}
+ ]);
+ view.render();
+ });
+
+ it('renames model in selection collection on rename', function() {
+ allTagsCollection.get('3').set('name', 'test3_renamed');
+
+ expect(view.selectedTagsCollection.get('3').get('name')).toEqual('test3_renamed');
+ });
+
+ it('adds tag to selection collection when selected by input', function() {
+ var createStub = sinon.stub(OC.SystemTags.SystemTagsMappingCollection.prototype, 'create');
+ view._inputView.trigger('select', allTagsCollection.get('2'));
+
+ expect(createStub.calledOnce).toEqual(true);
+ expect(createStub.getCall(0).args[0]).toEqual({
+ id: '2',
+ name: 'test2',
+ userVisible: true,
+ userAssignable: true
+ });
+
+ createStub.restore();
+ });
+ it('removes tag from selection collection when deselected by input', function() {
+ var destroyStub = sinon.stub(OC.SystemTags.SystemTagModel.prototype, 'destroy');
+ view._inputView.trigger('deselect', '3');
+
+ expect(destroyStub.calledOnce).toEqual(true);
+ expect(destroyStub.calledOn(view.selectedTagsCollection.get('3'))).toEqual(true);
+
+ destroyStub.restore();
+ });
+
+ it('removes tag from selection whenever the tag was deleted globally', function() {
+ expect(view.selectedTagsCollection.get('3')).not.toBeFalsy();
+
+ allTagsCollection.remove('3');
+
+ expect(view.selectedTagsCollection.get('3')).toBeFalsy();
+
+ });
+ });
+});