diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-02-03 16:18:14 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-02-03 16:18:14 +0100 |
commit | 85bec3ffcb0e2c948c57cee2817307af2826d847 (patch) | |
tree | 57d26e0d40e50d12da4d6913c3d30529a1e924cb /apps/comments/tests | |
parent | 8bb1437e240ce47e04f7bcb7dc3a56ef6b5d892b (diff) | |
download | nextcloud-server-85bec3ffcb0e2c948c57cee2817307af2826d847.tar.gz nextcloud-server-85bec3ffcb0e2c948c57cee2817307af2826d847.zip |
Reset comments read marker after loading comments
Diffstat (limited to 'apps/comments/tests')
-rw-r--r-- | apps/comments/tests/js/commentscollectionSpec.js | 44 | ||||
-rw-r--r-- | apps/comments/tests/js/commentstabviewSpec.js | 42 |
2 files changed, 82 insertions, 4 deletions
diff --git a/apps/comments/tests/js/commentscollectionSpec.js b/apps/comments/tests/js/commentscollectionSpec.js index 0dc68cc167c..2f41a272f67 100644 --- a/apps/comments/tests/js/commentscollectionSpec.js +++ b/apps/comments/tests/js/commentscollectionSpec.js @@ -100,5 +100,49 @@ describe('OCA.Comments.CommentCollection', function() { 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); + }); + }); }); diff --git a/apps/comments/tests/js/commentstabviewSpec.js b/apps/comments/tests/js/commentstabviewSpec.js index 0fb5eec0653..432fa5ddc4c 100644 --- a/apps/comments/tests/js/commentstabviewSpec.js +++ b/apps/comments/tests/js/commentstabviewSpec.js @@ -48,7 +48,7 @@ describe('OCA.Comments.CommentsTabView tests', function() { objectType: 'files', objectId: 5, message: 'First', - creationDateTime: Date.UTC(2016, 1, 3, 10, 5, 0) + creationDateTime: new Date(Date.UTC(2016, 1, 3, 10, 5, 0)).toUTCString() }); var comment2 = new OCA.Comments.CommentModel({ id: 2, @@ -58,7 +58,7 @@ describe('OCA.Comments.CommentsTabView tests', function() { objectType: 'files', objectId: 5, message: 'Second\nNewline', - creationDateTime: Date.UTC(2016, 1, 3, 10, 0, 0) + creationDateTime: new Date(Date.UTC(2016, 1, 3, 10, 0, 0)).toUTCString() }); testComments = [comment1, comment2]; @@ -142,7 +142,7 @@ describe('OCA.Comments.CommentsTabView tests', function() { objectType: 'files', objectId: 5, message: 'Third', - creationDateTime: Date.UTC(2016, 1, 3, 5, 0, 0) + creationDateTime: new Date(Date.UTC(2016, 1, 3, 5, 0, 0)).toUTCString() }); view.collection.add(comment3); @@ -184,7 +184,7 @@ describe('OCA.Comments.CommentsTabView tests', function() { actorType: 'users', verb: 'comment', message: 'New message', - creationDateTime: Date.UTC(2016, 1, 3, 10, 5, 9) + creationDateTime: new Date(Date.UTC(2016, 1, 3, 10, 5, 9)).toUTCString() }); }); it('does not create a comment if the field is empty', function() { @@ -195,4 +195,38 @@ describe('OCA.Comments.CommentsTabView tests', function() { }); }); + describe('read marker', function() { + var updateMarkerStub; + + beforeEach(function() { + updateMarkerStub = sinon.stub(OCA.Comments.CommentCollection.prototype, 'updateReadMarker'); + }); + afterEach(function() { + updateMarkerStub.restore(); + }); + + it('resets the read marker after REPORT', function() { + testComments[0].set('isUnread', true, {silent: true}); + testComments[1].set('isUnread', true, {silent: true}); + view.collection.set(testComments); + view.collection.trigger('sync', 'REPORT'); + + expect(updateMarkerStub.calledOnce).toEqual(true); + expect(updateMarkerStub.lastCall.args[0]).toBeFalsy(); + }); + it('does not reset the read marker if there was no unread comments', function() { + view.collection.set(testComments); + view.collection.trigger('sync', 'REPORT'); + + expect(updateMarkerStub.notCalled).toEqual(true); + }); + it('does not reset the read marker when posting comments', function() { + testComments[0].set('isUnread', true, {silent: true}); + testComments[1].set('isUnread', true, {silent: true}); + view.collection.set(testComments); + view.collection.trigger('sync', 'POST'); + + expect(updateMarkerStub.notCalled).toEqual(true); + }); + }); }); |