summaryrefslogtreecommitdiffstats
path: root/core/js/tests
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-10-22 11:06:53 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-10-30 15:18:55 +0100
commita1e3098322f3747181466632f11764ee6a8232a0 (patch)
treee57893b213d30baff1ed9023667786350269c9ee /core/js/tests
parentbfb2a914d26ed05db871e961b66c3eddd5463de7 (diff)
downloadnextcloud-server-a1e3098322f3747181466632f11764ee6a8232a0.tar.gz
nextcloud-server-a1e3098322f3747181466632f11764ee6a8232a0.zip
Add "Hide download" to the menu of link shares
Hiding the download does not depend on other settings and it does not affect other settings either (for example, it would be possible to hide the downloads yet make the share editable), so a simple checkbox was added to the menu. However, note that this option is only available for files, but not for folders. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'core/js/tests')
-rw-r--r--core/js/tests/specs/sharedialoglinkshareview.js94
-rw-r--r--core/js/tests/specs/shareitemmodelSpec.js13
2 files changed, 104 insertions, 3 deletions
diff --git a/core/js/tests/specs/sharedialoglinkshareview.js b/core/js/tests/specs/sharedialoglinkshareview.js
index 9d07dcb479d..d8dec3968e3 100644
--- a/core/js/tests/specs/sharedialoglinkshareview.js
+++ b/core/js/tests/specs/sharedialoglinkshareview.js
@@ -72,6 +72,100 @@ describe('OC.Share.ShareDialogLinkShareView', function () {
configModel.isShareWithLinkAllowed.restore();
});
+ describe('hide download', function () {
+
+ var $hideDownloadCheckbox;
+ var $workingIcon;
+
+ beforeEach(function () {
+ // Needed to render the view
+ configModel.isShareWithLinkAllowed.returns(true);
+
+ // Setting the share also triggers the rendering
+ shareModel.set({
+ linkShare: {
+ isLinkShare: true,
+ }
+ });
+
+ $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
+ $workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
+
+ sinon.stub(shareModel, 'saveLinkShare');
+
+ expect($workingIcon.hasClass('hidden')).toBeTruthy();
+ });
+
+ afterEach(function () {
+ shareModel.saveLinkShare.restore();
+ });
+
+ it('is shown if the share is a file', function() {
+ expect($hideDownloadCheckbox.length).toBeTruthy();
+ });
+
+ it('is not shown if the share is a folder', function() {
+ shareModel.fileInfoModel.set('mimetype', 'httpd/unix-directory');
+
+ // Setting the item type also triggers the rendering
+ shareModel.set({
+ itemType: 'folder'
+ });
+
+ $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
+
+ expect($hideDownloadCheckbox.length).toBeFalsy();
+ });
+
+ it('checkbox is checked when the setting is enabled', function () {
+ shareModel.set({
+ linkShare: {
+ isLinkShare: true,
+ hideDownload: true
+ }
+ });
+
+ $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
+
+ expect($hideDownloadCheckbox.is(':checked')).toEqual(true);
+ });
+
+ it('checkbox is not checked when the setting is disabled', function () {
+ expect($hideDownloadCheckbox.is(':checked')).toEqual(false);
+ });
+
+ it('enables the setting if clicked when unchecked', function () {
+ // Simulate the click by checking the checkbox and then triggering
+ // the "change" event.
+ $hideDownloadCheckbox.prop('checked', true);
+ $hideDownloadCheckbox.change();
+
+ expect($workingIcon.hasClass('hidden')).toBeFalsy();
+ expect(shareModel.saveLinkShare.withArgs({ hideDownload: true }).calledOnce).toBeTruthy();
+ });
+
+ it('disables the setting if clicked when checked', function () {
+ shareModel.set({
+ linkShare: {
+ isLinkShare: true,
+ hideDownload: true
+ }
+ });
+
+ $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
+ $workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
+
+ // Simulate the click by unchecking the checkbox and then triggering
+ // the "change" event.
+ $hideDownloadCheckbox.prop('checked', false);
+ $hideDownloadCheckbox.change();
+
+ expect($workingIcon.hasClass('hidden')).toBeFalsy();
+ expect(shareModel.saveLinkShare.withArgs({ hideDownload: false }).calledOnce).toBeTruthy();
+ });
+
+ });
+
describe('onPasswordEntered', function () {
var $passwordText;
diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js
index 2e89b2e3cda..a2eabbf4ae4 100644
--- a/core/js/tests/specs/shareitemmodelSpec.js
+++ b/core/js/tests/specs/shareitemmodelSpec.js
@@ -168,7 +168,8 @@ describe('OC.Share.ShareItemModel', function() {
stime: 1403884258,
storage: 1,
token: 'tehtoken',
- uid_owner: 'root'
+ uid_owner: 'root',
+ hide_download: 1
}
]));
@@ -186,6 +187,7 @@ describe('OC.Share.ShareItemModel', function() {
var linkShare = model.get('linkShare');
expect(linkShare.isLinkShare).toEqual(true);
+ expect(linkShare.hideDownload).toEqual(true);
// TODO: check more attributes
});
@@ -289,7 +291,8 @@ describe('OC.Share.ShareItemModel', function() {
stime: 1403884258,
storage: 1,
token: 'tehtoken',
- uid_owner: 'root'
+ uid_owner: 'root',
+ hide_download: 0
}, {
displayname_owner: 'root',
expiration: '2015-10-15 00:00:00',
@@ -307,7 +310,8 @@ describe('OC.Share.ShareItemModel', function() {
stime: 1403884509,
storage: 1,
token: 'anothertoken',
- uid_owner: 'root'
+ uid_owner: 'root',
+ hide_download: 1
}]
));
OC.currentUser = 'root';
@@ -320,6 +324,7 @@ describe('OC.Share.ShareItemModel', function() {
var linkShare = model.get('linkShare');
expect(linkShare.isLinkShare).toEqual(true);
expect(linkShare.token).toEqual('tehtoken');
+ expect(linkShare.hideDownload).toEqual(false);
// TODO: check child too
});
@@ -579,6 +584,7 @@ describe('OC.Share.ShareItemModel', function() {
expect(addShareStub.calledOnce).toEqual(true);
expect(addShareStub.firstCall.args[0]).toEqual({
+ hideDownload: false,
password: '',
passwordChanged: false,
permissions: OC.PERMISSION_READ,
@@ -603,6 +609,7 @@ describe('OC.Share.ShareItemModel', function() {
expect(addShareStub.calledOnce).toEqual(true);
expect(addShareStub.firstCall.args[0]).toEqual({
+ hideDownload: false,
password: '',
passwordChanged: false,
permissions: OC.PERMISSION_READ,