publicAppSpec.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**
  2. * @copyright 2015 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Vincent Petry <vincent@nextcloud.com>
  8. *
  9. * @license AGPL-3.0-or-later
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. describe('OCA.Sharing.PublicApp tests', function() {
  26. var App = OCA.Sharing.PublicApp;
  27. var hostStub, protocolStub;
  28. var originalWebroot;
  29. var $preview;
  30. beforeEach(function() {
  31. originalWebroot = OC.webroot;
  32. OC.webroot = '/owncloud';
  33. protocolStub = sinon.stub(OC, 'getProtocol').returns('https');
  34. hostStub = sinon.stub(OC, 'getHost').returns('example.com:9876');
  35. $preview = $('<div id="preview"></div>');
  36. $('#testArea').append($preview);
  37. $preview.append(
  38. '<div id="mimetype"></div>' +
  39. '<div id="mimetypeIcon"></div>' +
  40. '<input type="hidden" id="sharingToken" value="sh4tok"></input>'
  41. );
  42. });
  43. afterEach(function() {
  44. OC.webroot = originalWebroot;
  45. protocolStub.restore();
  46. hostStub.restore();
  47. });
  48. describe('File list', function() {
  49. var parseUrlQueryStub
  50. // TODO: this should be moved to a separate file once the PublicFileList is extracted from public.js
  51. beforeEach(function() {
  52. $preview.append(
  53. '<div id="app-content-files">' +
  54. // init horrible parameters
  55. '<input type="hidden" id="permissions" value="31"/>' +
  56. // dummy controls
  57. '<div class="files-controls">' +
  58. ' <div class="actions creatable"></div>' +
  59. ' <div class="notCreatable"></div>' +
  60. '</div>' +
  61. // uploader
  62. '<input type="file" id="file_upload_start" name="files[]" multiple="multiple">' +
  63. // dummy table
  64. // TODO: at some point this will be rendered by the fileList class itself!
  65. '<table class="files-filestable list-container view-grid">' +
  66. '<thead><tr>' +
  67. '<th class="hidden column-name">' +
  68. '<input type="checkbox" id="select_all_files" class="select-all">' +
  69. '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
  70. '<span class="selectedActions hidden">' +
  71. '<a href class="download">Download</a>' +
  72. '</span>' +
  73. '</th>' +
  74. '<th class="hidden column-size"><a class="columntitle" data-sort="size"><span class="sort-indicator"></span></a></th>' +
  75. '<th class="hidden column-mtime"><a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a></th>' +
  76. '</tr></thead>' +
  77. '<tbody class="files-fileList"></tbody>' +
  78. '<tfoot></tfoot>' +
  79. '</table>' +
  80. // TODO: move to handlebars template
  81. '<div class="emptyfilelist emptycontent"><h2>Empty content message</h2><p class="uploadmessage">Upload message</p></div>' +
  82. '<div class="nofilterresults hidden"></div>' +
  83. '</div>'
  84. );
  85. parseUrlQueryStub = sinon.stub(OC.Util.History, 'parseUrlQuery');
  86. parseUrlQueryStub.returns({path: '/subdir'});
  87. App.initialize($('#preview'));
  88. });
  89. afterEach(function() {
  90. App._initialized = false;
  91. parseUrlQueryStub.restore();
  92. });
  93. it('Uses public webdav endpoint', function() {
  94. App._initialized = false;
  95. fakeServer.restore();
  96. window.fakeServer = sinon.fakeServer.create();
  97. // uploader function messes up with fakeServer
  98. var uploaderDetectStub = sinon.stub(OC.Uploader.prototype, '_supportAjaxUploadWithProgress');
  99. App.initialize($('#preview'));
  100. expect(fakeServer.requests.length).toEqual(1);
  101. expect(fakeServer.requests[0].method).toEqual('PROPFIND');
  102. expect(fakeServer.requests[0].url).toEqual('https://example.com:9876/owncloud/public.php/webdav/subdir');
  103. expect(fakeServer.requests[0].requestHeaders.Authorization).toEqual('Basic c2g0dG9rOm51bGw=');
  104. uploaderDetectStub.restore();
  105. });
  106. describe('Download Url', function() {
  107. var fileList;
  108. beforeEach(function() {
  109. fileList = App.fileList;
  110. });
  111. it('returns correct download URL for single files', function() {
  112. expect(fileList.getDownloadUrl('some file.txt'))
  113. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fsubdir&files=some%20file.txt');
  114. expect(fileList.getDownloadUrl('some file.txt', '/anotherpath/abc'))
  115. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fanotherpath%2Fabc&files=some%20file.txt');
  116. fileList.changeDirectory('/');
  117. expect(fileList.getDownloadUrl('some file.txt'))
  118. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2F&files=some%20file.txt');
  119. });
  120. it('returns correct download URL for multiple files', function() {
  121. expect(fileList.getDownloadUrl(['a b c.txt', 'd e f.txt']))
  122. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fsubdir&files=%5B%22a%20b%20c.txt%22%2C%22d%20e%20f.txt%22%5D');
  123. });
  124. it('returns the correct ajax URL', function() {
  125. expect(fileList.getAjaxUrl('test', {a:1, b:'x y'}))
  126. .toEqual(OC.getRootPath() + '/index.php/apps/files_sharing/ajax/test.php?a=1&b=x%20y&t=sh4tok');
  127. });
  128. it('returns correct download URL for downloading everything', function() {
  129. expect(fileList.getDownloadUrl())
  130. .toEqual(OC.getRootPath() + '/index.php/s/sh4tok/download?path=%2Fsubdir');
  131. });
  132. });
  133. describe('Upload Url', function() {
  134. var fileList;
  135. beforeEach(function() {
  136. fileList = App.fileList;
  137. });
  138. it('returns correct upload URL', function() {
  139. expect(fileList.getUploadUrl('some file.txt'))
  140. .toEqual('/owncloud/public.php/webdav/subdir/some%20file.txt');
  141. });
  142. it('returns correct upload URL with specified dir', function() {
  143. expect(fileList.getUploadUrl('some file.txt', 'sub'))
  144. .toEqual('/owncloud/public.php/webdav/sub/some%20file.txt');
  145. });
  146. });
  147. });
  148. });