Skip to content

Commit 1fe30cf

Browse files
author
Jeremy Press
authored
Fix: Emit correct events when deleting a comment vs. a full annotation (#336)
1 parent eb0183c commit 1fe30cf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/doc/DocHighlightThread.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ class DocHighlightThread extends AnnotationThread {
113113
/** @inheritdoc */
114114
deleteSuccessHandler = () => {
115115
if (this.threadID) {
116+
this.emit(THREAD_EVENT.deleteComment);
116117
this.renderAnnotationPopover();
117118
} else {
118119
// $FlowFixMe
119120
const { page } = this.location;
121+
this.emit(THREAD_EVENT.delete);
120122
this.emit(THREAD_EVENT.render, { page });
121123
}
122124
};

src/doc/__tests__/DocHighlightThread-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@ describe('doc/DocHighlightThread', () => {
8585
});
8686
});
8787

88+
describe('deleteSuccessHandler()', () => {
89+
it('should emit comment deleted and render the popover if the thread still exists (one highlight comment in a thread was deleted)', () => {
90+
thread.emit = jest.fn();
91+
thread.renderAnnotationPopover = jest.fn();
92+
thread.threadID = 'foo';
93+
94+
thread.deleteSuccessHandler();
95+
96+
expect(thread.emit).toBeCalledWith(THREAD_EVENT.deleteComment);
97+
expect(thread.renderAnnotationPopover).toBeCalled();
98+
});
99+
100+
it('should emit deleted and a render event if the thread has been destroyed (the entire annotation was just deleted', () => {
101+
thread.emit = jest.fn();
102+
thread.location = {
103+
page: 1
104+
};
105+
thread.threadID = null;
106+
107+
thread.deleteSuccessHandler();
108+
109+
expect(thread.emit).toBeCalledWith(THREAD_EVENT.delete);
110+
expect(thread.emit).toBeCalledWith(THREAD_EVENT.render, { page: 1 });
111+
});
112+
});
113+
88114
describe('onClick()', () => {
89115
it('should set annotation to inactive if event has already been consumed', () => {
90116
thread.state = STATES.active;

0 commit comments

Comments
 (0)