1
0

sharedialoglinkshareview.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /**
  2. *
  3. * @copyright Copyright (c) 2015, Tom Needham (tom@owncloud.com)
  4. * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. describe('OC.Share.ShareDialogLinkShareView', function () {
  23. var configModel;
  24. var shareModel;
  25. var view;
  26. beforeEach(function () {
  27. var fileInfoModel = new OCA.Files.FileInfoModel({
  28. id: 123,
  29. name: 'shared_file_name.txt',
  30. path: '/subdir',
  31. size: 100,
  32. mimetype: 'text/plain',
  33. permissions: OC.PERMISSION_ALL,
  34. sharePermissions: OC.PERMISSION_ALL
  35. });
  36. var attributes = {
  37. itemType: fileInfoModel.isDirectory() ? 'folder' : 'file',
  38. itemSource: fileInfoModel.get('id'),
  39. possiblePermissions: OC.PERMISSION_ALL,
  40. permissions: OC.PERMISSION_ALL
  41. };
  42. configModel = new OC.Share.ShareConfigModel({
  43. enforcePasswordForPublicLink: false,
  44. isResharingAllowed: true,
  45. isDefaultExpireDateEnabled: false,
  46. isDefaultExpireDateEnforced: false,
  47. defaultExpireDate: 7
  48. });
  49. sinon.stub(configModel, 'isShareWithLinkAllowed');
  50. shareModel = new OC.Share.ShareItemModel(attributes, {
  51. configModel: configModel,
  52. fileInfoModel: fileInfoModel
  53. });
  54. view = new OC.Share.ShareDialogLinkShareView({
  55. configModel: configModel,
  56. model: shareModel
  57. });
  58. });
  59. afterEach(function () {
  60. view.remove();
  61. configModel.isShareWithLinkAllowed.restore();
  62. });
  63. describe('hide download', function () {
  64. var $hideDownloadCheckbox;
  65. var $workingIcon;
  66. beforeEach(function () {
  67. // Needed to render the view
  68. configModel.isShareWithLinkAllowed.returns(true);
  69. shareModel.set({
  70. linkShares: [{
  71. id: 123
  72. }]
  73. });
  74. view.render();
  75. $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
  76. $workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
  77. sinon.stub(shareModel, 'saveLinkShare');
  78. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  79. });
  80. afterEach(function () {
  81. shareModel.saveLinkShare.restore();
  82. });
  83. it('is shown if the share is a file', function() {
  84. expect($hideDownloadCheckbox.length).toBeTruthy();
  85. });
  86. it('is not shown if the share is a folder', function() {
  87. shareModel.fileInfoModel.set('mimetype', 'httpd/unix-directory');
  88. // Setting the item type also triggers the rendering
  89. shareModel.set({
  90. itemType: 'folder'
  91. });
  92. $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
  93. expect($hideDownloadCheckbox.length).toBeTruthy();
  94. });
  95. it('checkbox is checked when the setting is enabled', function () {
  96. shareModel.set({
  97. linkShares: [{
  98. id: 123,
  99. hideDownload: true
  100. }]
  101. });
  102. view.render();
  103. $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
  104. expect($hideDownloadCheckbox.is(':checked')).toEqual(true);
  105. });
  106. it('checkbox is not checked when the setting is disabled', function () {
  107. expect($hideDownloadCheckbox.is(':checked')).toEqual(false);
  108. });
  109. it('enables the setting if clicked when unchecked', function () {
  110. // Simulate the click by checking the checkbox and then triggering
  111. // the "change" event.
  112. $hideDownloadCheckbox.prop('checked', true);
  113. $hideDownloadCheckbox.change();
  114. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  115. expect(shareModel.saveLinkShare.withArgs({ hideDownload: true, cid: 123 }).calledOnce).toBeTruthy();
  116. });
  117. it('disables the setting if clicked when checked', function () {
  118. shareModel.set({
  119. linkShares: [{
  120. id: 123,
  121. hideDownload: true
  122. }]
  123. });
  124. view.render();
  125. $hideDownloadCheckbox = view.$el.find('.hideDownloadCheckbox');
  126. $workingIcon = $hideDownloadCheckbox.prev('.icon-loading-small');
  127. // Simulate the click by unchecking the checkbox and then triggering
  128. // the "change" event.
  129. $hideDownloadCheckbox.prop('checked', false);
  130. $hideDownloadCheckbox.change();
  131. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  132. expect(shareModel.saveLinkShare.withArgs({ hideDownload: false, cid: 123 }).calledOnce).toBeTruthy();
  133. });
  134. });
  135. describe('onPasswordEntered', function () {
  136. var $passwordText;
  137. var $workingIcon;
  138. beforeEach(function () {
  139. // Needed to render the view
  140. configModel.isShareWithLinkAllowed.returns(true);
  141. shareModel.set({
  142. linkShares: [{
  143. id: 123,
  144. password: 'password'
  145. }]
  146. });
  147. view.render();
  148. $passwordText = view.$el.find('.linkPassText');
  149. $workingIcon = view.$el.find('.linkPassMenu .icon-loading-small');
  150. sinon.stub(shareModel, 'saveLinkShare');
  151. expect($passwordText.hasClass('hidden')).toBeFalsy();
  152. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  153. $passwordText.val('myPassword');
  154. });
  155. afterEach(function () {
  156. shareModel.saveLinkShare.restore();
  157. });
  158. it('shows the working icon when called', function () {
  159. view.onPasswordEntered({target: view.$el.find('.linkPassText')});
  160. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  161. expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
  162. });
  163. it('hides the working icon when saving the password succeeds', function () {
  164. view.onPasswordEntered({target: view.$el.find('.linkPassText')});
  165. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  166. expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
  167. shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
  168. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  169. });
  170. it('hides the working icon when saving the password fails', function () {
  171. view.onPasswordEntered({target: view.$el.find('.linkPassText')});
  172. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  173. expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword', cid: 123 }).calledOnce).toBeTruthy();
  174. shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
  175. shareModel.saveLinkShare.yieldTo("error", [shareModel, "The error message"]);
  176. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  177. });
  178. });
  179. describe('protect password by Talk', function () {
  180. var $passwordByTalkCheckbox;
  181. var $workingIcon;
  182. beforeEach(function () {
  183. // Needed to render the view
  184. configModel.isShareWithLinkAllowed.returns(true);
  185. // "Enable" Talk
  186. OC.appswebroots['spreed'] = OC.getRootPath() + '/apps/files/';
  187. shareModel.set({
  188. linkShares: [{
  189. id: 123,
  190. password: 'password'
  191. }]
  192. });
  193. view.render();
  194. $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
  195. $workingIcon = $passwordByTalkCheckbox.prev('.icon-loading-small');
  196. sinon.stub(shareModel, 'saveLinkShare');
  197. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  198. });
  199. afterEach(function () {
  200. shareModel.saveLinkShare.restore();
  201. });
  202. it('is shown if Talk is enabled and there is a password set', function() {
  203. expect($passwordByTalkCheckbox.length).toBeTruthy();
  204. });
  205. it('is not shown if Talk is enabled but there is no password set', function() {
  206. // Changing the password value also triggers the rendering
  207. shareModel.set({
  208. linkShares: [{
  209. id: 123
  210. }]
  211. });
  212. $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
  213. expect($passwordByTalkCheckbox.length).toBeFalsy();
  214. });
  215. it('is not shown if there is a password set but Talk is not enabled', function() {
  216. // "Disable" Talk
  217. delete OC.appswebroots['spreed'];
  218. view.render();
  219. $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
  220. expect($passwordByTalkCheckbox.length).toBeFalsy();
  221. });
  222. it('checkbox is checked when the setting is enabled', function () {
  223. shareModel.set({
  224. linkShares: [{
  225. id: 123,
  226. password: 'password',
  227. sendPasswordByTalk: true
  228. }]
  229. });
  230. view.render();
  231. $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
  232. expect($passwordByTalkCheckbox.is(':checked')).toEqual(true);
  233. });
  234. it('checkbox is not checked when the setting is disabled', function () {
  235. expect($passwordByTalkCheckbox.is(':checked')).toEqual(false);
  236. });
  237. it('enables the setting if clicked when unchecked', function () {
  238. // Simulate the click by checking the checkbox and then triggering
  239. // the "change" event.
  240. $passwordByTalkCheckbox.prop('checked', true);
  241. $passwordByTalkCheckbox.change();
  242. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  243. expect(shareModel.saveLinkShare.withArgs({ sendPasswordByTalk: true, cid: 123 }).calledOnce).toBeTruthy();
  244. });
  245. it('disables the setting if clicked when checked', function () {
  246. shareModel.set({
  247. linkShares: [{
  248. id: 123,
  249. password: 'password',
  250. sendPasswordByTalk: true
  251. }]
  252. });
  253. view.render();
  254. $passwordByTalkCheckbox = view.$el.find('.passwordByTalkCheckbox');
  255. $workingIcon = $passwordByTalkCheckbox.prev('.icon-loading-small');
  256. // Simulate the click by unchecking the checkbox and then triggering
  257. // the "change" event.
  258. $passwordByTalkCheckbox.prop('checked', false);
  259. $passwordByTalkCheckbox.change();
  260. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  261. expect(shareModel.saveLinkShare.withArgs({ sendPasswordByTalk: false, cid: 123 }).calledOnce).toBeTruthy();
  262. });
  263. });
  264. });