filespluginSpec.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. * @author Vincent Petry <vincent@nextcloud.com>
  6. *
  7. * @license AGPL-3.0-or-later
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. describe('OCA.Comments.FilesPlugin tests', function() {
  24. var fileList;
  25. var testFiles;
  26. beforeEach(function() {
  27. var $content = $('<div id="app-content"></div>');
  28. $('#testArea').append($content);
  29. // dummy file list
  30. var $div = $(
  31. '<div>' +
  32. '<table class="files-filestable">' +
  33. '<thead></thead>' +
  34. '<tbody class="files-fileList"></tbody>' +
  35. '</table>' +
  36. '</div>');
  37. $('#app-content').append($div);
  38. fileList = new OCA.Files.FileList($div);
  39. OCA.Comments.FilesPlugin.attach(fileList);
  40. testFiles = [{
  41. id: 1,
  42. type: 'file',
  43. name: 'One.txt',
  44. path: '/subdir',
  45. mimetype: 'text/plain',
  46. size: 12,
  47. permissions: OC.PERMISSION_ALL,
  48. etag: 'abc',
  49. shareOwner: 'User One',
  50. isShareMountPoint: false,
  51. commentsUnread: 3
  52. }];
  53. });
  54. afterEach(function() {
  55. fileList.destroy();
  56. fileList = null;
  57. });
  58. describe('Comment icon', function() {
  59. it('does not render icon when no unread comments available', function() {
  60. testFiles[0].commentsUnread = 0;
  61. fileList.setFiles(testFiles);
  62. var $tr = fileList.findFileEl('One.txt');
  63. expect($tr.find('.action-comment').length).toEqual(0);
  64. });
  65. it('renders comment icon and extra data', function() {
  66. var $action, $tr;
  67. fileList.setFiles(testFiles);
  68. $tr = fileList.findFileEl('One.txt');
  69. $action = $tr.find('.action-comment');
  70. expect($action.length).toEqual(1);
  71. expect($action.hasClass('permanent')).toEqual(true);
  72. expect($tr.attr('data-comments-unread')).toEqual('3');
  73. });
  74. it('clicking icon opens sidebar', function() {
  75. var sidebarTabStub = sinon.stub(OCA.Files.Sidebar, 'setActiveTab');
  76. var sidebarStub = sinon.stub(OCA.Files.Sidebar, 'open');
  77. var $action, $tr;
  78. fileList.setFiles(testFiles);
  79. $tr = fileList.findFileEl('One.txt');
  80. $action = $tr.find('.action-comment');
  81. $action.click();
  82. expect(sidebarTabStub.calledOnce).toEqual(true);
  83. expect(sidebarTabStub.lastCall.args[0]).toEqual('comments');
  84. expect(sidebarStub.calledOnce).toEqual(true);
  85. expect(sidebarStub.lastCall.args[0]).toEqual('/subdir/One.txt');
  86. });
  87. });
  88. describe('elementToFile', function() {
  89. it('returns comment count', function() {
  90. fileList.setFiles(testFiles);
  91. var $tr = fileList.findFileEl('One.txt');
  92. var data = fileList.elementToFile($tr);
  93. expect(data.commentsUnread).toEqual(3);
  94. });
  95. it('does not set comment count when not set', function() {
  96. delete testFiles[0].commentsUnread;
  97. fileList.setFiles(testFiles);
  98. var $tr = fileList.findFileEl('One.txt');
  99. var data = fileList.elementToFile($tr);
  100. expect(data.commentsUnread).not.toBeDefined();
  101. });
  102. it('does not set comment count when zero', function() {
  103. testFiles[0].commentsUnread = 0;
  104. fileList.setFiles(testFiles);
  105. var $tr = fileList.findFileEl('One.txt');
  106. var data = fileList.elementToFile($tr);
  107. expect(data.commentsUnread).not.toBeDefined();
  108. });
  109. });
  110. });