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

Adapt borehole general segment #1647

Merged
merged 19 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- Hide the `help` button in the navigation bar in read-only mode.
- Hide the `original_name` field in the borehole detail view in read-only mode.
- Updated the style of the location tab.
- Changes on the location tab are now saved by clicking the `Save` button, instead of immediately.
- Changes on the location tab and the borehole tab are now saved by clicking the `Save` button, instead of immediately.

### Fixed

Expand Down
106 changes: 90 additions & 16 deletions src/client/cypress/e2e/detailPage/boreholeform.cy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { saveLocationForm } from "../helpers/buttonHelpers";
import { saveWithSaveBar } from "../helpers/buttonHelpers";
import { clickOnRowWithText, showTableAndWaitForData, sortBy } from "../helpers/dataGridHelpers";
import { evaluateInput, evaluateSelect, isDisabled, setSelect } from "../helpers/formHelpers";
import { evaluateInput, evaluateSelect, isDisabled, setInput, setSelect } from "../helpers/formHelpers";
import {
createBorehole,
goToRouteAndAcceptTerms,
handlePrompt,
newEditableBorehole,
returnToOverview,
startBoreholeEditing,
Expand Down Expand Up @@ -44,7 +45,7 @@ describe("Test for the borehole form.", () => {
evaluateSelect("qtReferenceElevationId", "20114002");
evaluateSelect("referenceElevationTypeId", "20117004");

saveLocationForm();
saveWithSaveBar();
// navigate away and back to check if values are saved
cy.get('[data-cy="borehole-menu-item"]').click();
cy.get('[data-cy="location-menu-item"]').click();
Expand All @@ -58,19 +59,92 @@ describe("Test for the borehole form.", () => {

// fill all dropdowns on borehole tab
cy.get('[data-cy="borehole-menu-item"]').click();
cy.get('[data-cy="domain-dropdown"]')
.should("have.length", 4)
.each(el => cy.wrap(el).click().find('[role="option"]').eq(1).click());

const boreholeDropdownValues = [];
cy.get('[data-cy="domain-dropdown"]')
.each(el => {
const value = el[0].children[1].firstChild.data;
boreholeDropdownValues.push(value);
})
.then(() => {
expect(boreholeDropdownValues).to.deep.eq(["borehole", "geotechnics", "open, no completion", "2"]);
});
setSelect("purposeId", 1);
setSelect("typeId", 1);
setSelect("qtDepthId", 1);
setSelect("statusId", 1);

evaluateSelect("purposeId", "22103001");
evaluateSelect("typeId", "20101001");
evaluateSelect("qtDepthId", "22108001");
evaluateSelect("statusId", "22104001");

saveWithSaveBar();

// navigate away and back to check if values are saved
cy.get('[data-cy="location-menu-item"]').click();
cy.get('[data-cy="borehole-menu-item"]').click();

evaluateSelect("purposeId", "22103001");
evaluateSelect("typeId", "20101001");
evaluateSelect("qtDepthId", "22108001");
evaluateSelect("statusId", "22104001");
});

it("Fills all inputs on borehole tab and saves", () => {
createBorehole({ "extended.original_name": "AAA_Ferret", "custom.alternate_name": "AAA_Ferret" }).as("borehole_id");
cy.get("@borehole_id").then(id => {
goToRouteAndAcceptTerms(`/${id}/borehole`);
startBoreholeEditing();

setSelect("purposeId", 1);
setSelect("typeId", 1);
setSelect("qtDepthId", 1);
setSelect("statusId", 1);
setSelect("lithologyTopBedrockId", 1);
setSelect("lithostratigraphyId", 1);
setSelect("chronostratigraphyId", 1);
setSelect("hasGroundwater", 1);

setInput("totalDepth", 700);
setInput("topBedrockFreshMd", 0.60224);
setInput("topBedrockWeatheredMd", 78945100);
setInput("remarks", "This is a test remark");

// navigate away is blocked before saving
cy.get('[data-cy="location-menu-item"]').click();

const messageUnsavedChanges = "There are unsaved changes. Do you want to discard all changes?";
handlePrompt(messageUnsavedChanges, "cancel");

saveWithSaveBar();
cy.get('[data-cy="location-menu-item"]').click();
cy.contains("Boreholes.swissgeol.ch ID");
});
});

it("Updates TVD Values when depth values change in boreholeform", () => {
createBorehole({ "extended.original_name": "AAA_Ferret", "custom.alternate_name": "AAA_Ferret" }).as("borehole_id");
cy.get("@borehole_id").then(id => {
goToRouteAndAcceptTerms(`/${id}/borehole`);
startBoreholeEditing();
setInput("totalDepth", 700);
setInput("topBedrockFreshMd", 0.60224);
setInput("topBedrockWeatheredMd", 78945100);

evaluateInput("totalDepth", "700");
evaluateInput("topBedrockFreshMd", "0.60224");
evaluateInput("topBedrockWeatheredMd", "78'945'100");

// in display only inputs the label is used for the data-cy instead of the field name
evaluateInput("total_depth_tvd", "700");
evaluateInput("top_bedrock_fresh_tvd", "0.6");
evaluateInput("top_bedrock_weathered_tvd", "78'945'100");

saveWithSaveBar();

returnToOverview();
showTableAndWaitForData();
clickOnRowWithText("AAA_Ferret");
cy.get('[data-cy="borehole-menu-item"]').click();
evaluateInput("totalDepth", "700");
evaluateInput("topBedrockFreshMd", "0.60224");
evaluateInput("topBedrockWeatheredMd", "78'945'100");

evaluateInput("total_depth_tvd", "700");
evaluateInput("top_bedrock_fresh_tvd", "0.6");
evaluateInput("top_bedrock_weathered_tvd", "78'945'100");
});
});

it("Checks if form values are updated when borehole changes", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/client/cypress/e2e/detailPage/coordinates.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { saveLocationForm } from "../helpers/buttonHelpers";
import { saveWithSaveBar } from "../helpers/buttonHelpers";
import { evaluateSelect, setSelect } from "../helpers/formHelpers";
import {
delayedType,
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("Tests for editing coordinates of a borehole.", () => {
checkDecimalPlaces("@LV03X-input", 2);
checkDecimalPlaces("@LV03Y-input", 2);

saveLocationForm();
saveWithSaveBar();
returnToOverview();
newUneditableBorehole();
// verify input are cleared for new borehole
Expand All @@ -169,7 +169,7 @@ describe("Tests for editing coordinates of a borehole.", () => {
checkDecimalPlaces("@LV03X-input", 4);
checkDecimalPlaces("@LV03Y-input", 4);

saveLocationForm();
saveWithSaveBar();
// Navigate somewhere else and return
cy.get('[data-cy="borehole-menu-item"]').click();
cy.get('[data-cy="location-menu-item"]').click();
Expand Down
8 changes: 4 additions & 4 deletions src/client/cypress/e2e/detailPage/location.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addItem, saveLocationForm, stopEditing } from "../helpers/buttonHelpers";
import { addItem, saveWithSaveBar, stopEditing } from "../helpers/buttonHelpers";
import { checkRowWithText, clickOnRowWithText, showTableAndWaitForData } from "../helpers/dataGridHelpers";
import { evaluateInput, evaluateSelect, setInput, setSelect } from "../helpers/formHelpers";
import {
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("Tests for 'Location' edit page.", () => {
originalNameInput.type("AAA_SCATORPS");

// save borehole
saveLocationForm();
saveWithSaveBar();

// stop editing
stopBoreholeEditing();
Expand Down Expand Up @@ -86,7 +86,7 @@ describe("Tests for 'Location' edit page.", () => {
cy.get("@alternateNameInput").should("have.value", "PHOTOMOUSE");

cy.get("@alternateNameInput").clear();
saveLocationForm();
saveWithSaveBar();
// should be reset to original name if alternate name is empty
cy.get("@originalNameInput").should("have.value", "PHOTOCAT");
cy.get("@alternateNameInput").should("have.value", "PHOTOCAT");
Expand Down Expand Up @@ -174,7 +174,7 @@ describe("Tests for 'Location' edit page.", () => {
originalNameInput.type("AAA_FELIX_THE_PANDA");

function saveFormAndReturnToOverview() {
saveLocationForm();
saveWithSaveBar();
returnToOverview();
}

Expand Down
8 changes: 4 additions & 4 deletions src/client/cypress/e2e/filters/identifierFilter.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addItem, saveLocationForm } from "../helpers/buttonHelpers";
import { addItem, saveWithSaveBar } from "../helpers/buttonHelpers";
import { checkAllVisibleRows, verifyPaginationText } from "../helpers/dataGridHelpers";
import { setInput, setSelect } from "../helpers/formHelpers";
import { newEditableBorehole, returnToOverview, stopBoreholeEditing } from "../helpers/testHelpers.js";
Expand All @@ -10,7 +10,7 @@ describe("Tests for filtering data by identifier.", () => {
addItem("addIdentifier");
setSelect("boreholeCodelists.0.codelistId", 1);
setInput("boreholeCodelists.0.value", 819544732);
saveLocationForm();
saveWithSaveBar();

stopBoreholeEditing();
returnToOverview();
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("Tests for filtering data by identifier.", () => {
addItem("addIdentifier");
setSelect("boreholeCodelists.0.codelistId", 1);
setInput("boreholeCodelists.0.value", 64531274);
saveLocationForm();
saveWithSaveBar();

stopBoreholeEditing();
returnToOverview();
Expand All @@ -49,7 +49,7 @@ describe("Tests for filtering data by identifier.", () => {
addItem("addIdentifier");
setSelect("boreholeCodelists.0.codelistId", 1);
setInput("boreholeCodelists.0.value", 436584127);
saveLocationForm();
saveWithSaveBar();

stopBoreholeEditing();
returnToOverview();
Expand Down
4 changes: 2 additions & 2 deletions src/client/cypress/e2e/filters/srsFilter.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { saveLocationForm } from "../helpers/buttonHelpers";
import { saveWithSaveBar } from "../helpers/buttonHelpers";
import { verifyPaginationText } from "../helpers/dataGridHelpers";
import { setSelect } from "../helpers/formHelpers";
import { loginAsAdmin, newEditableBorehole, returnToOverview, stopBoreholeEditing } from "../helpers/testHelpers.js";
Expand Down Expand Up @@ -43,7 +43,7 @@ describe("Tests for filtering data by reference system.", () => {
cy.get("@LV03X-input").type("645778", { delay: 10 });
cy.get("@LV03Y-input").type("245794", { delay: 10 });

saveLocationForm();
saveWithSaveBar();

stopBoreholeEditing();
returnToOverview();
Expand Down
2 changes: 1 addition & 1 deletion src/client/cypress/e2e/helpers/buttonHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createBaseSelector } from "./testHelpers";
* Clicks on the save button and waits for borehole update.
* @param {string} parent (optional) The parent of the button.
*/
export const saveLocationForm = parent => {
export const saveWithSaveBar = parent => {
saveForm(parent);
cy.wait(["@borehole_by_id", "@update-borehole"]);
};
Expand Down
9 changes: 0 additions & 9 deletions src/client/src/api-lib/actions/borehole.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ export function unlockBorehole(id) {
});
}

export function patchBorehole(id, field, value) {
return fetch("/borehole/edit", {
action: "PATCH",
id: id,
field: field,
value: value,
});
}

export function patchBoreholes(ids, fields) {
return fetch("/borehole/edit", {
action: "MULTIPATCH",
Expand Down
2 changes: 0 additions & 2 deletions src/client/src/api-lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
loadBoreholes,
loadEditingBoreholes,
lockBorehole,
patchBorehole,
patchBoreholes,
unlockBorehole,
updateBorehole,
Expand Down Expand Up @@ -51,7 +50,6 @@ export {
unlockBorehole,
deleteBorehole,
deleteBoreholes,
patchBorehole,
patchBoreholes,
getGeojson,
loadWorkflows,
Expand Down
13 changes: 13 additions & 0 deletions src/client/src/api/borehole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ export interface Identifier extends BasicIdentifier {
}

export interface BoreholeV2 {
lithologyTopBedrockId: number;
lithostratigraphyId: number;
chronostratigraphyId: number;
hasGroundwater: boolean | null;
topBedrockWeatheredMd: number;
topBedrockFreshMd: number;
qtDepthId: number;
totalDepth: number;
purposeId: number;
typeId: number;
remarks: string;
statusId: number;
workflow: Workflow;
boreholeCodelists: BasicIdentifier[];
workflows: Workflow[];
originalReferenceSystem: number;
Expand Down
1 change: 1 addition & 0 deletions src/client/src/components/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ export { FormDisplay } from "./formDisplay";
export { FormCoordinate } from "./formCoordinate";
export { FormContainer } from "./formContainer";
export { FormBooleanSelect } from "./formBooleanSelect";
export { FormInputDisplayOnly } from "./formInputDisplayOnly";
39 changes: 39 additions & 0 deletions src/client/src/components/form/formInputDisplayOnly.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { TextField, TextFieldProps } from "@mui/material";
import { NumericFormatWithThousandSeparator } from "./numericFormatWithThousandSeparator.tsx";

interface FormInputDisplayOnlyProps extends Omit<TextFieldProps, "value"> {
label: string;
value: number | null;
withThousandSeparator?: boolean;
disabled?: boolean;
readOnly?: boolean;
}

export const FormInputDisplayOnly: React.FC<FormInputDisplayOnlyProps> = ({
label,
value,
withThousandSeparator,
readOnly = true,
disabled = true,
...props
}) => {
const { t } = useTranslation();
return (
<TextField
label={t(label)}
data-cy={label + "-formInput"}
value={value}
InputProps={{
/* eslint-disable @typescript-eslint/no-explicit-any */
...(withThousandSeparator && { inputComponent: NumericFormatWithThousandSeparator as any }),
readOnly: readOnly,
disabled: disabled,
...props.InputProps,
}}
className="readonly"
{...props}
/>
);
};
Loading
Loading