favoritesfilelistspec.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  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.FavoritesFileList tests', function() {
  25. var fileList;
  26. beforeEach(function() {
  27. // init parameters and test table elements
  28. $('#testArea').append(
  29. '<div id="app-content">' +
  30. // init horrible parameters
  31. '<input type="hidden" id="permissions" value="31"></input>' +
  32. // dummy controls
  33. '<div class="files-controls">' +
  34. ' <div class="actions creatable"></div>' +
  35. ' <div class="notCreatable"></div>' +
  36. '</div>' +
  37. // dummy table
  38. // TODO: at some point this will be rendered by the fileList class itself!
  39. '<table class="files-filestable list-container view-grid">' +
  40. '<thead><tr>' +
  41. '<th class="hidden column-name">' +
  42. '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
  43. '</th>' +
  44. '<th class="hidden column-mtime">' +
  45. '<a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a>' +
  46. '</th>' +
  47. '</tr></thead>' +
  48. '<tbody class="files-fileList"></tbody>' +
  49. '<tfoot></tfoot>' +
  50. '</table>' +
  51. '<div class="emptyfilelist emptycontent">Empty content message</div>' +
  52. '</div>'
  53. );
  54. });
  55. describe('loading file list', function() {
  56. var fetchStub;
  57. beforeEach(function() {
  58. fileList = new OCA.Files.FavoritesFileList(
  59. $('#app-content')
  60. );
  61. OCA.Files.FavoritesPlugin.attach(fileList);
  62. fetchStub = sinon.stub(fileList.filesClient, 'getFilteredFiles');
  63. });
  64. afterEach(function() {
  65. fetchStub.restore();
  66. fileList.destroy();
  67. fileList = undefined;
  68. });
  69. it('render files', function(done) {
  70. var deferred = $.Deferred();
  71. fetchStub.returns(deferred.promise());
  72. fileList.reload();
  73. expect(fetchStub.calledOnce).toEqual(true);
  74. deferred.resolve(207, [{
  75. id: 7,
  76. name: 'test.txt',
  77. path: '/somedir',
  78. size: 123,
  79. mtime: 11111000,
  80. tags: [OC.TAG_FAVORITE],
  81. permissions: OC.PERMISSION_ALL,
  82. mimetype: 'text/plain'
  83. }]);
  84. setTimeout(function() {
  85. var $rows = fileList.$el.find('tbody tr');
  86. var $tr = $rows.eq(0);
  87. expect($rows.length).toEqual(1);
  88. expect($tr.attr('data-id')).toEqual('7');
  89. expect($tr.attr('data-type')).toEqual('file');
  90. expect($tr.attr('data-file')).toEqual('test.txt');
  91. expect($tr.attr('data-path')).toEqual('/somedir');
  92. expect($tr.attr('data-size')).toEqual('123');
  93. expect(parseInt($tr.attr('data-permissions'), 10))
  94. .toEqual(OC.PERMISSION_ALL);
  95. expect($tr.attr('data-mime')).toEqual('text/plain');
  96. expect($tr.attr('data-mtime')).toEqual('11111000');
  97. expect($tr.find('a.name').attr('href')).toEqual(
  98. OC.getRootPath() +
  99. '/remote.php/webdav/somedir/test.txt'
  100. );
  101. expect($tr.find('.nametext').text().trim()).toEqual('test.txt');
  102. done();
  103. }, 0);
  104. });
  105. });
  106. });