Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Mobile dialog doesn't properly close on delete cancel/confirm #148

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/AnnotationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,8 @@ class AnnotationDialog extends EventEmitter {

// Clear annotations from dialog
util.hideElement(this.element);
this.element = util.generateMobileDialogEl();
this.unbindDOMListeners();

// Cancel any unsaved annotations
this.cancelAnnotation();
this.element = util.generateMobileDialogEl();
}

/**
Expand Down Expand Up @@ -556,6 +553,10 @@ class AnnotationDialog extends EventEmitter {
clickHandler(event) {
event.stopPropagation();

if (this.isMobile) {
event.preventDefault();
}

const eventTarget = event.target;
const dataType = util.findClosestDataType(eventTarget);
const annotationID = util.findClosestDataType(eventTarget, 'data-annotation-id');
Expand Down
29 changes: 16 additions & 13 deletions src/__tests__/AnnotationDialog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,11 @@ describe('AnnotationDialog', () => {
dialog.element = document.querySelector(constants.SELECTOR_MOBILE_ANNOTATION_DIALOG);
stubs.hide = sandbox.stub(util, 'hideElement');
stubs.unbind = sandbox.stub(dialog, 'unbindDOMListeners');
stubs.cancel = sandbox.stub(dialog, 'cancelAnnotation');
dialog.hasAnnotations = true;

dialog.hideMobileDialog();
expect(stubs.hide).to.be.called;
expect(stubs.unbind).to.be.called;
expect(stubs.cancel).to.be.called;
});

it('should cancel unsaved annotations only if the dialog does not have annotations', () => {
dialog.element = document.querySelector(constants.SELECTOR_MOBILE_ANNOTATION_DIALOG);
stubs.cancel = sandbox.stub(dialog, 'cancelAnnotation');
dialog.hasAnnotations = false;

dialog.hideMobileDialog();
expect(stubs.cancel).to.be.called;
});
});

Expand Down Expand Up @@ -707,8 +696,8 @@ describe('AnnotationDialog', () => {
describe('clickHandler()', () => {
beforeEach(() => {
stubs.event = {
stopPropagation: () => {},
preventDefault: () => {},
stopPropagation: sandbox.stub(),
preventDefault: sandbox.stub(),
target: document.createElement('div')
};
stubs.post = sandbox.stub(dialog, 'postAnnotation');
Expand All @@ -721,10 +710,24 @@ describe('AnnotationDialog', () => {
stubs.delete = sandbox.stub(dialog, 'deleteAnnotation');
stubs.reply = sandbox.stub(dialog, 'postReply');
stubs.hideMobile = sandbox.stub(dialog, 'hideMobileDialog');
dialog.isMobile = false;

dialog.element.classList.remove(constants.CLASS_HIDDEN);
});

it('should only stop propogation on a desktop device', () => {
dialog.clickHandler(stubs.event);
expect(stubs.event.stopPropagation).to.be.called;
expect(stubs.event.preventDefault).to.not.be.called;
});

it('should stop propogation AND prevent default on a mobile device', () => {
dialog.isMobile = true;
dialog.clickHandler(stubs.event);
expect(stubs.event.stopPropagation).to.be.called;
expect(stubs.event.preventDefault).to.be.called;
});

it('should post annotation when post annotation button is clicked', () => {
stubs.findClosest.returns(constants.DATA_TYPE_POST);

Expand Down