favoritespluginspec.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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="app-navigation">' +
  16. '<ul><li data-id="files"><a>Files</a></li>' +
  17. '<li data-id="sharingin"><a></a></li>' +
  18. '<li data-id="sharingout"><a></a></li>' +
  19. '</ul></div>' +
  20. '<div id="app-content">' +
  21. '<div id="app-content-files" class="hidden">' +
  22. '</div>' +
  23. '<div id="app-content-favorites" class="hidden">' +
  24. '</div>' +
  25. '</div>' +
  26. '</div>'
  27. );
  28. OC.Plugins.attach('OCA.Files.App', Plugin);
  29. fileList = Plugin.showFileList($('#app-content-favorites'));
  30. });
  31. afterEach(function() {
  32. OC.Plugins.detach('OCA.Files.App', Plugin);
  33. });
  34. describe('initialization', function() {
  35. it('inits favorites list on show', function() {
  36. expect(fileList).toBeDefined();
  37. });
  38. });
  39. describe('file actions', function() {
  40. var oldLegacyFileActions;
  41. beforeEach(function() {
  42. oldLegacyFileActions = window.FileActions;
  43. window.FileActions = new OCA.Files.FileActions();
  44. });
  45. afterEach(function() {
  46. window.FileActions = oldLegacyFileActions;
  47. });
  48. it('provides default file actions', function() {
  49. var fileActions = fileList.fileActions;
  50. expect(fileActions.actions.all).toBeDefined();
  51. expect(fileActions.actions.all.Delete).toBeDefined();
  52. expect(fileActions.actions.all.Rename).toBeDefined();
  53. expect(fileActions.actions.all.Download).toBeDefined();
  54. expect(fileActions.defaults.dir).toEqual('Open');
  55. });
  56. it('provides custom file actions', function() {
  57. var actionStub = sinon.stub();
  58. // regular file action
  59. OCA.Files.fileActions.register(
  60. 'all',
  61. 'RegularTest',
  62. OC.PERMISSION_READ,
  63. OC.imagePath('core', 'actions/shared'),
  64. actionStub
  65. );
  66. Plugin.favoritesFileList = null;
  67. fileList = Plugin.showFileList($('#app-content-favorites'));
  68. expect(fileList.fileActions.actions.all.RegularTest).toBeDefined();
  69. });
  70. it('does not provide legacy file actions', function() {
  71. var actionStub = sinon.stub();
  72. // legacy file action
  73. window.FileActions.register(
  74. 'all',
  75. 'LegacyTest',
  76. OC.PERMISSION_READ,
  77. OC.imagePath('core', 'actions/shared'),
  78. actionStub
  79. );
  80. Plugin.favoritesFileList = null;
  81. fileList = Plugin.showFileList($('#app-content-favorites'));
  82. expect(fileList.fileActions.actions.all.LegacyTest).not.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 id="fileList"></tbody></table>';
  91. $('#app-content-favorites').append($table);
  92. Plugin.favoritesFileList = null;
  93. fileList = Plugin.showFileList($('#app-content-favorites'));
  94. fileList.setFiles([{
  95. name: 'testdir',
  96. type: 'dir',
  97. path: '/somewhere/inside/subdir',
  98. counterParts: ['user2'],
  99. shareOwner: 'user2'
  100. }]);
  101. fileList.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. });