1
0

publicAppSpec.js 5.8 KB

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