shareSpec.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. * ownCloud
  3. *
  4. * @author Vincent Petry
  5. * @copyright 2014 Vincent Petry <pvince81@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 tests', function() {
  23. describe('markFileAsShared', function() {
  24. var $file;
  25. var tooltipStub;
  26. beforeEach(function() {
  27. tooltipStub = sinon.stub($.fn, 'tooltip');
  28. $file = $('<tr><td class="filename"><div class="thumbnail"></div><span class="name">File name</span></td></tr>');
  29. $file.find('.filename').append(
  30. '<span class="fileactions">' +
  31. '<a href="#" class="action action-share" data-action="Share">' +
  32. '<img></img><span> Share</span>' +
  33. '</a>' +
  34. '</span>'
  35. );
  36. });
  37. afterEach(function() {
  38. $file = null;
  39. tooltipStub.restore();
  40. });
  41. describe('displaying the share owner', function() {
  42. function checkOwner(input, output, title) {
  43. var $action;
  44. $file.attr('data-share-owner', input);
  45. OC.Share.markFileAsShared($file);
  46. $action = $file.find('.action-share>span');
  47. expect($action.text().trim()).toEqual(output);
  48. if (_.isString(title)) {
  49. expect($action.find('.remoteAddress').attr('title')).toEqual(title);
  50. } else {
  51. expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
  52. }
  53. expect(tooltipStub.calledOnce).toEqual(true);
  54. tooltipStub.reset();
  55. }
  56. it('displays the local share owner as is', function() {
  57. checkOwner('User One', 'User One', null);
  58. });
  59. it('displays the user name part of a remote share owner', function() {
  60. checkOwner(
  61. 'User One@someserver.com',
  62. 'User One@…',
  63. 'User One@someserver.com'
  64. );
  65. checkOwner(
  66. 'User One@someserver.com/',
  67. 'User One@…',
  68. 'User One@someserver.com'
  69. );
  70. checkOwner(
  71. 'User One@someserver.com/root/of/owncloud',
  72. 'User One@…',
  73. 'User One@someserver.com'
  74. );
  75. });
  76. it('displays the user name part with domain of a remote share owner', function() {
  77. checkOwner(
  78. 'User One@example.com@someserver.com',
  79. 'User One@example.com',
  80. 'User One@example.com@someserver.com'
  81. );
  82. checkOwner(
  83. 'User One@example.com@someserver.com/',
  84. 'User One@example.com',
  85. 'User One@example.com@someserver.com'
  86. );
  87. checkOwner(
  88. 'User One@example.com@someserver.com/root/of/owncloud',
  89. 'User One@example.com',
  90. 'User One@example.com@someserver.com'
  91. );
  92. });
  93. });
  94. describe('displaying the folder icon', function() {
  95. function checkIcon(expectedImage) {
  96. var imageUrl = OC.TestUtil.getImageUrl($file.find('.filename .thumbnail'));
  97. expectedIcon = OC.imagePath('core', expectedImage);
  98. expect(imageUrl).toEqual(expectedIcon);
  99. }
  100. it('shows a plain folder icon for non-shared folders', function() {
  101. $file.attr('data-type', 'dir');
  102. OC.Share.markFileAsShared($file);
  103. checkIcon('filetypes/folder');
  104. });
  105. it('shows a shared folder icon for folders shared with another user', function() {
  106. $file.attr('data-type', 'dir');
  107. OC.Share.markFileAsShared($file, true);
  108. checkIcon('filetypes/folder-shared');
  109. });
  110. it('shows a shared folder icon for folders shared with the current user', function() {
  111. $file.attr('data-type', 'dir');
  112. $file.attr('data-share-owner', 'someoneelse');
  113. OC.Share.markFileAsShared($file);
  114. checkIcon('filetypes/folder-shared');
  115. });
  116. it('shows a link folder icon for folders shared with link', function() {
  117. $file.attr('data-type', 'dir');
  118. OC.Share.markFileAsShared($file, false, true);
  119. checkIcon('filetypes/folder-public');
  120. });
  121. it('shows a link folder icon for folders shared with both link and another user', function() {
  122. $file.attr('data-type', 'dir');
  123. OC.Share.markFileAsShared($file, true, true);
  124. checkIcon('filetypes/folder-public');
  125. });
  126. it('shows a link folder icon for folders reshared with link', function() {
  127. $file.attr('data-type', 'dir');
  128. $file.attr('data-share-owner', 'someoneelse');
  129. OC.Share.markFileAsShared($file, false, true);
  130. checkIcon('filetypes/folder-public');
  131. });
  132. it('shows external storage icon if external mount point', function() {
  133. $file.attr('data-type', 'dir');
  134. $file.attr('data-mountType', 'external');
  135. OC.Share.markFileAsShared($file, false, false);
  136. checkIcon('filetypes/folder-external');
  137. });
  138. });
  139. describe('displaying the recipoients', function() {
  140. function checkRecipients(input, output, title) {
  141. var $action;
  142. $file.attr('data-share-recipients', input);
  143. OC.Share.markFileAsShared($file, true);
  144. $action = $file.find('.action-share>span');
  145. expect($action.text().trim()).toEqual(output);
  146. if (_.isString(title)) {
  147. expect($action.find('.remoteAddress').attr('title')).toEqual(title);
  148. } else if (_.isArray(title)) {
  149. var tooltips = $action.find('.remoteAddress');
  150. expect(tooltips.length).toEqual(title.length);
  151. tooltips.each(function(i) {
  152. expect($(this).attr('title')).toEqual(title[i]);
  153. });
  154. } else {
  155. expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
  156. }
  157. expect(tooltipStub.calledOnce).toEqual(true);
  158. tooltipStub.reset();
  159. }
  160. it('displays the local share owner as is', function() {
  161. checkRecipients('User One', 'Shared with User One', null);
  162. });
  163. it('displays the user name part of a remote recipient', function() {
  164. checkRecipients(
  165. 'User One@someserver.com',
  166. 'Shared with User One@…',
  167. 'User One@someserver.com'
  168. );
  169. checkRecipients(
  170. 'User One@someserver.com/',
  171. 'Shared with User One@…',
  172. 'User One@someserver.com'
  173. );
  174. checkRecipients(
  175. 'User One@someserver.com/root/of/owncloud',
  176. 'Shared with User One@…',
  177. 'User One@someserver.com'
  178. );
  179. });
  180. it('displays the user name part with domain of a remote share owner', function() {
  181. checkRecipients(
  182. 'User One@example.com@someserver.com',
  183. 'Shared with User One@example.com',
  184. 'User One@example.com@someserver.com'
  185. );
  186. checkRecipients(
  187. 'User One@example.com@someserver.com/',
  188. 'Shared with User One@example.com',
  189. 'User One@example.com@someserver.com'
  190. );
  191. checkRecipients(
  192. 'User One@example.com@someserver.com/root/of/owncloud',
  193. 'Shared with User One@example.com',
  194. 'User One@example.com@someserver.com'
  195. );
  196. });
  197. it('display multiple remote recipients', function() {
  198. checkRecipients(
  199. 'One@someserver.com, two@otherserver.com',
  200. 'Shared with One@…, two@…',
  201. ['One@someserver.com', 'two@otherserver.com']
  202. );
  203. checkRecipients(
  204. 'One@someserver.com/, two@otherserver.com',
  205. 'Shared with One@…, two@…',
  206. ['One@someserver.com', 'two@otherserver.com']
  207. );
  208. checkRecipients(
  209. 'One@someserver.com/root/of/owncloud, two@otherserver.com',
  210. 'Shared with One@…, two@…',
  211. ['One@someserver.com', 'two@otherserver.com']
  212. );
  213. });
  214. it('display mixed recipients', function() {
  215. checkRecipients(
  216. 'One, two@otherserver.com',
  217. 'Shared with One, two@…',
  218. ['two@otherserver.com']
  219. );
  220. });
  221. });
  222. });
  223. });