filespluginSpec.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 sidebarStub = sinon.stub(fileList, 'showDetailsView');
  63. var $action, $tr;
  64. fileList.setFiles(testFiles);
  65. $tr = fileList.findFileEl('One.txt');
  66. $action = $tr.find('.action-comment');
  67. $action.click();
  68. expect(sidebarStub.calledOnce).toEqual(true);
  69. expect(sidebarStub.lastCall.args[0]).toEqual('One.txt');
  70. expect(sidebarStub.lastCall.args[1]).toEqual('commentsTabView');
  71. });
  72. });
  73. describe('elementToFile', function() {
  74. it('returns comment count', function() {
  75. fileList.setFiles(testFiles);
  76. var $tr = fileList.findFileEl('One.txt');
  77. var data = fileList.elementToFile($tr);
  78. expect(data.commentsUnread).toEqual(3);
  79. });
  80. it('does not set comment count when not set', function() {
  81. delete testFiles[0].commentsUnread;
  82. fileList.setFiles(testFiles);
  83. var $tr = fileList.findFileEl('One.txt');
  84. var data = fileList.elementToFile($tr);
  85. expect(data.commentsUnread).not.toBeDefined();
  86. });
  87. it('does not set comment count when zero', function() {
  88. testFiles[0].commentsUnread = 0;
  89. fileList.setFiles(testFiles);
  90. var $tr = fileList.findFileEl('One.txt');
  91. var data = fileList.elementToFile($tr);
  92. expect(data.commentsUnread).not.toBeDefined();
  93. });
  94. });
  95. });