favoritespluginspec.js 3.8 KB

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