Skip to content

Commit

Permalink
fix(api): Allow comments created via api to be destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpope committed Jan 24, 2020
1 parent b353f3b commit 5c8a4dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/js/components/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
22 changes: 13 additions & 9 deletions test/mocha/features/api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 5c8a4dc

Please sign in to comment.