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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* Copyright (c) 2016
*
* This file is licensed under the Affero General Public License comment 3
* or later.
*
* See the COPYING-README file.
*
*/
describe('OCA.Comments.CommentCollection', function() {
var CommentCollection = OCA.Comments.CommentCollection;
var collection, syncStub;
var comment1, comment2, comment3;
beforeEach(function() {
syncStub = sinon.stub(CommentCollection.prototype, 'sync');
collection = new CommentCollection();
collection.setObjectId(5);
comment1 = {
id: 1,
actorType: 'users',
actorId: 'user1',
actorDisplayName: 'User One',
objectType: 'files',
objectId: 5,
message: 'First',
creationDateTime: Date.UTC(2016, 1, 3, 10, 5, 0)
};
comment2 = {
id: 2,
actorType: 'users',
actorId: 'user2',
actorDisplayName: 'User Two',
objectType: 'files',
objectId: 5,
message: 'Second\nNewline',
creationDateTime: Date.UTC(2016, 1, 3, 10, 0, 0)
};
comment3 = {
id: 3,
actorType: 'users',
actorId: 'user3',
actorDisplayName: 'User Three',
objectType: 'files',
objectId: 5,
message: 'Third',
creationDateTime: Date.UTC(2016, 1, 3, 5, 0, 0)
};
});
afterEach(function() {
syncStub.restore();
});
it('fetches the next page', function() {
collection._limit = 2;
collection.fetchNext();
expect(syncStub.calledOnce).toEqual(true);
expect(syncStub.lastCall.args[0]).toEqual('REPORT');
var options = syncStub.lastCall.args[2];
expect(options.remove).toEqual(false);
var parser = new DOMParser();
var doc = parser.parseFromString(options.data, "application/xml");
expect(doc.getElementsByTagNameNS('http://owncloud.org/ns', 'limit')[0].textContent).toEqual('3');
expect(doc.getElementsByTagNameNS('http://owncloud.org/ns', 'offset')[0].textContent).toEqual('0');
syncStub.yieldTo('success', [comment1, comment2, comment3]);
expect(collection.length).toEqual(2);
expect(collection.hasMoreResults()).toEqual(true);
collection.fetchNext();
expect(syncStub.calledTwice).toEqual(true);
options = syncStub.lastCall.args[2];
doc = parser.parseFromString(options.data, "application/xml");
expect(doc.getElementsByTagNameNS('http://owncloud.org/ns', 'limit')[0].textContent).toEqual('3');
expect(doc.getElementsByTagNameNS('http://owncloud.org/ns', 'offset')[0].textContent).toEqual('2');
syncStub.yieldTo('success', [comment3]);
expect(collection.length).toEqual(3);
expect(collection.hasMoreResults()).toEqual(false);
collection.fetchNext();
// no further requests
expect(syncStub.calledTwice).toEqual(true);
});
it('resets page counted when calling reset', function() {
collection.fetchNext();
syncStub.yieldTo('success', [comment1]);
expect(collection.hasMoreResults()).toEqual(false);
collection.reset();
expect(collection.hasMoreResults()).toEqual(true);
});
describe('resetting read marker', function() {
var updateStub;
var clock;
beforeEach(function() {
updateStub = sinon.stub(OCA.Comments.CommentSummaryModel.prototype, 'save');
clock = sinon.useFakeTimers(Date.UTC(2016, 1, 3, 10, 5, 9));
});
afterEach(function() {
updateStub.restore();
clock.restore();
});
it('resets read marker to the default date', function() {
var successStub = sinon.stub();
collection.updateReadMarker(null, {
success: successStub
});
expect(updateStub.calledOnce).toEqual(true);
expect(updateStub.lastCall.args[0]).toEqual({
readMarker: new Date(Date.UTC(2016, 1, 3, 10, 5, 9)).toUTCString()
});
updateStub.yieldTo('success');
expect(successStub.calledOnce).toEqual(true);
});
it('resets read marker to the given date', function() {
var successStub = sinon.stub();
collection.updateReadMarker(new Date(Date.UTC(2016, 1, 2, 3, 4, 5)), {
success: successStub
});
expect(updateStub.calledOnce).toEqual(true);
expect(updateStub.lastCall.args[0]).toEqual({
readMarker: new Date(Date.UTC(2016, 1, 2, 3, 4, 5)).toUTCString()
});
updateStub.yieldTo('success');
expect(successStub.calledOnce).toEqual(true);
});
});
});
|