appSpec.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. it('provides default file actions', function() {
  58. _.each([fileListIn, fileListOut], function(fileList) {
  59. var fileActions = fileList.fileActions;
  60. expect(fileActions.actions.all).toBeDefined();
  61. expect(fileActions.actions.all.Delete).toBeDefined();
  62. expect(fileActions.actions.all.Rename).toBeDefined();
  63. expect(fileActions.actions.all.Download).toBeDefined();
  64. expect(fileActions.defaults.dir).toEqual('Open');
  65. });
  66. });
  67. it('provides custom file actions', function() {
  68. var actionStub = sinon.stub();
  69. // regular file action
  70. OCA.Files.fileActions.register(
  71. 'all',
  72. 'RegularTest',
  73. OC.PERMISSION_READ,
  74. OC.imagePath('core', 'actions/shared'),
  75. actionStub
  76. );
  77. App._inFileList = null;
  78. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  79. expect(fileListIn.fileActions.actions.all.RegularTest).toBeDefined();
  80. });
  81. it('redirects to files app when opening a directory', function() {
  82. var oldList = OCA.Files.App.fileList;
  83. // dummy new list to make sure it exists
  84. OCA.Files.App.fileList = new OCA.Files.FileList($('<table><thead></thead><tbody></tbody></table>'));
  85. var setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView');
  86. // create dummy table so we can click the dom
  87. var $table = '<table><thead></thead><tbody id="fileList"></tbody></table>';
  88. $('#app-content-sharingin').append($table);
  89. App._inFileList = null;
  90. fileListIn = App.initSharingIn($('#app-content-sharingin'));
  91. fileListIn.setFiles([{
  92. name: 'testdir',
  93. type: 'dir',
  94. path: '/somewhere/inside/subdir',
  95. counterParts: ['user2'],
  96. shareOwner: 'user2'
  97. }]);
  98. fileListIn.findFileEl('testdir').find('td .nametext').click();
  99. expect(OCA.Files.App.fileList.getCurrentDirectory()).toEqual('/somewhere/inside/subdir/testdir');
  100. expect(setActiveViewStub.calledOnce).toEqual(true);
  101. expect(setActiveViewStub.calledWith('files')).toEqual(true);
  102. setActiveViewStub.restore();
  103. // restore old list
  104. OCA.Files.App.fileList = oldList;
  105. });
  106. });
  107. });