diff --git a/src/js/components/comment.js b/src/js/components/comment.js index ab0f627..08f932c 100644 --- a/src/js/components/comment.js +++ b/src/js/components/comment.js @@ -55,6 +55,7 @@ module.exports = class Comment extends PlayerUIComponent { // Return a Comment obj given body content and plugin reference static newFromData(body, commentList, plugin) { const data = this.dataObj(body, plugin); + data.commentList = commentList; return new Comment(data, plugin.player); } diff --git a/test/mocha/features/api_test.js b/test/mocha/features/api_test.js index d707886..7b1f20c 100644 --- a/test/mocha/features/api_test.js +++ b/test/mocha/features/api_test.js @@ -172,8 +172,12 @@ describe('external event-based API', () => { player.play().then(() => { const annotation = plugin.annotationState.annotations[0]; const { commentList } = annotation; + plugin.fire('newComment', { + annotationId: annotation.id, + body: 'My new comment' + }); const startingLength = commentList.comments.length; - const commentId = commentList.comments[0].id; + const commentId = commentList.comments[startingLength - 1].id; plugin.fire('destroyComment', { id: commentId }); expect(commentList.comments.length).to.equal(startingLength - 1); @@ -193,7 +197,7 @@ describe('external event-based API', () => { it('is triggered when plugin state is changed', done => { const plugin = simplePluginSetup(); - plugin.on('onStateChanged', event => { + plugin.registerListener('onStateChanged', event => { expect(event.detail[0].id).to.equal(2); done(); }); @@ -211,7 +215,7 @@ describe('external event-based API', () => { it('is triggered when comment is deleted', done => { const plugin = simplePluginSetup(); - plugin.on('annotationDeleted', event => { + plugin.registerListener('annotationDeleted', event => { expect(event.detail.id).to.equal(2); done(); }); @@ -233,7 +237,7 @@ describe('external event-based API', () => { const plugin = simplePluginSetup(); // Add listener - plugin.on('annotationOpened', event => { + plugin.registerListener('annotationOpened', event => { expect(event.detail.triggered_by_timeline).to.equal(false); expect(event.detail.annotation.id).to.equal(1); expect(event.detail.annotation.range.end).to.equal(60); @@ -258,7 +262,7 @@ describe('external event-based API', () => { const plugin = simplePluginSetup(); // Add listener - plugin.on('annotationOpened', event => { + plugin.registerListener('annotationOpened', event => { expect(event.detail.triggered_by_timeline).to.equal(true); expect(event.detail.annotation.id).to.equal(1); expect(event.detail.annotation.range.end).to.equal(60); @@ -285,7 +289,7 @@ describe('external event-based API', () => { const plugin = simplePluginSetup(); // Add listener - plugin.on('addingAnnotationDataChanged', event => { + plugin.registerListener('addingAnnotationDataChanged', event => { expect(event.detail.shape).to.not.be.undefined; done(); }); @@ -321,7 +325,7 @@ describe('external event-based API', () => { const plugin = simplePluginSetup(); // Add listener - plugin.on('addingAnnotationDataChanged', event => { + plugin.registerListener('addingAnnotationDataChanged', event => { expect(event.detail.range).to.not.be.undefined; done(); }); @@ -347,7 +351,7 @@ describe('external event-based API', () => { const plugin = simplePluginSetup(); // Add listener - plugin.on('addingAnnotationDataChanged', event => { + plugin.registerListener('addingAnnotationDataChanged', event => { expect(event.detail.range.start).to.equal(9); expect(event.detail.range.end).to.equal(20); done(); @@ -377,7 +381,7 @@ describe('external event-based API', () => { const plugin = simplePluginSetup(); // Add listener - plugin.on('enteredAddingAnnotation', event => { + plugin.registerListener('enteredAddingAnnotation', event => { expect(event.detail.range.start).to.not.be.undefined; done(); });