mountsfilelistSpec.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Vincent Petry <vincent@nextcloud.com>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. describe('OCA.Files_External.FileList tests', function() {
  25. var testFiles, alertStub, notificationStub, fileList;
  26. beforeEach(function() {
  27. alertStub = sinon.stub(OC.dialogs, 'alert');
  28. notificationStub = sinon.stub(OC.Notification, 'show');
  29. // init parameters and test table elements
  30. $('#testArea').append(
  31. '<div id="app-content">' +
  32. // init horrible parameters
  33. '<input type="hidden" id="permissions" value="31"></input>' +
  34. // dummy controls
  35. '<div class="files-controls">' +
  36. ' <div class="actions creatable"></div>' +
  37. ' <div class="notCreatable"></div>' +
  38. '</div>' +
  39. // dummy table
  40. // TODO: at some point this will be rendered by the fileList class itself!
  41. '<table class="files-filestable">' +
  42. '<thead><tr>' +
  43. '<th class="hidden column-name">' +
  44. ' <div id="column-name-container">' +
  45. ' <a class="name sort columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
  46. ' </div>' +
  47. '</th>' +
  48. '<th id="headerBackend" class="hidden column-backend">' +
  49. ' <a class="backend sort columntitle" data-sort="backend"><span>Storage type</span><span class="sort-indicator"></span></a>' +
  50. '</th>' +
  51. '<th id="headerScope" class="hidden column-scope column-last">' +
  52. ' <a class="scope sort columntitle" data-sort="scope"><span>Scope</span><span class="sort-indicator"></span></a>' +
  53. '</th>' +
  54. '</tr></thead>' +
  55. '<tbody class="files-fileList"></tbody>' +
  56. '<tfoot></tfoot>' +
  57. '</table>' +
  58. '<div class="emptyfilelist emptycontent">Empty content message</div>' +
  59. '</div>'
  60. );
  61. });
  62. afterEach(function() {
  63. testFiles = undefined;
  64. fileList.destroy();
  65. fileList = undefined;
  66. notificationStub.restore();
  67. alertStub.restore();
  68. });
  69. describe('loading file list for external storage', function() {
  70. var ocsResponse;
  71. var reloading;
  72. beforeEach(function() {
  73. fileList = new OCA.Files_External.FileList(
  74. $('#app-content')
  75. );
  76. reloading = fileList.reload();
  77. /* jshint camelcase: false */
  78. ocsResponse = {
  79. ocs: {
  80. meta: {
  81. status: 'ok',
  82. statuscode: 100,
  83. message: null
  84. },
  85. data: [{
  86. name: 'smb mount',
  87. path: '/mount points',
  88. type: 'dir',
  89. backend: 'SMB',
  90. scope: 'personal',
  91. permissions: OC.PERMISSION_READ | OC.PERMISSION_DELETE
  92. }, {
  93. name: 'sftp mount',
  94. path: '/another mount points',
  95. type: 'dir',
  96. backend: 'SFTP',
  97. scope: 'system',
  98. permissions: OC.PERMISSION_READ
  99. }]
  100. }
  101. };
  102. });
  103. it('render storage list', function(done) {
  104. var request;
  105. var $rows;
  106. var $tr;
  107. expect(fakeServer.requests.length).toEqual(1);
  108. request = fakeServer.requests[0];
  109. expect(request.url).toEqual(
  110. OC.linkToOCS('apps/files_external/api/v1') + 'mounts?format=json'
  111. );
  112. fakeServer.requests[0].respond(
  113. 200,
  114. { 'Content-Type': 'application/json' },
  115. JSON.stringify(ocsResponse)
  116. );
  117. return reloading.then(function() {
  118. $rows = fileList.$el.find('tbody tr');
  119. expect($rows.length).toEqual(2);
  120. $tr = $rows.eq(0);
  121. expect($tr.attr('data-id')).not.toBeDefined();
  122. expect($tr.attr('data-type')).toEqual('dir');
  123. expect($tr.attr('data-file')).toEqual('sftp mount');
  124. expect($tr.attr('data-path')).toEqual('/another mount points');
  125. expect($tr.attr('data-size')).not.toBeDefined();
  126. expect($tr.attr('data-permissions')).toEqual('1'); // read only
  127. expect($tr.find('a.name').attr('href')).toEqual(
  128. OC.getRootPath() +
  129. '/index.php/apps/files' +
  130. '?dir=/another%20mount%20points/sftp%20mount'
  131. );
  132. expect($tr.find('.nametext').text().trim()).toEqual('sftp mount');
  133. expect($tr.find('.column-scope > span').text().trim()).toEqual('System');
  134. expect($tr.find('.column-backend').text().trim()).toEqual('SFTP');
  135. $tr = $rows.eq(1);
  136. expect($tr.attr('data-id')).not.toBeDefined();
  137. expect($tr.attr('data-type')).toEqual('dir');
  138. expect($tr.attr('data-file')).toEqual('smb mount');
  139. expect($tr.attr('data-path')).toEqual('/mount points');
  140. expect($tr.attr('data-size')).not.toBeDefined();
  141. expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
  142. expect($tr.find('a.name').attr('href')).toEqual(
  143. OC.getRootPath() +
  144. '/index.php/apps/files' +
  145. '?dir=/mount%20points/smb%20mount'
  146. );
  147. expect($tr.find('.nametext').text().trim()).toEqual('smb mount');
  148. expect($tr.find('.column-scope > span').text().trim()).toEqual('Personal');
  149. expect($tr.find('.column-backend').text().trim()).toEqual('SMB');
  150. }).then(done, done);
  151. });
  152. });
  153. });