]> source.dussan.org Git - nextcloud-server.git/commitdiff
Properly update internal file info with updated tags
authorVincent Petry <pvince81@owncloud.com>
Mon, 12 Jan 2015 16:54:35 +0000 (17:54 +0100)
committerVincent Petry <pvince81@owncloud.com>
Mon, 12 Jan 2015 16:58:57 +0000 (17:58 +0100)
Whenever tags are updated, they need to be updated in the file list's
file info array as well.

This commit also adds unit tests and makes sure that whichever tags are
sent back by the server after update are used when updating
attributes/fileinfo.

apps/files/js/tagsplugin.js
apps/files/tests/js/tagspluginspec.js

index a6757431ffaeea2f49a051a92ef83244a9f14fa8..dec6063aa9b8d0f408f60ca4f4a7187d9e82b1ca 100644 (file)
                                                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;
                                        });
                                }
                        });
index 66240575a5c5b1ecac3ed6ec5e508bb4e42dc5f0..5309973cf4f82f87d708adafda0b632d19dfdf23 100644 (file)
@@ -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'));
                });
        });
 });