diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 84a628345d..2e798a9257 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -151,6 +151,9 @@ }, }); promises.push(remoteShares); + } else { + //Push empty promise so callback gets called the same way + promises.push($.Deferred().resolve()); } this._reloadCall = $.when.apply($, promises); @@ -174,7 +177,7 @@ // TODO: error handling } - if (remoteShares[0].ocs && remoteShares[0].ocs.data) { + if (remoteShares && remoteShares[0].ocs && remoteShares[0].ocs.data) { files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data)); } else { // TODO: error handling @@ -193,11 +196,12 @@ var file = { shareOwner: share.owner + '@' + share.remote.replace(/.*?:\/\//g, ""), name: OC.basename(share.mountpoint), - mtime: share.mtime, + mtime: share.mtime * 1000, mimetype: share.mimetype, type: share.type, id: share.file_id, - path: OC.dirname(share.mountpoint) + path: OC.dirname(share.mountpoint), + permissions: share.permissions }; file.shares = [{ diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index 7fdc6345e3..90ae9c2d6d 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -57,6 +57,7 @@ describe('OCA.Sharing.FileList tests', function() { describe('loading file list for incoming shares', function() { var ocsResponse; + var ocsResponseRemote; beforeEach(function() { fileList = new OCA.Sharing.FileList( @@ -95,26 +96,64 @@ describe('OCA.Sharing.FileList tests', function() { }] } }; + + /* jshint camelcase: false */ + ocsResponseRemote = { + ocs: { + meta: { + status: 'ok', + statuscode: 100, + message: null + }, + data: [{ + id: 8, + remote: 'https://foo.bar/', + remote_id: 42, + share_token: 'abc', + name: '/a.txt', + owner: 'user3', + user: 'user1', + mountpoint: '/b.txt', + mountpoint_hash: 'def', + accepted: 1, + mimetype: 'text/plain', + mtime: 22222, + permissions: 31, + type: 'file', + file_id: 1337 + }] + } + }; + }); it('render file shares', function() { - var request; - - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( + expect(fakeServer.requests.length).toEqual(2); + expect(fakeServer.requests[0].url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + 'shares?format=json&shared_with_me=true' ); + expect(fakeServer.requests[1].url).toEqual( + OC.linkToOCS('apps/files_sharing/api/v1') + + 'remote_shares?format=json' + ); + fakeServer.requests[0].respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify(ocsResponse) ); + fakeServer.requests[1].respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify(ocsResponseRemote) + ); + var $rows = fileList.$el.find('tbody tr'); + expect($rows.length).toEqual(2); + var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); expect($tr.attr('data-id')).toEqual('49'); expect($tr.attr('data-type')).toEqual('file'); expect($tr.attr('data-file')).toEqual('local name.txt'); @@ -132,32 +171,66 @@ describe('OCA.Sharing.FileList tests', function() { '?dir=%2Flocal%20path&files=local%20name.txt' ); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); + + $tr = $rows.eq(1); + expect($tr.attr('data-id')).toEqual('1337'); + expect($tr.attr('data-type')).toEqual('file'); + expect($tr.attr('data-file')).toEqual('b.txt'); + expect($tr.attr('data-path')).toEqual(''); + expect($tr.attr('data-size')).not.toBeDefined(); + expect(parseInt($tr.attr('data-permissions'), 10)) + .toEqual(OC.PERMISSION_ALL); // read and delete + expect($tr.attr('data-mime')).toEqual('text/plain'); + expect($tr.attr('data-mtime')).toEqual('22222000'); + expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/'); + expect($tr.attr('data-share-id')).toEqual('8'); + expect($tr.find('a.name').attr('href')).toEqual( + OC.webroot + + '/index.php/apps/files/ajax/download.php' + + '?dir=%2F&files=b.txt' + ); + expect($tr.find('.nametext').text().trim()).toEqual('b.txt'); }); it('render folder shares', function() { /* jshint camelcase: false */ - var request; ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], { item_type: 'folder', file_target: '/local path/local name', path: 'files/something shared', }); - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( + ocsResponseRemote.ocs.data[0] = _.extend(ocsResponseRemote.ocs.data[0], { + type: 'dir', + mimetype: 'httpd/unix-directory', + name: '/a', + mountpoint: '/b' + }); + + expect(fakeServer.requests.length).toEqual(2); + expect(fakeServer.requests[0].url).toEqual( OC.linkToOCS('apps/files_sharing/api/v1') + 'shares?format=json&shared_with_me=true' ); + expect(fakeServer.requests[1].url).toEqual( + OC.linkToOCS('apps/files_sharing/api/v1') + + 'remote_shares?format=json' + ); fakeServer.requests[0].respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify(ocsResponse) ); + fakeServer.requests[1].respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify(ocsResponseRemote) + ); var $rows = fileList.$el.find('tbody tr'); + expect($rows.length).toEqual(2); + var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); expect($tr.attr('data-id')).toEqual('49'); expect($tr.attr('data-type')).toEqual('dir'); expect($tr.attr('data-file')).toEqual('local name'); @@ -175,6 +248,26 @@ describe('OCA.Sharing.FileList tests', function() { '?dir=/local%20path/local%20name' ); expect($tr.find('.nametext').text().trim()).toEqual('local name'); + + $tr = $rows.eq(1); + expect($tr.attr('data-id')).toEqual('1337'); + expect($tr.attr('data-type')).toEqual('dir'); + expect($tr.attr('data-file')).toEqual('b'); + expect($tr.attr('data-path')).toEqual(''); + expect($tr.attr('data-size')).not.toBeDefined(); + expect(parseInt($tr.attr('data-permissions'), 10)) + .toEqual(OC.PERMISSION_ALL); // read and delete + expect($tr.attr('data-mime')).toEqual('httpd/unix-directory'); + expect($tr.attr('data-mtime')).toEqual('22222000'); + expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/'); + expect($tr.attr('data-share-id')).toEqual('8'); + expect($tr.find('a.name').attr('href')).toEqual( + OC.webroot + + '/index.php/apps/files' + + '?dir=/b' + ); + expect($tr.find('.nametext').text().trim()).toEqual('b'); + }); }); describe('loading file list for outgoing shares', function() {