1
0

appSpec.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Vincent Petry <vincent@nextcloud.com>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. describe('OCA.Sharing.App tests', function() {
  25. var App = OCA.Sharing.App;
  26. var fileListIn;
  27. var fileListOut;
  28. beforeEach(function() {
  29. $('#testArea').append(
  30. '<div id="app-navigation">' +
  31. '<ul><li data-id="files"><a>Files</a></li>' +
  32. '<li data-id="sharingin"><a></a></li>' +
  33. '<li data-id="sharingout"><a></a></li>' +
  34. '</ul></div>' +
  35. '<div id="app-content">' +
  36. '<div id="app-content-files" class="hidden">' +
  37. '</div>' +
  38. '<div id="app-content-sharingin" class="hidden">' +
  39. '</div>' +
  40. '<div id="app-content-sharingout" class="hidden">' +
  41. '</div>' +
  42. '</div>' +
  43. '</div>'
  44. );
  45. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  46. fileListOut = App.initSharingOut($('#app-content-sharingout'));
  47. });
  48. afterEach(function() {
  49. App.destroy();
  50. });
  51. describe('initialization', function() {
  52. it('inits sharing-in list on show', function() {
  53. expect(fileListIn._sharedWithUser).toEqual(true);
  54. });
  55. it('inits sharing-out list on show', function() {
  56. expect(fileListOut._sharedWithUser).toBeFalsy();
  57. });
  58. });
  59. describe('file actions', function() {
  60. it('provides default file actions', function() {
  61. _.each([fileListIn, fileListOut], function(fileList) {
  62. var fileActions = fileList.fileActions;
  63. expect(fileActions.actions.all).toBeDefined();
  64. expect(fileActions.actions.all.Delete).toBeDefined();
  65. expect(fileActions.actions.all.Rename).toBeDefined();
  66. expect(fileActions.actions.all.Download).toBeDefined();
  67. expect(fileActions.defaults.dir).toEqual('Open');
  68. });
  69. });
  70. it('provides custom file actions', function() {
  71. var actionStub = sinon.stub();
  72. // regular file action
  73. OCA.Files.fileActions.register(
  74. 'all',
  75. 'RegularTest',
  76. OC.PERMISSION_READ,
  77. OC.imagePath('core', 'actions/shared'),
  78. actionStub
  79. );
  80. App._inFileList = null;
  81. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  82. expect(fileListIn.fileActions.actions.all.RegularTest).toBeDefined();
  83. });
  84. it('redirects to files app when opening a directory', function() {
  85. var oldList = OCA.Files.App.fileList;
  86. // dummy new list to make sure it exists
  87. OCA.Files.App.fileList = new OCA.Files.FileList($('<table><thead></thead><tbody></tbody></table>'));
  88. var setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView');
  89. // create dummy table so we can click the dom
  90. var $table = '<table><thead></thead><tbody class="files-fileList"></tbody></table>';
  91. $('#app-content-sharingin').append($table);
  92. App._inFileList = null;
  93. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  94. fileListIn.setFiles([{
  95. name: 'testdir',
  96. type: 'dir',
  97. path: '/somewhere/inside/subdir',
  98. counterParts: ['user2'],
  99. shareOwner: 'user2'
  100. }]);
  101. fileListIn.findFileEl('testdir').find('td .nametext').click();
  102. expect(OCA.Files.App.fileList.getCurrentDirectory()).toEqual('/somewhere/inside/subdir/testdir');
  103. expect(setActiveViewStub.calledOnce).toEqual(true);
  104. expect(setActiveViewStub.calledWith('files')).toEqual(true);
  105. setActiveViewStub.restore();
  106. // restore old list
  107. OCA.Files.App.fileList = oldList;
  108. });
  109. });
  110. });