You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shareSpec.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. describe('OC.Share tests', function() {
  22. describe('markFileAsShared', function() {
  23. var $file;
  24. var tooltipStub;
  25. beforeEach(function() {
  26. tooltipStub = sinon.stub($.fn, 'tooltip');
  27. $file = $('<tr><td class="filename"><div class="thumbnail"></div><span class="name">File name</span></td></tr>');
  28. $file.find('.filename').append(
  29. '<span class="fileactions">' +
  30. '<a href="#" class="action action-share" data-action="Share">' +
  31. '<img></img><span> Share</span>' +
  32. '</a>' +
  33. '</span>'
  34. );
  35. });
  36. afterEach(function() {
  37. $file = null;
  38. tooltipStub.restore();
  39. });
  40. describe('displaying the share owner', function() {
  41. function checkOwner(input, output, title) {
  42. var $action;
  43. $file.attr('data-share-owner', input);
  44. $file.attr('data-share-owner-id', input);
  45. OC.Share.markFileAsShared($file);
  46. $action = $file.find('.action-share>span').parent();
  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 with "Shared by" prefix', function() {
  57. checkOwner('User One', 'Shared by 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. 'Shared by User One@someserver.com'
  64. );
  65. checkOwner(
  66. 'User One@someserver.com/',
  67. 'User One@…',
  68. 'Shared by User One@someserver.com'
  69. );
  70. checkOwner(
  71. 'User One@someserver.com/root/of/owncloud',
  72. 'User One@…',
  73. 'Shared by 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. 'Shared by User One@example.com@someserver.com'
  81. );
  82. checkOwner(
  83. 'User One@example.com@someserver.com/',
  84. 'User One@example.com',
  85. 'Shared by 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. 'Shared by 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. $file.attr('data-share-owner-id', 'someoneelse');
  114. OC.Share.markFileAsShared($file);
  115. checkIcon('filetypes/folder-shared');
  116. });
  117. it('shows a link folder icon for folders shared with link', function() {
  118. $file.attr('data-type', 'dir');
  119. OC.Share.markFileAsShared($file, false, true);
  120. checkIcon('filetypes/folder-public');
  121. });
  122. it('shows a link folder icon for folders shared with both link and another user', function() {
  123. $file.attr('data-type', 'dir');
  124. OC.Share.markFileAsShared($file, true, true);
  125. checkIcon('filetypes/folder-public');
  126. });
  127. it('shows a link folder icon for folders reshared with link', function() {
  128. $file.attr('data-type', 'dir');
  129. $file.attr('data-share-owner', 'someoneelse');
  130. OC.Share.markFileAsShared($file, false, true);
  131. checkIcon('filetypes/folder-public');
  132. });
  133. it('shows external storage icon if external mount point', function() {
  134. $file.attr('data-type', 'dir');
  135. $file.attr('data-mountType', 'external');
  136. OC.Share.markFileAsShared($file, false, false);
  137. checkIcon('filetypes/folder-external');
  138. });
  139. it('shows encrypted icon if encrypted folder', function() {
  140. $file.attr('data-type', 'dir');
  141. $file.attr('data-e2eencrypted', true);
  142. OC.Share.markFileAsShared($file, false, false);
  143. checkIcon('filetypes/folder-encrypted');
  144. });
  145. });
  146. describe('displaying the recipients', function() {
  147. function checkRecipients(input, output, title) {
  148. var $action;
  149. $file.attr('data-share-recipient-data', JSON.stringify(input));
  150. OC.Share.markFileAsShared($file, true);
  151. $action = $file.find('.action-share>span').parent();
  152. expect($action.text().trim()).toEqual(output);
  153. if (_.isString(title)) {
  154. expect($action.find('.remoteAddress').attr('title')).toEqual(title);
  155. } else if (_.isArray(title)) {
  156. var tooltips = $action.find('.remoteAddress');
  157. expect(tooltips.length).toEqual(title.length);
  158. tooltips.each(function(i) {
  159. expect($(this).attr('title')).toEqual(title[i]);
  160. });
  161. } else {
  162. expect($action.find('.remoteAddress').attr('title')).not.toBeDefined();
  163. }
  164. expect(tooltipStub.calledOnce).toEqual(true);
  165. tooltipStub.reset();
  166. }
  167. it('displays the local share owner as is', function() {
  168. var input = {
  169. 0: {
  170. shareWith: 'User One',
  171. shareWithDisplayName: 'User One'
  172. }
  173. };
  174. checkRecipients(input, 'Shared with User One', null);
  175. });
  176. it('displays the user name part of a remote recipient', function() {
  177. var input = {
  178. 0: {
  179. shareWith: 'User One@someserver.com',
  180. shareWithDisplayName: 'User One@someserver.com'
  181. }
  182. };
  183. checkRecipients(
  184. input,
  185. 'User One@…',
  186. 'Shared with User One@someserver.com'
  187. );
  188. input = {
  189. 0: {
  190. shareWith: 'User One@someserver.com/',
  191. shareWithDisplayName: 'User One@someserver.com/'
  192. }
  193. };
  194. checkRecipients(
  195. input,
  196. 'User One@…',
  197. 'Shared with User One@someserver.com'
  198. );
  199. input = {
  200. 0: {
  201. shareWith: 'User One@someserver.com/root/of/nextcloud',
  202. shareWithDisplayName: 'User One@someserver.com/root/of/nextcloud'
  203. }
  204. };
  205. checkRecipients(
  206. input,
  207. 'User One@…',
  208. 'Shared with User One@someserver.com'
  209. );
  210. });
  211. it('displays the user name part with domain of a remote share owner', function() {
  212. var input = {
  213. 0: {
  214. shareWith: 'User One@example.com@someserver.com',
  215. shareWithDisplayName: 'User One@example.com@someserver.com'
  216. }
  217. };
  218. checkRecipients(
  219. input,
  220. 'User One@example.com',
  221. 'Shared with User One@example.com@someserver.com'
  222. );
  223. input = {
  224. 0: {
  225. shareWith: 'User One@example.com@someserver.com/',
  226. shareWithDisplayName: 'User One@example.com@someserver.com/'
  227. }
  228. };
  229. checkRecipients(
  230. input,
  231. 'User One@example.com',
  232. 'Shared with User One@example.com@someserver.com'
  233. );
  234. input = {
  235. 0: {
  236. shareWith: 'User One@example.com@someserver.com/root/of/nextcloud',
  237. shareWithDisplayName: 'User One@example.com@someserver.com/root/of/nextcloud'
  238. }
  239. };
  240. checkRecipients(
  241. input,
  242. 'User One@example.com',
  243. 'Shared with User One@example.com@someserver.com'
  244. );
  245. });
  246. it('display multiple remote recipients', function() {
  247. var input = {
  248. 0: {
  249. shareWith: 'One@someserver.com',
  250. shareWithDisplayName: 'One@someserver.com'
  251. },
  252. 1: {
  253. shareWith: 'two@otherserver.com',
  254. shareWithDisplayName: 'two@otherserver.com'
  255. }
  256. };
  257. checkRecipients(
  258. input,
  259. 'One@… two@…',
  260. ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
  261. );
  262. input = {
  263. 0: {
  264. shareWith: 'One@someserver.com/',
  265. shareWithDisplayName: 'One@someserver.com/'
  266. },
  267. 1: {
  268. shareWith: 'two@someserver.com',
  269. shareWithDisplayName: 'two@someserver.com'
  270. }
  271. };
  272. checkRecipients(
  273. input,
  274. 'One@… two@…',
  275. ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
  276. );
  277. input = {
  278. 0: {
  279. shareWith: 'One@someserver.com/root/of/nextcloud',
  280. shareWithDisplayName: 'One@someserver.com/root/of/nextcloud'
  281. },
  282. 1: {
  283. shareWith: 'two@someserver.com',
  284. shareWithDisplayName: 'two@someserver.com'
  285. }
  286. };
  287. checkRecipients(
  288. input,
  289. 'One@… two@…',
  290. ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
  291. );
  292. });
  293. it('display mixed recipients', function() {
  294. checkRecipients(
  295. {
  296. 0: {
  297. shareWith: 'One',
  298. shareWithDisplayName: 'One'
  299. },
  300. 1: {
  301. shareWith: 'two@otherserver.com',
  302. shareWithDisplayName: 'two@otherserver.com'
  303. }
  304. },
  305. 'Shared with One two@…',
  306. ['Shared with two@otherserver.com']
  307. );
  308. });
  309. it('display multiple with divergent displaynames', function() {
  310. var recipients = {
  311. 0: {
  312. shareWith: 'One',
  313. shareWithDisplayName: 'Yoko Ono',
  314. _output: 'Shared with Yoko Ono'
  315. },
  316. 1: {
  317. shareWith: 'two@otherserver.com',
  318. shareWithDisplayName: 'two@othererver.com',
  319. _output: 'two@…'
  320. },
  321. 2: {
  322. shareWith: 'Three',
  323. shareWithDisplayName: 'Green, Mina',
  324. _output: 'Shared with Green, Mina'
  325. }
  326. };
  327. // we cannot assume the locale, also because PhantomJS has a bug.
  328. var sortArray = _.toArray(recipients)
  329. .sort(function(a, b) {
  330. return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName);
  331. });
  332. var sortedOutput = _.map(sortArray, function(recipient) {
  333. return recipient._output;
  334. }).join(' ');
  335. checkRecipients(
  336. recipients,
  337. sortedOutput,
  338. ['Shared with two@otherserver.com']
  339. );
  340. });
  341. });
  342. });
  343. });