Skip to content

Commit

Permalink
Fix: Ensure dialog is still visible on undo/redo (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Nov 30, 2018
1 parent 71afd21 commit 1c8a7e2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/AnnotationThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ class AnnotationThread extends EventEmitter {
* @return {void}
*/
reset() {
this.state = STATES.inactive;
if (this.threadNumber) {
// Saved thread
this.state = STATES.inactive;
} else {
// Newly created thread
this.state = STATES.pending;
}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/__tests__/AnnotationThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,16 @@ describe('AnnotationThread', () => {
});

describe('reset()', () => {
it('should set the thread state to inactive', () => {
it('should set the thread state to inactive if saved', () => {
thread.reset();
expect(thread.state).toEqual(STATES.inactive);
});

it('should set the thread state to pending if not saved', () => {
thread.threadNumber = undefined;
thread.reset();
expect(thread.state).toEqual(STATES.pending);
});
});

describe('save()', () => {
Expand Down
12 changes: 5 additions & 7 deletions src/drawing/DrawingThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class DrawingThread extends AnnotationThread {

if (this.pathContainer.isEmpty()) {
this.unmountPopover();
} else {
this.renderAnnotationPopover();
}

this.drawBoundary();
Expand All @@ -277,6 +279,8 @@ class DrawingThread extends AnnotationThread {

if (this.pathContainer.isEmpty()) {
this.unmountPopover();
} else {
this.renderAnnotationPopover();
}

this.drawBoundary();
Expand All @@ -290,13 +294,7 @@ class DrawingThread extends AnnotationThread {
* @return {void}
*/
setup() {
if (this.threadNumber) {
// Saved thread, load boundary dialog
this.state = STATES.inactive;
} else {
// Newly created thread
this.state = STATES.pending;
}
this.reset();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/drawing/__tests__/DrawingThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ describe('drawing/DrawingThread', () => {
thread.regenerateBoundary = jest.fn();
thread.drawBoundary = jest.fn();
thread.emitAvailableActions = jest.fn();
thread.unmountPopover = jest.fn();
thread.renderAnnotationPopover = jest.fn();
thread.pathContainer = {
isEmpty: jest.fn(),
undo: jest.fn().mockReturnValue(false)
Expand All @@ -220,13 +222,20 @@ describe('drawing/DrawingThread', () => {
expect(thread.updateBoundary).toBeCalled();
expect(thread.regenerateBoundary).toBeCalled();
expect(thread.drawBoundary).toBeCalled();
expect(thread.renderAnnotationPopover).toBeCalled();

thread.pathContainer.isEmpty = jest.fn().mockReturnValue(true);
thread.undo();
expect(thread.unmountPopover).toBeCalled();
});
});

describe('redo()', () => {
beforeEach(() => {
thread.draw = jest.fn();
thread.emitAvailableActions = jest.fn();
thread.unmountPopover = jest.fn();
thread.renderAnnotationPopover = jest.fn();
thread.pathContainer = {
isEmpty: jest.fn(),
redo: jest.fn().mockReturnValue(false),
Expand All @@ -247,6 +256,11 @@ describe('drawing/DrawingThread', () => {
expect(thread.pathContainer.redo).toBeCalled();
expect(thread.draw).toBeCalled();
expect(thread.emitAvailableActions).toBeCalled();
expect(thread.renderAnnotationPopover).toBeCalled();

thread.pathContainer.isEmpty = jest.fn().mockReturnValue(true);
thread.redo();
expect(thread.unmountPopover).toBeCalled();
});
});

Expand Down

0 comments on commit 1c8a7e2

Please sign in to comment.