sharedialogshareelistview.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * ownCloud
  3. *
  4. * @author Tom Needham
  5. * @copyright 2015 Tom Needham <tom@owncloud.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. /* global oc_appconfig */
  22. describe('OC.Share.ShareDialogShareeListView', function () {
  23. var oldCurrentUser;
  24. var fileInfoModel;
  25. var configModel;
  26. var shareModel;
  27. var listView;
  28. var updateShareStub;
  29. beforeEach(function () {
  30. /* jshint camelcase:false */
  31. oldAppConfig = _.extend({}, oc_appconfig.core);
  32. oc_appconfig.core.enforcePasswordForPublicLink = false;
  33. fileInfoModel = new OCA.Files.FileInfoModel({
  34. id: 123,
  35. name: 'shared_file_name.txt',
  36. path: '/subdir',
  37. size: 100,
  38. mimetype: 'text/plain',
  39. permissions: 31,
  40. sharePermissions: 31
  41. });
  42. var attributes = {
  43. itemType: fileInfoModel.isDirectory() ? 'folder' : 'file',
  44. itemSource: fileInfoModel.get('id'),
  45. possiblePermissions: 31,
  46. permissions: 31
  47. };
  48. shareModel = new OC.Share.ShareItemModel(attributes, {
  49. configModel: configModel,
  50. fileInfoModel: fileInfoModel
  51. });
  52. configModel = new OC.Share.ShareConfigModel({
  53. enforcePasswordForPublicLink: false,
  54. isResharingAllowed: true,
  55. isDefaultExpireDateEnabled: false,
  56. isDefaultExpireDateEnforced: false,
  57. defaultExpireDate: 7
  58. });
  59. listView = new OC.Share.ShareDialogShareeListView({
  60. configModel: configModel,
  61. model: shareModel
  62. });
  63. // required for proper event propagation when simulating clicks in some cases (jquery bugs)
  64. $('#testArea').append(listView.$el);
  65. shareModel.set({
  66. linkShare: {isLinkShare: false}
  67. });
  68. oldCurrentUser = OC.currentUser;
  69. OC.currentUser = 'user0';
  70. updateShareStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'updateShare');
  71. });
  72. afterEach(function () {
  73. OC.currentUser = oldCurrentUser;
  74. /* jshint camelcase:false */
  75. oc_appconfig.core = oldAppConfig;
  76. listView.remove();
  77. updateShareStub.restore();
  78. });
  79. describe('Manages checkbox events correctly', function () {
  80. it('Checks cruds boxes when edit box checked', function () {
  81. shareModel.set('shares', [{
  82. id: 100,
  83. item_source: 123,
  84. permissions: 1,
  85. share_type: OC.Share.SHARE_TYPE_USER,
  86. share_with: 'user1',
  87. share_with_displayname: 'User One'
  88. }]);
  89. shareModel.set('itemType', 'folder');
  90. listView.render();
  91. listView.$el.find("input[name='edit']").click();
  92. expect(listView.$el.find("input[name='update']").is(':checked')).toEqual(true);
  93. expect(updateShareStub.calledOnce).toEqual(true);
  94. });
  95. it('Checks edit box when create/update/delete are checked', function () {
  96. shareModel.set('shares', [{
  97. id: 100,
  98. item_source: 123,
  99. permissions: 1,
  100. share_type: OC.Share.SHARE_TYPE_USER,
  101. share_with: 'user1',
  102. share_with_displayname: 'User One',
  103. itemType: 'folder'
  104. }]);
  105. shareModel.set('itemType', 'folder');
  106. listView.render();
  107. listView.$el.find("input[name='update']").click();
  108. expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
  109. expect(updateShareStub.calledOnce).toEqual(true);
  110. });
  111. it('shows cruds checkboxes when toggled', function () {
  112. shareModel.set('shares', [{
  113. id: 100,
  114. item_source: 123,
  115. permissions: 1,
  116. share_type: OC.Share.SHARE_TYPE_USER,
  117. share_with: 'user1',
  118. share_with_displayname: 'User One'
  119. }]);
  120. listView.render();
  121. listView.$el.find('a.showCruds').click();
  122. expect(listView.$el.find('li.cruds').hasClass('hidden')).toEqual(false);
  123. });
  124. });
  125. });