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.

filespluginSpec.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2016 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.Comments.FilesPlugin tests', function() {
  11. var fileList;
  12. var testFiles;
  13. beforeEach(function() {
  14. var $content = $('<div id="content"></div>');
  15. $('#testArea').append($content);
  16. // dummy file list
  17. var $div = $(
  18. '<div>' +
  19. '<table id="filestable">' +
  20. '<thead></thead>' +
  21. '<tbody id="fileList"></tbody>' +
  22. '</table>' +
  23. '</div>');
  24. $('#content').append($div);
  25. fileList = new OCA.Files.FileList($div);
  26. OCA.Comments.FilesPlugin.attach(fileList);
  27. testFiles = [{
  28. id: 1,
  29. type: 'file',
  30. name: 'One.txt',
  31. path: '/subdir',
  32. mimetype: 'text/plain',
  33. size: 12,
  34. permissions: OC.PERMISSION_ALL,
  35. etag: 'abc',
  36. shareOwner: 'User One',
  37. isShareMountPoint: false,
  38. commentsUnread: 3
  39. }];
  40. });
  41. afterEach(function() {
  42. fileList.destroy();
  43. fileList = null;
  44. });
  45. describe('Comment icon', function() {
  46. it('does not render icon when no unread comments available', function() {
  47. testFiles[0].commentsUnread = 0;
  48. fileList.setFiles(testFiles);
  49. var $tr = fileList.findFileEl('One.txt');
  50. expect($tr.find('.action-comment').length).toEqual(0);
  51. });
  52. it('renders comment icon and extra data', function() {
  53. var $action, $tr;
  54. fileList.setFiles(testFiles);
  55. $tr = fileList.findFileEl('One.txt');
  56. $action = $tr.find('.action-comment');
  57. expect($action.length).toEqual(1);
  58. expect($action.hasClass('permanent')).toEqual(true);
  59. expect($tr.attr('data-comments-unread')).toEqual('3');
  60. });
  61. it('clicking icon opens sidebar', function() {
  62. var sidebarTabStub = sinon.stub(OCA.Files.Sidebar, 'setActiveTab');
  63. var sidebarStub = sinon.stub(OCA.Files.Sidebar, 'open');
  64. var $action, $tr;
  65. fileList.setFiles(testFiles);
  66. $tr = fileList.findFileEl('One.txt');
  67. $action = $tr.find('.action-comment');
  68. $action.click();
  69. expect(sidebarTabStub.calledOnce).toEqual(true);
  70. expect(sidebarTabStub.lastCall.args[0]).toEqual('comments');
  71. expect(sidebarStub.calledOnce).toEqual(true);
  72. expect(sidebarStub.lastCall.args[0]).toEqual('/One.txt');
  73. });
  74. });
  75. describe('elementToFile', function() {
  76. it('returns comment count', function() {
  77. fileList.setFiles(testFiles);
  78. var $tr = fileList.findFileEl('One.txt');
  79. var data = fileList.elementToFile($tr);
  80. expect(data.commentsUnread).toEqual(3);
  81. });
  82. it('does not set comment count when not set', function() {
  83. delete testFiles[0].commentsUnread;
  84. fileList.setFiles(testFiles);
  85. var $tr = fileList.findFileEl('One.txt');
  86. var data = fileList.elementToFile($tr);
  87. expect(data.commentsUnread).not.toBeDefined();
  88. });
  89. it('does not set comment count when zero', function() {
  90. testFiles[0].commentsUnread = 0;
  91. fileList.setFiles(testFiles);
  92. var $tr = fileList.findFileEl('One.txt');
  93. var data = fileList.elementToFile($tr);
  94. expect(data.commentsUnread).not.toBeDefined();
  95. });
  96. });
  97. });