publicAppSpec.js 5.8 KB

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