shareSpec.js 9.3 KB

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