appSpec.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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('OCA.Sharing.App tests', function() {
  22. var App = OCA.Sharing.App;
  23. var fileListIn;
  24. var fileListOut;
  25. beforeEach(function() {
  26. $('#testArea').append(
  27. '<div id="app-navigation">' +
  28. '<ul><li data-id="files"><a>Files</a></li>' +
  29. '<li data-id="sharingin"><a></a></li>' +
  30. '<li data-id="sharingout"><a></a></li>' +
  31. '</ul></div>' +
  32. '<div id="app-content">' +
  33. '<div id="app-content-files" class="hidden">' +
  34. '</div>' +
  35. '<div id="app-content-sharingin" class="hidden">' +
  36. '</div>' +
  37. '<div id="app-content-sharingout" class="hidden">' +
  38. '</div>' +
  39. '</div>' +
  40. '</div>'
  41. );
  42. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  43. fileListOut = App.initSharingOut($('#app-content-sharingout'));
  44. });
  45. afterEach(function() {
  46. App.destroy();
  47. });
  48. describe('initialization', function() {
  49. it('inits sharing-in list on show', function() {
  50. expect(fileListIn._sharedWithUser).toEqual(true);
  51. });
  52. it('inits sharing-out list on show', function() {
  53. expect(fileListOut._sharedWithUser).toBeFalsy();
  54. });
  55. });
  56. describe('file actions', function() {
  57. var oldLegacyFileActions;
  58. beforeEach(function() {
  59. oldLegacyFileActions = window.FileActions;
  60. window.FileActions = new OCA.Files.FileActions();
  61. });
  62. afterEach(function() {
  63. window.FileActions = oldLegacyFileActions;
  64. });
  65. it('provides default file actions', function() {
  66. _.each([fileListIn, fileListOut], function(fileList) {
  67. var fileActions = fileList.fileActions;
  68. expect(fileActions.actions.all).toBeDefined();
  69. expect(fileActions.actions.all.Delete).toBeDefined();
  70. expect(fileActions.actions.all.Rename).toBeDefined();
  71. expect(fileActions.actions.all.Download).toBeDefined();
  72. expect(fileActions.defaults.dir).toEqual('Open');
  73. });
  74. });
  75. it('provides custom file actions', function() {
  76. var actionStub = sinon.stub();
  77. // regular file action
  78. OCA.Files.fileActions.register(
  79. 'all',
  80. 'RegularTest',
  81. OC.PERMISSION_READ,
  82. OC.imagePath('core', 'actions/shared'),
  83. actionStub
  84. );
  85. App._inFileList = null;
  86. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  87. expect(fileListIn.fileActions.actions.all.RegularTest).toBeDefined();
  88. });
  89. it('does not provide legacy file actions', function() {
  90. var actionStub = sinon.stub();
  91. // legacy file action
  92. window.FileActions.register(
  93. 'all',
  94. 'LegacyTest',
  95. OC.PERMISSION_READ,
  96. OC.imagePath('core', 'actions/shared'),
  97. actionStub
  98. );
  99. App._inFileList = null;
  100. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  101. expect(fileListIn.fileActions.actions.all.LegacyTest).not.toBeDefined();
  102. });
  103. it('redirects to files app when opening a directory', function() {
  104. var oldList = OCA.Files.App.fileList;
  105. // dummy new list to make sure it exists
  106. OCA.Files.App.fileList = new OCA.Files.FileList($('<table><thead></thead><tbody></tbody></table>'));
  107. var setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView');
  108. // create dummy table so we can click the dom
  109. var $table = '<table><thead></thead><tbody id="fileList"></tbody></table>';
  110. $('#app-content-sharingin').append($table);
  111. App._inFileList = null;
  112. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  113. fileListIn.setFiles([{
  114. name: 'testdir',
  115. type: 'dir',
  116. path: '/somewhere/inside/subdir',
  117. counterParts: ['user2'],
  118. shareOwner: 'user2'
  119. }]);
  120. fileListIn.findFileEl('testdir').find('td .nametext').click();
  121. expect(OCA.Files.App.fileList.getCurrentDirectory()).toEqual('/somewhere/inside/subdir/testdir');
  122. expect(setActiveViewStub.calledOnce).toEqual(true);
  123. expect(setActiveViewStub.calledWith('files')).toEqual(true);
  124. setActiveViewStub.restore();
  125. // restore old list
  126. OCA.Files.App.fileList = oldList;
  127. });
  128. });
  129. });