Skip to content

Commit 5c8a4dc

Browse files
committed
fix(api): Allow comments created via api to be destroyed
1 parent b353f3b commit 5c8a4dc

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/js/components/comment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module.exports = class Comment extends PlayerUIComponent {
5555
// Return a Comment obj given body content and plugin reference
5656
static newFromData(body, commentList, plugin) {
5757
const data = this.dataObj(body, plugin);
58+
data.commentList = commentList;
5859
return new Comment(data, plugin.player);
5960
}
6061

test/mocha/features/api_test.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,12 @@ describe('external event-based API', () => {
172172
player.play().then(() => {
173173
const annotation = plugin.annotationState.annotations[0];
174174
const { commentList } = annotation;
175+
plugin.fire('newComment', {
176+
annotationId: annotation.id,
177+
body: 'My new comment'
178+
});
175179
const startingLength = commentList.comments.length;
176-
const commentId = commentList.comments[0].id;
180+
const commentId = commentList.comments[startingLength - 1].id;
177181
plugin.fire('destroyComment', { id: commentId });
178182

179183
expect(commentList.comments.length).to.equal(startingLength - 1);
@@ -193,7 +197,7 @@ describe('external event-based API', () => {
193197
it('is triggered when plugin state is changed', done => {
194198
const plugin = simplePluginSetup();
195199

196-
plugin.on('onStateChanged', event => {
200+
plugin.registerListener('onStateChanged', event => {
197201
expect(event.detail[0].id).to.equal(2);
198202
done();
199203
});
@@ -211,7 +215,7 @@ describe('external event-based API', () => {
211215
it('is triggered when comment is deleted', done => {
212216
const plugin = simplePluginSetup();
213217

214-
plugin.on('annotationDeleted', event => {
218+
plugin.registerListener('annotationDeleted', event => {
215219
expect(event.detail.id).to.equal(2);
216220
done();
217221
});
@@ -233,7 +237,7 @@ describe('external event-based API', () => {
233237
const plugin = simplePluginSetup();
234238

235239
// Add listener
236-
plugin.on('annotationOpened', event => {
240+
plugin.registerListener('annotationOpened', event => {
237241
expect(event.detail.triggered_by_timeline).to.equal(false);
238242
expect(event.detail.annotation.id).to.equal(1);
239243
expect(event.detail.annotation.range.end).to.equal(60);
@@ -258,7 +262,7 @@ describe('external event-based API', () => {
258262
const plugin = simplePluginSetup();
259263

260264
// Add listener
261-
plugin.on('annotationOpened', event => {
265+
plugin.registerListener('annotationOpened', event => {
262266
expect(event.detail.triggered_by_timeline).to.equal(true);
263267
expect(event.detail.annotation.id).to.equal(1);
264268
expect(event.detail.annotation.range.end).to.equal(60);
@@ -285,7 +289,7 @@ describe('external event-based API', () => {
285289
const plugin = simplePluginSetup();
286290

287291
// Add listener
288-
plugin.on('addingAnnotationDataChanged', event => {
292+
plugin.registerListener('addingAnnotationDataChanged', event => {
289293
expect(event.detail.shape).to.not.be.undefined;
290294
done();
291295
});
@@ -321,7 +325,7 @@ describe('external event-based API', () => {
321325
const plugin = simplePluginSetup();
322326

323327
// Add listener
324-
plugin.on('addingAnnotationDataChanged', event => {
328+
plugin.registerListener('addingAnnotationDataChanged', event => {
325329
expect(event.detail.range).to.not.be.undefined;
326330
done();
327331
});
@@ -347,7 +351,7 @@ describe('external event-based API', () => {
347351
const plugin = simplePluginSetup();
348352

349353
// Add listener
350-
plugin.on('addingAnnotationDataChanged', event => {
354+
plugin.registerListener('addingAnnotationDataChanged', event => {
351355
expect(event.detail.range.start).to.equal(9);
352356
expect(event.detail.range.end).to.equal(20);
353357
done();
@@ -377,7 +381,7 @@ describe('external event-based API', () => {
377381
const plugin = simplePluginSetup();
378382

379383
// Add listener
380-
plugin.on('enteredAddingAnnotation', event => {
384+
plugin.registerListener('enteredAddingAnnotation', event => {
381385
expect(event.detail.range.start).to.not.be.undefined;
382386
done();
383387
});

0 commit comments

Comments
 (0)