aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/tests/js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-02-03 13:00:55 +0100
committerVincent Petry <pvince81@owncloud.com>2016-02-03 13:00:55 +0100
commit8bb1437e240ce47e04f7bcb7dc3a56ef6b5d892b (patch)
tree9b484c1f7102cebd96995c29efd11fbbad870e64 /apps/comments/tests/js
parent621f54da514af548bf900f7a1c64af046f53b86d (diff)
downloadnextcloud-server-8bb1437e240ce47e04f7bcb7dc3a56ef6b5d892b.tar.gz
nextcloud-server-8bb1437e240ce47e04f7bcb7dc3a56ef6b5d892b.zip
Add file row indicator for unread comments
Diffstat (limited to 'apps/comments/tests/js')
-rw-r--r--apps/comments/tests/js/filespluginSpec.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/apps/comments/tests/js/filespluginSpec.js b/apps/comments/tests/js/filespluginSpec.js
new file mode 100644
index 00000000000..78becc5af09
--- /dev/null
+++ b/apps/comments/tests/js/filespluginSpec.js
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+describe('OCA.Comments.FilesPlugin tests', function() {
+ var fileList;
+ var testFiles;
+
+ beforeEach(function() {
+ var $content = $('<div id="content"></div>');
+ $('#testArea').append($content);
+ // dummy file list
+ var $div = $(
+ '<div>' +
+ '<table id="filestable">' +
+ '<thead></thead>' +
+ '<tbody id="fileList"></tbody>' +
+ '</table>' +
+ '</div>');
+ $('#content').append($div);
+
+ fileList = new OCA.Files.FileList($div);
+ OCA.Comments.FilesPlugin.attach(fileList);
+
+ testFiles = [{
+ id: 1,
+ type: 'file',
+ name: 'One.txt',
+ path: '/subdir',
+ mimetype: 'text/plain',
+ size: 12,
+ permissions: OC.PERMISSION_ALL,
+ etag: 'abc',
+ shareOwner: 'User One',
+ isShareMountPoint: false,
+ commentsUnread: 3
+ }];
+ });
+ afterEach(function() {
+ fileList.destroy();
+ fileList = null;
+ });
+
+ describe('Comment icon', function() {
+ it('does not render icon when no unread comments available', function() {
+ testFiles[0].commentsUnread = 0;
+ fileList.setFiles(testFiles);
+ var $tr = fileList.findFileEl('One.txt');
+ expect($tr.find('.action-comment').length).toEqual(0);
+ });
+ it('renders comment icon and extra data', function() {
+ var $action, $tr;
+ fileList.setFiles(testFiles);
+ $tr = fileList.findFileEl('One.txt');
+ $action = $tr.find('.action-comment');
+ expect($action.length).toEqual(1);
+ expect($action.hasClass('permanent')).toEqual(true);
+
+ expect($tr.attr('data-comments-unread')).toEqual('3');
+ });
+ it('clicking icon opens sidebar', function() {
+ var sidebarStub = sinon.stub(fileList, 'showDetailsView');
+ var $action, $tr;
+ fileList.setFiles(testFiles);
+ $tr = fileList.findFileEl('One.txt');
+ $action = $tr.find('.action-comment');
+ $action.click();
+
+ expect(sidebarStub.calledOnce).toEqual(true);
+ expect(sidebarStub.lastCall.args[0]).toEqual('One.txt');
+ expect(sidebarStub.lastCall.args[1]).toEqual('commentsTabView');
+ });
+ });
+ describe('elementToFile', function() {
+ it('returns comment count', function() {
+ fileList.setFiles(testFiles);
+ var $tr = fileList.findFileEl('One.txt');
+ var data = fileList.elementToFile($tr);
+ expect(data.commentsUnread).toEqual(3);
+ });
+ it('does not set comment count when not set', function() {
+ delete testFiles[0].commentsUnread;
+ fileList.setFiles(testFiles);
+ var $tr = fileList.findFileEl('One.txt');
+ var data = fileList.elementToFile($tr);
+ expect(data.commentsUnread).not.toBeDefined();
+ });
+ it('does not set comment count when zero', function() {
+ testFiles[0].commentsUnread = 0;
+ fileList.setFiles(testFiles);
+ var $tr = fileList.findFileEl('One.txt');
+ var data = fileList.elementToFile($tr);
+ expect(data.commentsUnread).not.toBeDefined();
+ });
+ });
+});