1
0

shareSpec.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /**
  2. * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  5. * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
  6. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Vincent Petry <vincent@nextcloud.com>
  11. *
  12. * @license AGPL-3.0-or-later
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. describe('OCA.Sharing.Util tests', function() {
  29. var fileList;
  30. var testFiles;
  31. function getImageUrl($el) {
  32. // might be slightly different cross-browser
  33. var url = $el.css('background-image');
  34. var r = url.match(/url\(['"]?([^'")]*)['"]?\)/);
  35. if (!r) {
  36. return url;
  37. }
  38. return r[1];
  39. }
  40. beforeEach(function() {
  41. var $content = $('<div id="app-content"></div>');
  42. $('#testArea').append($content);
  43. // dummy file list
  44. var $div = $(
  45. '<div id="listContainer">' +
  46. '<table class="files-filestable list-container view-grid">' +
  47. '<thead></thead>' +
  48. '<tbody class="files-fileList"></tbody>' +
  49. '</table>' +
  50. '</div>');
  51. $('#app-content').append($div);
  52. var fileActions = new OCA.Files.FileActions();
  53. fileList = new OCA.Files.FileList(
  54. $div, {
  55. fileActions : fileActions
  56. }
  57. );
  58. OCA.Sharing.Util.attach(fileList);
  59. testFiles = [{
  60. id: 1,
  61. type: 'file',
  62. name: 'One.txt',
  63. path: '/subdir',
  64. mimetype: 'text/plain',
  65. size: 12,
  66. permissions: OC.PERMISSION_ALL,
  67. etag: 'abc',
  68. shareOwner: 'User One',
  69. isShareMountPoint: false,
  70. shareTypes: [OC.Share.SHARE_TYPE_USER]
  71. }];
  72. });
  73. afterEach(function() {
  74. delete OCA.Sharing.sharesLoaded;
  75. delete OC.Share.droppedDown;
  76. fileList.destroy();
  77. fileList = null;
  78. });
  79. describe('Sharing data in table row', function() {
  80. // TODO: test data-permissions, data-share-owner, etc
  81. });
  82. describe('Share action icon', function() {
  83. it('do not shows share text when not shared', function() {
  84. var $action, $tr;
  85. OC.Share.statuses = {};
  86. fileList.setFiles([{
  87. id: 1,
  88. type: 'dir',
  89. name: 'One',
  90. path: '/subdir',
  91. mimetype: 'httpd/unix-directory',
  92. size: 12,
  93. permissions: OC.PERMISSION_ALL,
  94. etag: 'abc',
  95. shareTypes: []
  96. }]);
  97. $tr = fileList.$el.find('tbody tr:first');
  98. $action = $tr.find('.action-share');
  99. expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
  100. expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
  101. expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder.svg');
  102. });
  103. it('shows simple share text with share icon', function() {
  104. var $action, $tr;
  105. fileList.setFiles([{
  106. id: 1,
  107. type: 'dir',
  108. name: 'One',
  109. path: '/subdir',
  110. mimetype: 'text/plain',
  111. size: 12,
  112. permissions: OC.PERMISSION_ALL,
  113. etag: 'abc',
  114. shareTypes: [OC.Share.SHARE_TYPE_USER]
  115. }]);
  116. $tr = fileList.$el.find('tbody tr:first');
  117. $action = $tr.find('.action-share');
  118. expect($action.find('>span').text().trim()).toEqual('Shared');
  119. expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
  120. expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
  121. expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
  122. });
  123. it('shows simple share text with share icon when shared to a room', function() {
  124. var $action, $tr;
  125. fileList.setFiles([{
  126. id: 1,
  127. type: 'dir',
  128. name: 'One',
  129. path: '/subdir',
  130. mimetype: 'text/plain',
  131. size: 12,
  132. permissions: OC.PERMISSION_ALL,
  133. etag: 'abc',
  134. shareTypes: [OC.Share.SHARE_TYPE_ROOM]
  135. }]);
  136. $tr = fileList.$el.find('tbody tr:first');
  137. $action = $tr.find('.action-share');
  138. expect($action.find('>span').text().trim()).toEqual('Shared');
  139. expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
  140. expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
  141. expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
  142. });
  143. it('shows simple share text with public icon when shared with link', function() {
  144. var $action, $tr;
  145. OC.Share.statuses = {1: {link: true, path: '/subdir'}};
  146. fileList.setFiles([{
  147. id: 1,
  148. type: 'dir',
  149. name: 'One',
  150. path: '/subdir',
  151. mimetype: 'text/plain',
  152. size: 12,
  153. permissions: OC.PERMISSION_ALL,
  154. etag: 'abc',
  155. shareTypes: [OC.Share.SHARE_TYPE_LINK]
  156. }]);
  157. $tr = fileList.$el.find('tbody tr:first');
  158. $action = $tr.find('.action-share');
  159. expect($action.find('>span').text().trim()).toEqual('Shared');
  160. expect($action.find('.icon').hasClass('icon-shared')).toEqual(false);
  161. expect($action.find('.icon').hasClass('icon-public')).toEqual(true);
  162. expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-public.svg');
  163. });
  164. it('shows owner name when owner is available but no icons', function() {
  165. var $action, $tr;
  166. fileList.setFiles([{
  167. id: 1,
  168. type: 'dir',
  169. name: 'One.txt',
  170. path: '/subdir',
  171. mimetype: 'text/plain',
  172. size: 12,
  173. permissions: OC.PERMISSION_ALL,
  174. shareOwner: 'User One',
  175. shareOwnerId: 'User One',
  176. etag: 'abc',
  177. shareTypes: []
  178. }]);
  179. $tr = fileList.$el.find('tbody tr:first');
  180. $action = $tr.find('.action-share');
  181. expect($action.find('>span').text().trim()).toEqual('Shared by User One');
  182. expect($action.find('.icon').hasClass('icon-shared')).toEqual(false);
  183. expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
  184. expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
  185. });
  186. it('shows recipients when recipients are available', function() {
  187. var $action, $tr;
  188. fileList.setFiles([{
  189. id: 1,
  190. type: 'dir',
  191. name: 'One.txt',
  192. path: '/subdir',
  193. mimetype: 'text/plain',
  194. size: 12,
  195. permissions: OC.PERMISSION_ALL,
  196. recipientsDisplayName: 'User One, User Two',
  197. recipientData: {
  198. 0: {
  199. shareWith: 'User One',
  200. shareWithDisplayName: 'User One'
  201. },
  202. 1: {
  203. shareWith: 'User Two',
  204. shareWithDisplayName: 'User Two'
  205. }
  206. },
  207. etag: 'abc',
  208. shareTypes: [OC.Share.SHARE_TYPE_USER]
  209. }]);
  210. $tr = fileList.$el.find('tbody tr:first');
  211. $action = $tr.find('.action-share');
  212. expect($action.text().trim()).toEqual('Shared with User One Shared with User Two');
  213. expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
  214. expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
  215. expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
  216. });
  217. it('shows share action when shared with user who has no share permission', function() {
  218. var $action, $tr;
  219. fileList.setFiles([{
  220. id: 1,
  221. type: 'dir',
  222. name: 'One',
  223. path: '/subdir',
  224. mimetype: 'text/plain',
  225. size: 12,
  226. permissions: OC.PERMISSION_CREATE,
  227. etag: 'abc',
  228. shareOwner: 'User One'
  229. }]);
  230. $tr = fileList.$el.find('tbody tr:first');
  231. expect($tr.find('.action-share').length).toEqual(1);
  232. });
  233. it('do not show share action when share exists but neither permission nor owner is available', function() {
  234. var $action, $tr;
  235. fileList.setFiles([{
  236. id: 1,
  237. type: 'dir',
  238. name: 'One',
  239. path: '/subdir',
  240. mimetype: 'text/plain',
  241. size: 12,
  242. permissions: OC.PERMISSION_CREATE,
  243. etag: 'abc'
  244. }]);
  245. $tr = fileList.$el.find('tbody tr:first');
  246. expect($tr.find('.action-share').length).toEqual(0);
  247. });
  248. });
  249. describe('Excluded lists', function() {
  250. function createListThenAttach(listId) {
  251. var fileActions = new OCA.Files.FileActions();
  252. fileList.destroy();
  253. fileList = new OCA.Files.FileList(
  254. $('#listContainer'), {
  255. id: listId,
  256. fileActions: fileActions
  257. }
  258. );
  259. OCA.Sharing.Util.attach(fileList);
  260. fileList.setFiles(testFiles);
  261. return fileList;
  262. }
  263. it('does not attach to trashbin or public file lists', function() {
  264. createListThenAttach('trashbin');
  265. expect($('.action-share').length).toEqual(0);
  266. expect($('[data-share-recipient]').length).toEqual(0);
  267. createListThenAttach('files.public');
  268. expect($('.action-share').length).toEqual(0);
  269. expect($('[data-share-recipient]').length).toEqual(0);
  270. });
  271. });
  272. describe('ShareTabView interaction', function() {
  273. var shareTabSpy;
  274. var fileInfoModel;
  275. var configModel;
  276. var shareModel;
  277. beforeEach(function() {
  278. shareTabSpy = sinon.spy(OCA.Sharing, 'ShareTabView');
  279. var attributes = {
  280. itemType: 'file',
  281. itemSource: 123,
  282. possiblePermissions: 31,
  283. permissions: 31
  284. };
  285. fileInfoModel = new OCA.Files.FileInfoModel(testFiles[0]);
  286. configModel = new OC.Share.ShareConfigModel({
  287. enforcePasswordForPublicLink: false,
  288. isResharingAllowed: true,
  289. isDefaultExpireDateEnabled: false,
  290. isDefaultExpireDateEnforced: false,
  291. defaultExpireDate: 7
  292. });
  293. shareModel = new OC.Share.ShareItemModel(attributes, {
  294. configModel: configModel,
  295. fileInfoModel: fileInfoModel
  296. });
  297. /* jshint camelcase: false */
  298. shareModel.set({
  299. reshare: {},
  300. shares: [{
  301. id: 100,
  302. item_source: 1,
  303. permissions: 31,
  304. share_type: OC.Share.SHARE_TYPE_USER,
  305. share_with: 'user1',
  306. share_with_displayname: 'User One'
  307. }, {
  308. id: 102,
  309. item_source: 1,
  310. permissions: 31,
  311. share_type: OC.Share.SHARE_TYPE_REMOTE,
  312. share_with: 'foo@bar.com/baz',
  313. share_with_displayname: 'foo@bar.com/baz'
  314. }]
  315. }, {parse: true});
  316. fileList.destroy();
  317. fileList = new OCA.Files.FileList(
  318. $('#listContainer'), {
  319. id: 'files',
  320. fileActions: new OCA.Files.FileActions()
  321. }
  322. );
  323. OCA.Sharing.Util.attach(fileList);
  324. fileList.setFiles(testFiles);
  325. });
  326. afterEach(function() {
  327. shareTabSpy.restore();
  328. });
  329. });
  330. });