1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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();
});
});
});
|