You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mountsfilelistSpec.js 4.6KB

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