diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-09-27 08:07:20 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-10-19 01:46:13 +0200 |
commit | 420d1b91ab0d3c9e521bf6def682fd3c58fde997 (patch) | |
tree | e871cb10a061ebffade06c37e8b79511be802a96 /apps/files/tests | |
parent | a8f1902b02d02cc2b7d624b3d7b288f8aea84fdc (diff) | |
download | nextcloud-server-420d1b91ab0d3c9e521bf6def682fd3c58fde997.tar.gz nextcloud-server-420d1b91ab0d3c9e521bf6def682fd3c58fde997.zip |
Add "Favorite" action to the file actions menu
The new FileAction for the menu is essentially the same as the old
inline FileAction, except for the rendering; in this case the FileAction
is shown in the menu in a standard way, so there is no need to provide a
custom renderer (although the menu entry text and icon change depending
on whether the file is currently a favorite or not, but that can be done
just with displayName and iconClass functions).
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/files/tests')
-rw-r--r-- | apps/files/tests/js/tagspluginspec.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/apps/files/tests/js/tagspluginspec.js b/apps/files/tests/js/tagspluginspec.js index a4efc08aa53..e2cbaa2c4d0 100644 --- a/apps/files/tests/js/tagspluginspec.js +++ b/apps/files/tests/js/tagspluginspec.js @@ -123,6 +123,62 @@ describe('OCA.Files.TagsPlugin tests', function() { expect($action.find('.icon').hasClass('icon-star')).toEqual(true); expect($action.find('.icon').hasClass('icon-starred')).toEqual(false); }); + it('through FileActionsMenu sends request to server and updates icon', function() { + var request; + fileList.setFiles(testFiles); + var $tr = fileList.findFileEl('One.txt'); + var $action = $tr.find('.action-favorite'); + var $showMenuAction = $tr.find('.action-menu'); + $showMenuAction.click(); + var $favoriteActionInMenu = $tr.find('.fileActionsMenu .action-favorite'); + $favoriteActionInMenu.click(); + + expect(fakeServer.requests.length).toEqual(1); + 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] + })); + + // re-read the element as it was re-inserted + $tr = fileList.findFileEl('One.txt'); + $action = $tr.find('.action-favorite'); + $showMenuAction = $tr.find('.action-menu'); + + 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('.icon').hasClass('icon-star')).toEqual(false); + expect($action.find('.icon').hasClass('icon-starred')).toEqual(true); + + // show again the menu and get the new action, as the menu was + // closed and removed (and with it, the previous action) when that + // action was clicked + $showMenuAction.click(); + $favoriteActionInMenu = $tr.find('.fileActionsMenu .action-favorite'); + $favoriteActionInMenu.click(); + + expect(fakeServer.requests.length).toEqual(2); + 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'] + })); + + // re-read the element as it was re-inserted + $tr = fileList.findFileEl('One.txt'); + $action = $tr.find('.action-favorite'); + + expect($tr.attr('data-favorite')).toBeFalsy(); + expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', 'tag3']); + expect(fileList.files[0].tags).toEqual(['tag1', 'tag2', 'tag3']); + expect($action.find('.icon').hasClass('icon-star')).toEqual(true); + expect($action.find('.icon').hasClass('icon-starred')).toEqual(false); + }); }); describe('elementToFile', function() { it('returns tags', function() { |