favoritespluginspec.js 3.7 KB

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