1
0

publicAppSpec.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. describe('OCA.Sharing.PublicApp tests', function() {
  7. var App = OCA.Sharing.PublicApp;
  8. var hostStub, protocolStub;
  9. var originalWebroot;
  10. var $preview;
  11. beforeEach(function() {
  12. originalWebroot = window._oc_webroot;
  13. window._oc_webroot = '/owncloud';
  14. protocolStub = sinon.stub(OC, 'getProtocol').returns('https');
  15. hostStub = sinon.stub(OC, 'getHost').returns('example.com:9876');
  16. $preview = $('<div id="preview"></div>');
  17. $('#testArea').append($preview);
  18. $preview.append(
  19. '<div id="mimetype"></div>' +
  20. '<div id="mimetypeIcon"></div>' +
  21. '<input type="hidden" id="sharingToken" value="sh4tok"></input>'
  22. );
  23. });
  24. afterEach(function() {
  25. window._oc_webroot = originalWebroot;
  26. protocolStub.restore();
  27. hostStub.restore();
  28. });
  29. describe('File list', function() {
  30. var parseUrlQueryStub
  31. // TODO: this should be moved to a separate file once the PublicFileList is extracted from public.js
  32. beforeEach(function() {
  33. $preview.append(
  34. '<div id="app-content-files">' +
  35. // init horrible parameters
  36. '<input type="hidden" id="permissions" value="31"/>' +
  37. // dummy controls
  38. '<div class="files-controls">' +
  39. ' <div class="actions creatable"></div>' +
  40. ' <div class="notCreatable"></div>' +
  41. '</div>' +
  42. // uploader
  43. '<input type="file" id="file_upload_start" name="files[]" multiple="multiple">' +
  44. // dummy table
  45. // TODO: at some point this will be rendered by the fileList class itself!
  46. '<table class="files-filestable list-container view-grid">' +
  47. '<thead><tr>' +
  48. '<th class="hidden column-name">' +
  49. '<input type="checkbox" id="select_all_files" class="select-all">' +
  50. '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
  51. '<span class="selectedActions hidden">' +
  52. '<a href class="download">Download</a>' +
  53. '</span>' +
  54. '</th>' +
  55. '<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></th>' +
  56. '<th class="hidden column-mtime"><a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a></th>' +
  57. '</tr></thead>' +
  58. '<tbody class="files-fileList"></tbody>' +
  59. '<tfoot></tfoot>' +
  60. '</table>' +
  61. // TODO: move to handlebars template
  62. '<div class="emptyfilelist emptycontent"><h2>Empty content message</h2><p class="uploadmessage">Upload message</p></div>' +
  63. '<div class="nofilterresults hidden"></div>' +
  64. '</div>'
  65. );
  66. parseUrlQueryStub = sinon.stub(OC.Util.History, 'parseUrlQuery');
  67. parseUrlQueryStub.returns({path: '/subdir'});
  68. App.initialize($('#preview'));
  69. });
  70. afterEach(function() {
  71. App._initialized = false;
  72. parseUrlQueryStub.restore();
  73. });
  74. it('Uses public webdav endpoint', function() {
  75. App._initialized = false;
  76. fakeServer.restore();
  77. window.fakeServer = sinon.fakeServer.create();
  78. // uploader function messes up with fakeServer
  79. var uploaderDetectStub = sinon.stub(OC.Uploader.prototype, '_supportAjaxUploadWithProgress');
  80. App.initialize($('#preview'));
  81. expect(fakeServer.requests.length).toEqual(1);
  82. expect(fakeServer.requests[0].method).toEqual('PROPFIND');
  83. expect(fakeServer.requests[0].url).toEqual('https://example.com:9876/owncloud/public.php/dav/files/sh4tok/subdir');
  84. uploaderDetectStub.restore();
  85. });
  86. describe('Download Url', function() {
  87. var fileList;
  88. beforeEach(function() {
  89. fileList = App.fileList;
  90. });
  91. it('returns correct download URL for single files', function() {
  92. expect(fileList.getDownloadUrl('some file.txt'))
  93. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fsubdir&files=some%20file.txt');
  94. expect(fileList.getDownloadUrl('some file.txt', '/anotherpath/abc'))
  95. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fanotherpath%2Fabc&files=some%20file.txt');
  96. fileList.changeDirectory('/');
  97. expect(fileList.getDownloadUrl('some file.txt'))
  98. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2F&files=some%20file.txt');
  99. });
  100. it('returns correct download URL for multiple files', function() {
  101. expect(fileList.getDownloadUrl(['a b c.txt', 'd e f.txt']))
  102. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D');
  103. });
  104. it('returns the correct ajax URL', function() {
  105. expect(fileList.getAjaxUrl('test', {a:1, b:'x y'}))
  106. .toEqual(OC.getRootPath() + '/index.php/apps/files_sharing/ajax/test.php?a=1&b=x%20y&t=sh4tok');
  107. });
  108. it('returns correct download URL for downloading everything', function() {
  109. expect(fileList.getDownloadUrl())
  110. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fsubdir');
  111. });
  112. });
  113. describe('Upload Url', function() {
  114. var fileList;
  115. beforeEach(function() {
  116. fileList = App.fileList;
  117. });
  118. it('returns correct upload URL', function() {
  119. expect(fileList.getUploadUrl('some file.txt'))
  120. .toEqual('/owncloud/public.php/dav/files/sh4tok/subdir/some%20file.txt');
  121. });
  122. it('returns correct upload URL with specified dir', function() {
  123. expect(fileList.getUploadUrl('some file.txt', 'sub'))
  124. .toEqual('/owncloud/public.php/dav/files/sh4tok/sub/some%20file.txt');
  125. });
  126. });
  127. });
  128. });