Fix and extend unit tests
This commit is contained in:
parent
40dd2d9dbe
commit
4adc78b78b
|
@ -151,6 +151,9 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
promises.push(remoteShares);
|
promises.push(remoteShares);
|
||||||
|
} else {
|
||||||
|
//Push empty promise so callback gets called the same way
|
||||||
|
promises.push($.Deferred().resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
this._reloadCall = $.when.apply($, promises);
|
this._reloadCall = $.when.apply($, promises);
|
||||||
|
@ -174,7 +177,7 @@
|
||||||
// TODO: error handling
|
// 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));
|
files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data));
|
||||||
} else {
|
} else {
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
|
@ -193,11 +196,12 @@
|
||||||
var file = {
|
var file = {
|
||||||
shareOwner: share.owner + '@' + share.remote.replace(/.*?:\/\//g, ""),
|
shareOwner: share.owner + '@' + share.remote.replace(/.*?:\/\//g, ""),
|
||||||
name: OC.basename(share.mountpoint),
|
name: OC.basename(share.mountpoint),
|
||||||
mtime: share.mtime,
|
mtime: share.mtime * 1000,
|
||||||
mimetype: share.mimetype,
|
mimetype: share.mimetype,
|
||||||
type: share.type,
|
type: share.type,
|
||||||
id: share.file_id,
|
id: share.file_id,
|
||||||
path: OC.dirname(share.mountpoint)
|
path: OC.dirname(share.mountpoint),
|
||||||
|
permissions: share.permissions
|
||||||
};
|
};
|
||||||
|
|
||||||
file.shares = [{
|
file.shares = [{
|
||||||
|
|
|
@ -57,6 +57,7 @@ describe('OCA.Sharing.FileList tests', function() {
|
||||||
|
|
||||||
describe('loading file list for incoming shares', function() {
|
describe('loading file list for incoming shares', function() {
|
||||||
var ocsResponse;
|
var ocsResponse;
|
||||||
|
var ocsResponseRemote;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
fileList = new OCA.Sharing.FileList(
|
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() {
|
it('render file shares', function() {
|
||||||
var request;
|
expect(fakeServer.requests.length).toEqual(2);
|
||||||
|
expect(fakeServer.requests[0].url).toEqual(
|
||||||
expect(fakeServer.requests.length).toEqual(1);
|
|
||||||
request = fakeServer.requests[0];
|
|
||||||
expect(request.url).toEqual(
|
|
||||||
OC.linkToOCS('apps/files_sharing/api/v1') +
|
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||||
'shares?format=json&shared_with_me=true'
|
'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(
|
fakeServer.requests[0].respond(
|
||||||
200,
|
200,
|
||||||
{ 'Content-Type': 'application/json' },
|
{ 'Content-Type': 'application/json' },
|
||||||
JSON.stringify(ocsResponse)
|
JSON.stringify(ocsResponse)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fakeServer.requests[1].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify(ocsResponseRemote)
|
||||||
|
);
|
||||||
|
|
||||||
var $rows = fileList.$el.find('tbody tr');
|
var $rows = fileList.$el.find('tbody tr');
|
||||||
|
expect($rows.length).toEqual(2);
|
||||||
|
|
||||||
var $tr = $rows.eq(0);
|
var $tr = $rows.eq(0);
|
||||||
expect($rows.length).toEqual(1);
|
|
||||||
expect($tr.attr('data-id')).toEqual('49');
|
expect($tr.attr('data-id')).toEqual('49');
|
||||||
expect($tr.attr('data-type')).toEqual('file');
|
expect($tr.attr('data-type')).toEqual('file');
|
||||||
expect($tr.attr('data-file')).toEqual('local name.txt');
|
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'
|
'?dir=%2Flocal%20path&files=local%20name.txt'
|
||||||
);
|
);
|
||||||
expect($tr.find('.nametext').text().trim()).toEqual('local name.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() {
|
it('render folder shares', function() {
|
||||||
/* jshint camelcase: false */
|
/* jshint camelcase: false */
|
||||||
var request;
|
|
||||||
ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], {
|
ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], {
|
||||||
item_type: 'folder',
|
item_type: 'folder',
|
||||||
file_target: '/local path/local name',
|
file_target: '/local path/local name',
|
||||||
path: 'files/something shared',
|
path: 'files/something shared',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(fakeServer.requests.length).toEqual(1);
|
ocsResponseRemote.ocs.data[0] = _.extend(ocsResponseRemote.ocs.data[0], {
|
||||||
request = fakeServer.requests[0];
|
type: 'dir',
|
||||||
expect(request.url).toEqual(
|
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') +
|
OC.linkToOCS('apps/files_sharing/api/v1') +
|
||||||
'shares?format=json&shared_with_me=true'
|
'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(
|
fakeServer.requests[0].respond(
|
||||||
200,
|
200,
|
||||||
{ 'Content-Type': 'application/json' },
|
{ 'Content-Type': 'application/json' },
|
||||||
JSON.stringify(ocsResponse)
|
JSON.stringify(ocsResponse)
|
||||||
);
|
);
|
||||||
|
fakeServer.requests[1].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify(ocsResponseRemote)
|
||||||
|
);
|
||||||
|
|
||||||
var $rows = fileList.$el.find('tbody tr');
|
var $rows = fileList.$el.find('tbody tr');
|
||||||
|
expect($rows.length).toEqual(2);
|
||||||
|
|
||||||
var $tr = $rows.eq(0);
|
var $tr = $rows.eq(0);
|
||||||
expect($rows.length).toEqual(1);
|
|
||||||
expect($tr.attr('data-id')).toEqual('49');
|
expect($tr.attr('data-id')).toEqual('49');
|
||||||
expect($tr.attr('data-type')).toEqual('dir');
|
expect($tr.attr('data-type')).toEqual('dir');
|
||||||
expect($tr.attr('data-file')).toEqual('local name');
|
expect($tr.attr('data-file')).toEqual('local name');
|
||||||
|
@ -175,6 +248,26 @@ describe('OCA.Sharing.FileList tests', function() {
|
||||||
'?dir=/local%20path/local%20name'
|
'?dir=/local%20path/local%20name'
|
||||||
);
|
);
|
||||||
expect($tr.find('.nametext').text().trim()).toEqual('local name');
|
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() {
|
describe('loading file list for outgoing shares', function() {
|
||||||
|
|
Loading…
Reference in New Issue