Skip to content

Commit

Permalink
Stop editing when leaving borehole with back button (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt authored Oct 22, 2024
2 parents 0645f08 + b08211c commit 320ea36
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
39 changes: 38 additions & 1 deletion src/client/cypress/e2e/detailPage/boreholeform.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { clickOnRowWithText, showTableAndWaitForData, sortBy } from "../helpers/dataGridHelpers";
import { evaluateInput, evaluateSelect, isDisabled, setSelect } from "../helpers/formHelpers";
import { createBorehole, goToRouteAndAcceptTerms, newEditableBorehole, returnToOverview } from "../helpers/testHelpers";
import {
createBorehole,
goToRouteAndAcceptTerms,
newEditableBorehole,
returnToOverview,
startBoreholeEditing,
} from "../helpers/testHelpers";

function ensureEditingDisabled() {
cy.get('[data-cy="edit-button"]').should("exist");
cy.get('[data-cy="editingstop-button"]').should("not.exist");
}

function ensureEditingEnabled() {
cy.get('[data-cy="edit-button"]').should("not.exist");
cy.get('[data-cy="editingstop-button"]').should("exist");
}

describe("Test for the borehole form.", () => {
it("Creates a borehole and fills dropdowns.", () => {
Expand Down Expand Up @@ -107,4 +123,25 @@ describe("Test for the borehole form.", () => {
expect(location.hash).to.eq("#geometry");
});
});

it.only("stops editing when going back to overview", () => {
createBorehole({ "extended.original_name": "AAA_HIPPOPOTHAMUS", "custom.alternate_name": "AAA_HIPPOPOTHAMUS" }).as(
"borehole_id",
);
cy.get("@borehole_id").then(id => {
goToRouteAndAcceptTerms(`/${id}`);
ensureEditingDisabled();
startBoreholeEditing();
ensureEditingEnabled();
returnToOverview(); // navigating with swissgeol back button stops editing
showTableAndWaitForData();
clickOnRowWithText("AAA_HIPPOPOTHAMUS");
ensureEditingDisabled();
startBoreholeEditing();
goToRouteAndAcceptTerms(`/`); // navigating with browser does not stop editing
showTableAndWaitForData();
clickOnRowWithText("AAA_HIPPOPOTHAMUS");
ensureEditingEnabled();
});
});
});
9 changes: 5 additions & 4 deletions src/client/src/pages/detail/detailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const DetailHeader = ({ editingEnabled, setEditingEnabled, editableByCurrentUser
const { t } = useTranslation();
const { showPrompt } = useContext(PromptContext);

const toggleEditing = (editingEnabled: boolean) => {
setEditingEnabled(editingEnabled);
if (borehole.data.lock !== null && borehole.data.lock.id === user.data.id) {
const toggleEditing = (editing: boolean) => {
setEditingEnabled(editing);
if (!editing && borehole.data.lock !== null && borehole.data.lock.id === user.data.id) {
dispatch(unlockBorehole(borehole.data.id));
} else if (borehole.data.lock === null) {
} else if (editing && borehole.data.lock === null) {
dispatch(lockBorehole(borehole.data.id));
}
};
Expand Down Expand Up @@ -64,6 +64,7 @@ const DetailHeader = ({ editingEnabled, setEditingEnabled, editableByCurrentUser
color="primary"
data-cy="backButton"
onClick={() => {
stopEditing();
history.push("/");
}}
sx={{
Expand Down

0 comments on commit 320ea36

Please sign in to comment.