Skip to content

Commit

Permalink
Identifier segment (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt authored Oct 17, 2024
2 parents f16101b + 0f4efce commit 4dbf7c1
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 251 deletions.
17 changes: 1 addition & 16 deletions src/client/cypress/e2e/detailPage/boreholeform.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@ describe("Test for the borehole form.", () => {
// create boreholes
newEditableBorehole().as("borehole_id");

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

const locationDropdownValues = [];
cy.get('[data-cy="domain-dropdown"]')
.each(el => {
const value = el[0].children[1].firstChild.data;
locationDropdownValues.push(value);
})
.then(() => {
expect(locationDropdownValues).to.deep.eq(["ID Kernlager"]);
});

// fills and evaluates all mui dropdowns on location tab
// fills and evaluates all mui dropdowns on location tab (identifiers are tested separately)
setSelect("restriction", 2);
isDisabled("restriction_until", true);
setSelect("restriction", 3);
Expand Down
29 changes: 14 additions & 15 deletions src/client/cypress/e2e/detailPage/location.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { checkRowWithText, showTableAndWaitForData } from "../helpers/dataGridHelpers";
import { setInput, setSelect } from "../helpers/formHelpers";
import {
createBorehole,
goToRouteAndAcceptTerms,
Expand Down Expand Up @@ -69,30 +70,28 @@ describe("Tests for 'Location' edit page.", () => {
});
});

it("removes error highlight of identifier fields if at least one identifier is present.", () => {
it("adds and removes identifiers.", () => {
newEditableBorehole().as("borehole_id");

// initial state
cy.get('[data-cy="identifier-dropdown"]').should("have.class", "error");
cy.get('[data-cy="identifier-value"]').should("have.class", "error");
cy.get('[data-cy="identifier-add"]').should("be.disabled");

// add identifier
cy.get('[data-cy="identifier-dropdown"]').click();
cy.get('[data-cy="identifier-dropdown"]').find("div[role='option']").contains("ID Canton").click();
cy.get('[data-cy="identifier-dropdown"]').should("not.have.class", "error");
cy.get('[data-cy="identifier-value"]').should("have.class", "error");
setSelect("borehole_identifier", 5);
cy.get('[data-cy="identifier-add"]').should("be.disabled");

cy.get('[data-cy="identifier-value"]').type("ECKLERTA");
cy.get('[data-cy="identifier-dropdown"]').should("not.have.class", "error");
cy.get('[data-cy="identifier-value"]').should("not.have.class", "error");
setInput("borehole_identifier_value", "ECKLERTA");
cy.get('[data-cy="identifier-add"]').should("not.be.disabled");

cy.get('[data-cy="identifier-add"]').click();
cy.get('[data-cy="identifier-dropdown"]').should("not.have.class", "error");
cy.get('[data-cy="identifier-value"]').should("not.have.class", "error");
cy.contains("ID Canton").should("exist");
cy.contains("ECKLERTA").should("exist");

cy.get('[data-cy="identifier-add"]').should("be.disabled");

// delete identifier
cy.get('[data-cy="identifier"]').contains("Delete").click();
cy.get('[data-cy="identifier-dropdown"]').should("have.class", "error");
cy.get('[data-cy="identifier-value"]').should("have.class", "error");
cy.get('[data-cy="identifier-delete"]').click();
cy.contains("ID Canton").should("not.exist");
cy.get('[data-cy="identifier-add"]').should("be.disabled");
});
});
24 changes: 7 additions & 17 deletions src/client/cypress/e2e/filters/identifierFilter.cy.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { checkAllVisibleRows, verifyPaginationText } from "../helpers/dataGridHelpers";
import { setInput, setSelect } from "../helpers/formHelpers";
import { newEditableBorehole, returnToOverview, stopBoreholeEditing } from "../helpers/testHelpers.js";

describe("Tests for filtering data by identifier.", () => {
it("can filter by identifier", () => {
newEditableBorehole().as("borehole_id");
let identifierDropdown = cy.get('[data-cy="identifier-dropdown"]');

identifierDropdown.each(el =>
cy.wrap(el).click({ force: true }).find('[role="option"]').eq(1).click({ force: true }),
);

cy.get('[data-cy="identifier-value"] input').type(819544732);
setSelect("borehole_identifier", 1);
setInput("borehole_identifier_value", 819544732);
cy.get('[data-cy="identifier-add"]').click();

stopBoreholeEditing();
Expand Down Expand Up @@ -38,26 +35,19 @@ describe("Tests for filtering data by identifier.", () => {

it("can bulk edit boreholes while filter by identifier is set", () => {
newEditableBorehole().as("borehole_id");
let identifierDropdown = cy.get('[data-cy="identifier-dropdown"]');

identifierDropdown.each(el =>
cy.wrap(el).click({ force: true }).find('[role="option"]').eq(1).click({ force: true }),
);
setSelect("borehole_identifier", 1);

cy.get('[data-cy="identifier-value"] input').type(64531274);
setInput("borehole_identifier_value", 64531274);
cy.get('[data-cy="identifier-add"]').click();

stopBoreholeEditing();
returnToOverview();

newEditableBorehole().as("borehole_id_2");
identifierDropdown = cy.get('[data-cy="identifier-dropdown"]');

identifierDropdown.each(el =>
cy.wrap(el).click({ force: true }).find('[role="option"]').eq(1).click({ force: true }),
);
setSelect("borehole_identifier", 1);

cy.get('[data-cy="identifier-value"] input').type(436584127);
setInput("borehole_identifier_value", 436584127);
cy.get('[data-cy="identifier-add"]').click();

stopBoreholeEditing();
Expand Down
15 changes: 6 additions & 9 deletions src/client/cypress/e2e/mainPage/bulkedit.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ function giveAdminUser2workgroups() {
}

describe("Test the borehole bulk edit feature.", () => {
it.skip("opens the bulk edit dialog with all boreholes selected", () => {
it("opens the bulk edit dialog with all boreholes selected", () => {
giveAdminUser1workgroup();
showTableAndWaitForData();
checkAllVisibleRows();
cy.contains("button", "Bulk editing").click({ force: true });
cy.get("h1").should("have.text", "Bulk editing");
});

it.skip("displays workgroup accordion only if user has permission for more than one workgroup", () => {
it("displays workgroup accordion only if user has permission for more than one workgroup", () => {
giveAdminUser1workgroup();
checkAllVisibleRows();
cy.contains("button", "Bulk editing").click({ force: true });
Expand All @@ -77,7 +77,6 @@ describe("Test the borehole bulk edit feature.", () => {

it("fills all bulkedit fields and saves.", () => {
createBoreholes();
giveAdminUser1workgroup();
goToRouteAndAcceptTerms(`/`);
showTableAndWaitForData();
cy.wait("@borehole");
Expand Down Expand Up @@ -110,12 +109,10 @@ describe("Test the borehole bulk edit feature.", () => {
cy.wrap($input).scrollIntoView().clear().type(`${index}`);
});

cy.get('[role="combobox"]')
.should("have.length", 14)
.each(el => {
cy.wrap(el).click();
cy.get('li[role="option"]').last().click();
});
cy.get('[role="combobox"]').each(el => {
cy.wrap(el).click();
cy.get('li[role="option"]').last().click();
});

// save
cy.contains("button", "Save").click();
Expand Down
9 changes: 8 additions & 1 deletion src/client/src/api-lib/ReduxStateInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ interface Workflow {
workflow: number;
}

interface BoreholeAttributes {
export interface Identifier {
id: number;
identifier: string;
value: string;
}

export interface BoreholeAttributes {
national_interest: boolean;
restriction_until: Date;
restriction: number;
Expand Down Expand Up @@ -85,6 +91,7 @@ interface BoreholeAttributes {
precision_location_x_lv03: number;
precision_location_y_lv03: number;
custom: {
identifiers: Identifier[];
country: string;
canton: string;
municipality: string;
Expand Down
4 changes: 2 additions & 2 deletions src/client/src/components/form/simpleDomainSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface SimpleDomainSelectProps {
selected?: number | boolean | null;
sx?: SxProps;
className?: string;
onUpdate?: (value: number | boolean | string | null) => void;
onUpdate?: (value: number | null) => void;
}

export const SimpleDomainSelect: FC<SimpleDomainSelectProps> = ({
Expand Down Expand Up @@ -63,7 +63,7 @@ export const SimpleDomainSelect: FC<SimpleDomainSelectProps> = ({
name={fieldName}
onChange={e => {
if (onUpdate) {
onUpdate(e.target.value);
onUpdate(parseInt(e.target.value));
}
}}
value={selected}
Expand Down
11 changes: 3 additions & 8 deletions src/client/src/pages/detail/detailPageContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import FieldMeasurement from "./form/hydrogeology/fieldMeasurement.jsx";
import GroundwaterLevelMeasurement from "./form/hydrogeology/groundwaterLevelMeasurement.jsx";
import Hydrotest from "./form/hydrogeology/hydrotest.jsx";
import WaterIngress from "./form/hydrogeology/waterIngress.jsx";
import IdentifierSegment from "./form/location/indentifierSegment.jsx";
import IdentifierSegment from "./form/location/identifierSegment.tsx";
import LocationSegment from "./form/location/locationSegment.tsx";
import NameSegment from "./form/location/nameSegment.tsx";
import RestrictionSegment from "./form/location/restrictionSegment.tsx";
Expand Down Expand Up @@ -55,7 +55,6 @@ class DetailPageContent extends React.Component {
this.updateNumber = this.updateNumber.bind(this);
this.updateChange = this.updateChange.bind(this);
this.patch = this.patch.bind(this);
this.setStateBound = this.setState.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -226,7 +225,7 @@ class DetailPageContent extends React.Component {
}

render() {
const { t, borehole, user, editingEnabled } = this.props;
const { t, borehole, editingEnabled } = this.props;
if (borehole.error !== null) {
return <div>{t(borehole.error, borehole.data)}</div>;
}
Expand Down Expand Up @@ -280,11 +279,8 @@ class DetailPageContent extends React.Component {
<Stack gap={3} mr={2}>
<IdentifierSegment
borehole={borehole}
identifier={this.state.identifier}
identifierValue={this.state.identifierValue}
setState={this.setStateBound}
updateBorehole={this.props.updateBorehole}
user={user}></IdentifierSegment>
editingEnabled={editingEnabled}></IdentifierSegment>
<NameSegment
borehole={borehole}
updateChange={this.updateChange}
Expand Down Expand Up @@ -423,7 +419,6 @@ const mapStateToProps = state => {
borehole: state.core_borehole,
workflow: state.core_workflow,
domains: state.core_domain_list,
user: state.core_user,
};
};

Expand Down
Loading

0 comments on commit 4dbf7c1

Please sign in to comment.