summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-01-13 08:28:30 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-01-13 08:28:30 +0100
commitc4aeb0b5b543de8f6e5e5296937ab81914e5cc7d (patch)
tree2a26e0c84562ddfc152ff3ecf7625a6d72c619d1 /apps/files
parent3ece0a7767e51082d89c549a742f0faed0b7eda5 (diff)
parentef1dd3ea0ae74a72f92ab1c6504cd24a2bd865c9 (diff)
downloadnextcloud-server-c4aeb0b5b543de8f6e5e5296937ab81914e5cc7d.tar.gz
nextcloud-server-c4aeb0b5b543de8f6e5e5296937ab81914e5cc7d.zip
Merge pull request #13289 from owncloud/fav-keepfavoncancelrename
Properly update internal file info with updated tags
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/js/tagsplugin.js11
-rw-r--r--apps/files/tests/js/tagspluginspec.js36
2 files changed, 41 insertions, 6 deletions
diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js
index a6757431ffa..dec6063aa9b 100644
--- a/apps/files/js/tagsplugin.js
+++ b/apps/files/js/tagsplugin.js
@@ -110,10 +110,17 @@
dir + '/' + fileName,
tags
).then(function(result) {
+ // response from server should contain updated tags
+ var newTags = result.tags;
+ if (_.isUndefined(newTags)) {
+ newTags = tags;
+ }
+ var fileInfo = context.fileList.files[$file.index()];
// read latest state from result
- toggleStar($actionEl, (result.tags.indexOf(OC.TAG_FAVORITE) >= 0));
- $file.attr('data-tags', tags.join('|'));
+ toggleStar($actionEl, (newTags.indexOf(OC.TAG_FAVORITE) >= 0));
+ $file.attr('data-tags', newTags.join('|'));
$file.attr('data-favorite', !isFavorite);
+ fileInfo.tags = newTags;
});
}
});
diff --git a/apps/files/tests/js/tagspluginspec.js b/apps/files/tests/js/tagspluginspec.js
index 66240575a5c..5309973cf4f 100644
--- a/apps/files/tests/js/tagspluginspec.js
+++ b/apps/files/tests/js/tagspluginspec.js
@@ -77,11 +77,39 @@ describe('OCA.Files.TagsPlugin tests', function() {
});
describe('Applying tags', function() {
it('sends request to server and updates icon', function() {
- // TODO
+ var request;
fileList.setFiles(testFiles);
- });
- it('sends all tags to server when applyFileTags() is called ', function() {
- // TODO
+ $tr = fileList.$el.find('tbody tr:first');
+ $action = $tr.find('.action-favorite');
+ $action.click();
+
+ expect(fakeServer.requests.length).toEqual(1);
+ var request = fakeServer.requests[0];
+ expect(JSON.parse(request.requestBody)).toEqual({
+ tags: ['tag1', 'tag2', OC.TAG_FAVORITE]
+ });
+ request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({
+ tags: ['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]
+ }));
+
+ expect($tr.attr('data-favorite')).toEqual('true');
+ expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]);
+ expect(fileList.files[0].tags).toEqual(['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]);
+ expect($action.find('img').attr('src')).toEqual(OC.imagePath('core', 'actions/starred'));
+
+ $action.click();
+ request = fakeServer.requests[1];
+ expect(JSON.parse(request.requestBody)).toEqual({
+ tags: ['tag1', 'tag2', 'tag3']
+ });
+ request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({
+ tags: ['tag1', 'tag2', 'tag3']
+ }));
+
+ expect($tr.attr('data-favorite')).toEqual('false');
+ expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', 'tag3']);
+ expect(fileList.files[0].tags).toEqual(['tag1', 'tag2', 'tag3']);
+ expect($action.find('img').attr('src')).toEqual(OC.imagePath('core', 'actions/star'));
});
});
});