diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-08-17 12:25:58 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-04-26 13:38:12 +0200 |
commit | 17a31a51c62e36500f59b3c2d385ab79258f6bb6 (patch) | |
tree | d73fc6bb6a326cc34832c963bcda26e7417f35e1 /apps/files_sharing | |
parent | 5b5c3a1773dab4960d41aafc4150859a308311b7 (diff) | |
download | nextcloud-server-17a31a51c62e36500f59b3c2d385ab79258f6bb6.tar.gz nextcloud-server-17a31a51c62e36500f59b3c2d385ab79258f6bb6.zip |
Fix share indicator handling
Properly update the fileInfoModel with the updated share types, which
also updates the file list row indicator properly
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/js/share.js | 17 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/shareSpec.js | 78 |
2 files changed, 88 insertions, 7 deletions
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index c40ca07b76b..5cd04ece446 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -189,13 +189,16 @@ // remove icon, if applicable OC.Share.markFileAsShared($tr, false, false); } - var newIcon = $tr.attr('data-icon'); - // in case markFileAsShared decided to change the icon, - // we need to modify the model - // (FIXME: yes, this is hacky) - if (fileInfoModel.get('icon') !== newIcon) { - fileInfoModel.set('icon', newIcon); - } + + // FIXME: this is too convoluted. We need to get rid of the above updates + // and only ever update the model and let the events take care of rerendering + fileInfoModel.set({ + shareTypes: shareModel.getShareTypes(), + // in case markFileAsShared decided to change the icon, + // we need to modify the model + // (FIXME: yes, this is hacky) + icon: $tr.attr('data-icon') + }); }); fileList.registerTabView(shareTab); diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js index 7568b06f27c..ea2f427df75 100644 --- a/apps/files_sharing/tests/js/shareSpec.js +++ b/apps/files_sharing/tests/js/shareSpec.js @@ -470,4 +470,82 @@ describe('OCA.Sharing.Util tests', function() { }); }); + describe('ShareTabView interaction', function() { + var shareTabSpy; + var fileInfoModel; + var configModel; + var shareModel; + + beforeEach(function() { + shareTabSpy = sinon.spy(OCA.Sharing, 'ShareTabView'); + + var attributes = { + itemType: 'file', + itemSource: 123, + possiblePermissions: 31, + permissions: 31 + }; + fileInfoModel = new OCA.Files.FileInfoModel(testFiles[0]); + configModel = new OC.Share.ShareConfigModel({ + enforcePasswordForPublicLink: false, + isResharingAllowed: true, + isDefaultExpireDateEnabled: false, + isDefaultExpireDateEnforced: false, + defaultExpireDate: 7 + }); + shareModel = new OC.Share.ShareItemModel(attributes, { + configModel: configModel, + fileInfoModel: fileInfoModel + }); + + /* jshint camelcase: false */ + shareModel.set({ + reshare: {}, + shares: [{ + id: 100, + item_source: 1, + permissions: 31, + share_type: OC.Share.SHARE_TYPE_USER, + share_with: 'user1', + share_with_displayname: 'User One' + }, { + id: 102, + item_source: 1, + permissions: 31, + share_type: OC.Share.SHARE_TYPE_REMOTE, + share_with: 'foo@bar.com/baz', + share_with_displayname: 'foo@bar.com/baz' + + }] + }, {parse: true}); + + fileList.destroy(); + fileList = new OCA.Files.FileList( + $('#listContainer'), { + id: 'files', + fileActions: new OCA.Files.FileActions() + } + ); + OCA.Sharing.Util.attach(fileList); + fileList.setFiles(testFiles); + }); + afterEach(function() { + shareTabSpy.restore(); + }); + + it('updates fileInfoModel when shares changed', function() { + var changeHandler = sinon.stub(); + fileInfoModel.on('change', changeHandler); + + shareTabSpy.getCall(0).thisValue.trigger('sharesChanged', shareModel); + + expect(changeHandler.calledOnce).toEqual(true); + expect(changeHandler.getCall(0).args[0].changed).toEqual({ + shareTypes: [ + OC.Share.SHARE_TYPE_USER, + OC.Share.SHARE_TYPE_REMOTE + ] + }); + }); + }); }); |