Skip to content

Commit

Permalink
Add instumentation test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehats committed Jan 10, 2024
1 parent 3788344 commit 4f2c055
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 1 deletion.
134 changes: 134 additions & 0 deletions src/client/cypress/e2e/editor/instrumentation-v2.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { loginAsAdmin, adminUserAuth, createBorehole } from "../testHelpers";

const openDropdown = dataCy => {
cy.get(`[data-cy="${dataCy}"]`)
.find('[role="combobox"]')
.click({ force: true });
};

const selectDropdownOption = index => {
cy.get('.MuiPaper-elevation [role="listbox"]')
.find('[role="option"]')
.eq(index)
.click();
};

describe("Instrumentation crud tests", () => {
it("add, edit and delete instrumentations", () => {
createBorehole({ "extended.original_name": "INTEADAL" })
.as("borehole_id")
.then(id =>
cy
.request({
method: "POST",
url: "/api/v2/completion",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
body: {
boreholeId: id,
isPrimary: true,
kindId: 16000002,
},
auth: adminUserAuth,
})
.then(response => {
expect(response).to.have.property("status", 200);
}),
);

// open completion editor
cy.get("@borehole_id").then(id =>
loginAsAdmin(`/editor/${id}/completion/v2`),
);

cy.contains("Tabs");

// start editing session
cy.contains("a", "Start editing").click();
cy.wait("@edit_lock");

// create instrumentation
cy.get('[data-cy="add-instrumentation-button"]');

cy.get('[data-cy="add-instrumentation-button"]').click({ force: true });
cy.wait("@instrumentation_GET");

// Necessary to wait for the instrumentation form to be loaded.
cy.wait(1000);

// fill out form
cy.get('[data-cy="notes-textfield"]')
.click()
.then(() => {
cy.get('[data-cy="notes-textfield"]').type("Lorem.", {
delay: 10,
});
});

cy.get('input[name="name"]')
.click()
.then(() => {
cy.get('input[name="name"]').type("Inst-1", {
delay: 10,
});
});

cy.get('input[name="fromDepth"]')
.click()
.then(() => {
cy.get('input[name="fromDepth"]').type("123456", {
delay: 10,
});
});

cy.get('input[name="toDepth"]')
.click()
.then(() => {
cy.get('input[name="toDepth"]').type("987654", {
delay: 10,
});
});

openDropdown("instrumentation-kind-select");
selectDropdownOption(2);

openDropdown("instrumentation-status-select");
selectDropdownOption(1);

// save instrumentation
cy.get('[data-cy="save-icon"]').click();

// check if instrumentation is saved
cy.contains("123456");
cy.contains("987654");
cy.contains("Inst-1");
cy.contains("Lorem.");
cy.contains("suction pump");
cy.contains("inactive");

// edit instrumentation
cy.get('[data-cy="edit-icon"]').click({ force: true });

cy.wait("@instrumentation_GET");

cy.get('input[name="fromDepth"]')
.click()
.then(() => {
cy.get('input[name="fromDepth"]').type("222", {
delay: 10,
});
});

// Necessary to wait, otherwise the type is not finished yet.
// It cannot be checked for the value of the input element, because the value is not updated yet.
cy.wait(1000);

// close editing mask
cy.get('[data-cy="save-icon"]').click({ force: true });
cy.contains("123456222");
cy.contains("inactive");
});
});
4 changes: 4 additions & 0 deletions src/client/cypress/e2e/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export const interceptApiCalls = () => {
return (req.alias = `hydrotest_${req.method}`);
});

cy.intercept("/api/v2/instrumentation*", req => {
return (req.alias = `instrumentation_${req.method}`);
});

cy.intercept("/api/v2/codelist*", req => {
return (req.alias = `codelist_${req.method}`);
});
Expand Down
2 changes: 1 addition & 1 deletion src/client/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { interceptApiCalls, loginAndResetState } from "../e2e/testHelpers";

Cypress.on('uncaught:exception', () => {
Cypress.on("uncaught:exception", () => {
// returning false here prevents Cypress from
// failing the test
return false;
Expand Down

0 comments on commit 4f2c055

Please sign in to comment.