1
0

mountsfilelistSpec.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2014-2016 ownCloud, Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. describe('OCA.Files_External.FileList tests', function() {
  7. var testFiles, alertStub, notificationStub, fileList;
  8. beforeEach(function() {
  9. alertStub = sinon.stub(OC.dialogs, 'alert');
  10. notificationStub = sinon.stub(OC.Notification, 'show');
  11. // init parameters and test table elements
  12. $('#testArea').append(
  13. '<div id="app-content">' +
  14. // init horrible parameters
  15. '<input type="hidden" id="permissions" value="31"></input>' +
  16. // dummy controls
  17. '<div class="files-controls">' +
  18. ' <div class="actions creatable"></div>' +
  19. ' <div class="notCreatable"></div>' +
  20. '</div>' +
  21. // dummy table
  22. // TODO: at some point this will be rendered by the fileList class itself!
  23. '<table class="files-filestable">' +
  24. '<thead><tr>' +
  25. '<th class="hidden column-name">' +
  26. ' <div id="column-name-container">' +
  27. ' <a class="name sort columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
  28. ' </div>' +
  29. '</th>' +
  30. '<th id="headerBackend" class="hidden column-backend">' +
  31. ' <a class="backend sort columntitle" data-sort="backend"><span>Storage type</span><span class="sort-indicator"></span></a>' +
  32. '</th>' +
  33. '<th id="headerScope" class="hidden column-scope column-last">' +
  34. ' <a class="scope sort columntitle" data-sort="scope"><span>Scope</span><span class="sort-indicator"></span></a>' +
  35. '</th>' +
  36. '</tr></thead>' +
  37. '<tbody class="files-fileList"></tbody>' +
  38. '<tfoot></tfoot>' +
  39. '</table>' +
  40. '<div class="emptyfilelist emptycontent">Empty content message</div>' +
  41. '</div>'
  42. );
  43. });
  44. afterEach(function() {
  45. testFiles = undefined;
  46. fileList.destroy();
  47. fileList = undefined;
  48. notificationStub.restore();
  49. alertStub.restore();
  50. });
  51. describe('loading file list for external storage', function() {
  52. var ocsResponse;
  53. var reloading;
  54. beforeEach(function() {
  55. fileList = new OCA.Files_External.FileList(
  56. $('#app-content')
  57. );
  58. reloading = fileList.reload();
  59. /* jshint camelcase: false */
  60. ocsResponse = {
  61. ocs: {
  62. meta: {
  63. status: 'ok',
  64. statuscode: 100,
  65. message: null
  66. },
  67. data: [{
  68. name: 'smb mount',
  69. path: '/mount points',
  70. type: 'dir',
  71. backend: 'SMB',
  72. scope: 'personal',
  73. permissions: OC.PERMISSION_READ | OC.PERMISSION_DELETE
  74. }, {
  75. name: 'sftp mount',
  76. path: '/another mount points',
  77. type: 'dir',
  78. backend: 'SFTP',
  79. scope: 'system',
  80. permissions: OC.PERMISSION_READ
  81. }]
  82. }
  83. };
  84. });
  85. it('render storage list', function(done) {
  86. var request;
  87. var $rows;
  88. var $tr;
  89. expect(fakeServer.requests.length).toEqual(1);
  90. request = fakeServer.requests[0];
  91. expect(request.url).toEqual(
  92. OC.linkToOCS('apps/files_external/api/v1') + 'mounts?format=json'
  93. );
  94. fakeServer.requests[0].respond(
  95. 200,
  96. { 'Content-Type': 'application/json' },
  97. JSON.stringify(ocsResponse)
  98. );
  99. return reloading.then(function() {
  100. $rows = fileList.$el.find('tbody tr');
  101. expect($rows.length).toEqual(2);
  102. $tr = $rows.eq(0);
  103. expect($tr.attr('data-id')).not.toBeDefined();
  104. expect($tr.attr('data-type')).toEqual('dir');
  105. expect($tr.attr('data-file')).toEqual('sftp mount');
  106. expect($tr.attr('data-path')).toEqual('/another mount points');
  107. expect($tr.attr('data-size')).not.toBeDefined();
  108. expect($tr.attr('data-permissions')).toEqual('1'); // read only
  109. expect($tr.find('a.name').attr('href')).toEqual(
  110. OC.getRootPath() +
  111. '/index.php/apps/files' +
  112. '?dir=/another%20mount%20points/sftp%20mount'
  113. );
  114. expect($tr.find('.nametext').text().trim()).toEqual('sftp mount');
  115. expect($tr.find('.column-scope > span').text().trim()).toEqual('System');
  116. expect($tr.find('.column-backend').text().trim()).toEqual('SFTP');
  117. $tr = $rows.eq(1);
  118. expect($tr.attr('data-id')).not.toBeDefined();
  119. expect($tr.attr('data-type')).toEqual('dir');
  120. expect($tr.attr('data-file')).toEqual('smb mount');
  121. expect($tr.attr('data-path')).toEqual('/mount points');
  122. expect($tr.attr('data-size')).not.toBeDefined();
  123. expect($tr.attr('data-permissions')).toEqual('9'); // read and delete
  124. expect($tr.find('a.name').attr('href')).toEqual(
  125. OC.getRootPath() +
  126. '/index.php/apps/files' +
  127. '?dir=/mount%20points/smb%20mount'
  128. );
  129. expect($tr.find('.nametext').text().trim()).toEqual('smb mount');
  130. expect($tr.find('.column-scope > span').text().trim()).toEqual('Personal');
  131. expect($tr.find('.column-backend').text().trim()).toEqual('SMB');
  132. }).then(done, done);
  133. });
  134. });
  135. });