favoritesfilelistspec.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.Files.FavoritesFileList tests', function() {
  11. var fileList;
  12. beforeEach(function() {
  13. // init parameters and test table elements
  14. $('#testArea').append(
  15. '<div id="app-content-container">' +
  16. // init horrible parameters
  17. '<input type="hidden" id="dir" value="/"></input>' +
  18. '<input type="hidden" id="permissions" value="31"></input>' +
  19. // dummy controls
  20. '<div id="controls">' +
  21. ' <div class="actions creatable"></div>' +
  22. ' <div class="notCreatable"></div>' +
  23. '</div>' +
  24. // dummy table
  25. // TODO: at some point this will be rendered by the fileList class itself!
  26. '<table id="filestable" class="list-container view-grid">' +
  27. '<thead><tr>' +
  28. '<th id="headerName" class="hidden column-name">' +
  29. '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
  30. '</th>' +
  31. '<th class="hidden column-mtime">' +
  32. '<a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a>' +
  33. '</th>' +
  34. '</tr></thead>' +
  35. '<tbody id="fileList"></tbody>' +
  36. '<tfoot></tfoot>' +
  37. '</table>' +
  38. '<div id="emptycontent">Empty content message</div>' +
  39. '</div>'
  40. );
  41. });
  42. describe('loading file list', function() {
  43. var fetchStub;
  44. beforeEach(function() {
  45. fileList = new OCA.Files.FavoritesFileList(
  46. $('#app-content-container')
  47. );
  48. OCA.Files.FavoritesPlugin.attach(fileList);
  49. fetchStub = sinon.stub(fileList.filesClient, 'getFilteredFiles');
  50. });
  51. afterEach(function() {
  52. fetchStub.restore();
  53. fileList.destroy();
  54. fileList = undefined;
  55. });
  56. it('render files', function() {
  57. var deferred = $.Deferred();
  58. fetchStub.returns(deferred.promise());
  59. fileList.reload();
  60. expect(fetchStub.calledOnce).toEqual(true);
  61. deferred.resolve(207, [{
  62. id: 7,
  63. name: 'test.txt',
  64. path: '/somedir',
  65. size: 123,
  66. mtime: 11111000,
  67. tags: [OC.TAG_FAVORITE],
  68. permissions: OC.PERMISSION_ALL,
  69. mimetype: 'text/plain'
  70. }]);
  71. var $rows = fileList.$el.find('tbody tr');
  72. var $tr = $rows.eq(0);
  73. expect($rows.length).toEqual(1);
  74. expect($tr.attr('data-id')).toEqual('7');
  75. expect($tr.attr('data-type')).toEqual('file');
  76. expect($tr.attr('data-file')).toEqual('test.txt');
  77. expect($tr.attr('data-path')).toEqual('/somedir');
  78. expect($tr.attr('data-size')).toEqual('123');
  79. expect(parseInt($tr.attr('data-permissions'), 10))
  80. .toEqual(OC.PERMISSION_ALL);
  81. expect($tr.attr('data-mime')).toEqual('text/plain');
  82. expect($tr.attr('data-mtime')).toEqual('11111000');
  83. expect($tr.find('a.name').attr('href')).toEqual(
  84. OC.getRootPath() +
  85. '/remote.php/webdav/somedir/test.txt'
  86. );
  87. expect($tr.find('.nametext').text().trim()).toEqual('test.txt');
  88. });
  89. });
  90. });