sharedialoglinkshareview.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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('onPasswordEntered', function () {
  64. var $passwordText;
  65. var $workingIcon;
  66. beforeEach(function () {
  67. // Needed to render the view
  68. configModel.isShareWithLinkAllowed.returns(true);
  69. // Setting the share also triggers the rendering
  70. shareModel.set({
  71. linkShare: {
  72. isLinkShare: true,
  73. password: 'password'
  74. }
  75. });
  76. var $passwordDiv = view.$el.find('#linkPass');
  77. $passwordText = view.$el.find('.linkPassText');
  78. $workingIcon = view.$el.find('.linkPass .icon-loading-small');
  79. sinon.stub(shareModel, 'saveLinkShare');
  80. expect($passwordDiv.hasClass('hidden')).toBeFalsy();
  81. expect($passwordText.hasClass('hidden')).toBeFalsy();
  82. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  83. $passwordText.val('myPassword');
  84. });
  85. afterEach(function () {
  86. shareModel.saveLinkShare.restore();
  87. });
  88. it('shows the working icon when called', function () {
  89. view.onPasswordEntered();
  90. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  91. expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword' }).calledOnce).toBeTruthy();
  92. });
  93. it('hides the working icon when saving the password succeeds', function () {
  94. view.onPasswordEntered();
  95. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  96. expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword' }).calledOnce).toBeTruthy();
  97. shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
  98. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  99. });
  100. it('hides the working icon when saving the password fails', function () {
  101. view.onPasswordEntered();
  102. expect($workingIcon.hasClass('hidden')).toBeFalsy();
  103. expect(shareModel.saveLinkShare.withArgs({ password: 'myPassword' }).calledOnce).toBeTruthy();
  104. shareModel.saveLinkShare.yieldTo("complete", [shareModel]);
  105. shareModel.saveLinkShare.yieldTo("error", [shareModel, "The error message"]);
  106. expect($workingIcon.hasClass('hidden')).toBeTruthy();
  107. });
  108. });
  109. });