Skip to content

Commit

Permalink
Fix #3906 the 'back' button does not undo the annotation creation (#3967
Browse files Browse the repository at this point in the history
)

* Fix #3906  the 'back' button does not undo the annotation creation

fix #3906

* improve test coverage
  • Loading branch information
kasongoyo authored and Tobia Di Pisa committed Jul 17, 2019
1 parent 1f85afe commit 193cb08
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,7 @@ class AnnotationsEditor extends React.Component {
visible: true,
onClick: () => {
if (this.props.unsavedChanges) {
const errors = this.validate();
if (Object.keys(errors).length === 0) {
this.props.onToggleUnsavedChangesModal();
} else {
this.props.onError(errors);
}
this.props.onToggleUnsavedChangesModal();
} else {
this.cancelEdit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,36 @@ describe("test the AnnotationsEditor Panel", () => {
expect(spyCancel.calls.length).toEqual(1);
});

it('test click cancel trigger UnsavedChangesModal', () => {
const feature = {
id: "1",
title: 'mytitle',
description: '<span><i>desc</i></span>'
};

const testHandlers = {
onToggleUnsavedChangesModal: (id) => { return id; }
};

const spyUnsavedModal = expect.spyOn(testHandlers, 'onToggleUnsavedChangesModal');

const viewer = ReactDOM.render(<AnnotationsEditor {...feature} {...actions} editing={{
properties: feature,
geometry: {}
}}
onToggleUnsavedChangesModal={testHandlers.onToggleUnsavedChangesModal}
unsavedChanges
/>, document.getElementById("container"));
expect(viewer).toExist();

let cancelButton = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithTag(viewer, "button")[0]);

expect(cancelButton).toExist();
TestUtils.Simulate.click(cancelButton);

expect(spyUnsavedModal.calls.length).toEqual(1);
});

it('test click save validate title error', () => {
const feature = {
id: "1",
Expand Down

0 comments on commit 193cb08

Please sign in to comment.