Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt committed Aug 14, 2024
1 parent 999df87 commit e2e5cf3
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 118 deletions.
144 changes: 49 additions & 95 deletions src/client/cypress/e2e/editor/boreholeTable.cy.js
Original file line number Diff line number Diff line change
@@ -1,129 +1,83 @@
import { loginAsAdmin, loginAsEditor, returnToOverview } from "../helpers/testHelpers.js";
import {
showTableAndWaitForData,
verifiyPaginationText,
verifyRowContains,
waitForTableData,
} from "../helpers/dataGridHelpers";

function sortBy(headerTextContent) {
cy.get(".MuiDataGrid-columnHeader").contains(headerTextContent).click();
cy.wait("@edit_list");
cy.get(".loading-indicator").should("not.exist");
}

describe("Borehole editor table tests", () => {
it("Boreholes are displayed in correct order with admin login", () => {
loginAsAdmin();
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();

cy.wait("@edit_list");
cy.get("div[id=map]").should("be.visible");

cy.get(".MuiDataGrid-root").should("be.visible");
cy.get(".loading-indicator").should("not.exist");
showTableAndWaitForData();

// default soring by name ascending
cy.get(".MuiDataGrid-row")
.eq(0)
.within(() => {
cy.contains("Aaliyah Casper").should("exist");
});
cy.get(".MuiDataGrid-row")
.eq(1)
.within(() => {
cy.contains("Aaliyah Lynch").should("exist");
});
cy.get(".MuiDataGrid-row")
.eq(2)
.within(() => {
cy.contains("Aaron Bartell").should("exist");
});
verifyRowContains("Aaliyah Casper", 0);
verifyRowContains("Aaliyah Lynch", 1);
verifyRowContains("Aaron Bartell", 2);

// sort by Name descending
cy.get(".MuiDataGrid-columnHeader").contains("Name").click();
cy.get(".MuiDataGrid-root").should("be.visible");
cy.get(".loading-indicator").should("not.exist");

cy.get(".MuiDataGrid-row")
.eq(0)
.within(() => {
cy.contains("Zena Rath").should("exist");
});
cy.get(".MuiDataGrid-row")
.eq(1)
.within(() => {
cy.contains("Zena Mraz").should("exist");
});
cy.get(".MuiDataGrid-row")
.eq(2)
.within(() => {
cy.contains("Zena Halvorson").should("exist");
});

// sort by borehole length desc
cy.get(".MuiDataGrid-columnHeader").contains("Borehole length").click();
cy.get(".MuiDataGrid-columnHeader").contains("Borehole length").click();
cy.get(".MuiDataGrid-root").should("be.visible");
cy.get(".loading-indicator").should("not.exist");

cy.wait("@edit_list");
cy.get(".MuiDataGrid-row")
.eq(0)
.within(() => {
cy.contains("1998.07").should("exist");
});
cy.get(".MuiDataGrid-row")
.eq(1)
.within(() => {
cy.contains("1997.79").should("exist");
});
sortBy("Name");
verifyRowContains("Zena Rath", 0);
verifyRowContains("Zena Mraz", 1);
verifyRowContains("Zena Halvorson", 2);

// sort by borehole length descending
sortBy("Borehole length");
sortBy("Borehole length");
verifyRowContains("1998.07", 0);
verifyRowContains("1997.79", 1);
verifyRowContains("1995.5", 2);

// sort by reference elevation
cy.get(".MuiDataGrid-columnHeader").contains("Reference elevation").click();

cy.wait("@edit_list");
cy.get(".MuiDataGrid-row")
.eq(0)
.within(() => {
cy.contains("3.36").should("exist");
});
sortBy("Reference elevation");
verifyRowContains("3.36", 0);
verifyRowContains("4.26", 1);
verifyRowContains("4.58", 2);

// sort by borehole type
sortBy("Borehole type");
verifyRowContains("borehole", 0);
verifyRowContains("borehole", 1);
verifyRowContains("borehole", 2);
});

it("preserves column sorting and active page when navigating", () => {
loginAsEditor();
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();

// sort by name descending
cy.get(".MuiDataGrid-columnHeaderTitle").contains("Name").click();
cy.wait("@edit_list");

cy.get(".MuiDataGrid-row")
.eq(0)
.within(() => {
cy.contains("Zena Rath").should("exist");
});
sortBy("Name");
verifyRowContains("Zena Rath", 0);

// navigate to page 4
cy.get('[aria-label="next page"]').scrollIntoView().click();
cy.wait("@edit_list");
waitForTableData();
cy.get('[aria-label="next page"]').scrollIntoView().click();
cy.wait("@edit_list");
waitForTableData();
cy.get('[aria-label="next page"]').scrollIntoView().click();
cy.wait("@edit_list");
waitForTableData();
cy.get('[aria-label="next page"]').scrollIntoView().click();
cy.wait("@edit_list");
waitForTableData();

// verify current page is 4
cy.get(".MuiTablePagination-displayedRows").should("have.text", "401 - 500 of 1627");
cy.get(".MuiDataGrid-row")
.eq(0)
.within(() => {
cy.contains("Nichole VonRueden").should("exist").click();
});
cy.wait("@edit_list");
verifiyPaginationText("401 - 500 of 1627");
verifyRowContains("Nichole VonRueden", 0);

// return to list
returnToOverview();

// verify current page is still 4
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiDataGrid-row").should("have.length.greaterThan", 0);
cy.get(".MuiTablePagination-displayedRows").should("have.text", "401 - 500 of 1627");
cy.get(".MuiDataGrid-row")
.eq(0)
.within(() => {
cy.contains("Nichole VonRueden").should("exist").click();
});
showTableAndWaitForData();
verifiyPaginationText("401 - 500 of 1627");
verifyRowContains("Nichole VonRueden", 0);
});
});
16 changes: 5 additions & 11 deletions src/client/cypress/e2e/editor/bulkedit.cy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { createBorehole, loginAsAdmin, startBoreholeEditing, stopBoreholeEditing } from "../helpers/testHelpers";
import adminUser from "../../fixtures/adminUser.json";
import { showTableAndWaitForData } from "../helpers/dataGridHelpers";

beforeEach(() => {
loginAsAdmin();
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiDataGrid-root").should("be.visible");
cy.get(".MuiDataGrid-row").should("have.length.greaterThan", 0);
cy.get(".loading-indicator").should("not.exist");
showTableAndWaitForData();
});

describe("Test the borehole bulk edit feature.", () => {
Expand Down Expand Up @@ -49,10 +47,7 @@ describe("Test the borehole bulk edit feature.", () => {
body: JSON.stringify(adminUser2Workgroups),
}).as("adminUser2Workgroups");
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiDataGrid-root").should("be.visible");
cy.get(".MuiDataGrid-row").should("have.length.greaterThan", 0);
cy.get(".loading-indicator").should("not.exist");
showTableAndWaitForData();
cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").find('input[type="checkbox"]').check({ force: true });
cy.contains("button", "Bulk editing").click({ force: true });

Expand All @@ -74,7 +69,7 @@ describe("Test the borehole bulk edit feature.", () => {

loginAsAdmin();
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();
cy.wait("@borehole");

// select the boreholes for bulk edit
Expand Down Expand Up @@ -133,8 +128,7 @@ describe("Test the borehole bulk edit feature.", () => {
cy.visit(`/${id}/borehole`);
startBoreholeEditing();
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiDataGrid-row").should("have.length.greaterThan", 0);
showTableAndWaitForData();
cy.contains(".MuiDataGrid-row", "AAA_JUNIORSOUFFLE")
.find('.MuiCheckbox-root input[type="checkbox"]')
.should("be.disabled");
Expand Down
3 changes: 2 additions & 1 deletion src/client/cypress/e2e/editor/copyBorehole.cy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { createBorehole, handlePrompt, loginAsAdmin, startBoreholeEditing } from "../helpers/testHelpers";
import { showTableAndWaitForData } from "../helpers/dataGridHelpers";

describe("Test copying of boreholes", () => {
it("copies a borehole", () => {
createBorehole({ "extended.original_name": "NINTIC" }).as("borehole_id_1");

loginAsAdmin();
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();
cy.get(".MuiDataGrid-checkboxInput").eq(1).scrollIntoView().click();

cy.contains("button", "Create a copy").click();
Expand Down
3 changes: 2 additions & 1 deletion src/client/cypress/e2e/editor/location.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { newEditableBorehole, returnToOverview, stopBoreholeEditing } from "../helpers/testHelpers";
import { showTableAndWaitForData } from "../helpers/dataGridHelpers";

describe("Tests for 'Location' edit page.", () => {
it("creates and deletes a borehole.", () => {
Expand All @@ -11,7 +12,7 @@ describe("Tests for 'Location' edit page.", () => {
// stop editing
stopBoreholeEditing();
returnToOverview();
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();

// search the newly created borehole and delete it
cy.get('[data-cy="borehole-table"]').within(() => {
Expand Down
12 changes: 7 additions & 5 deletions src/client/cypress/e2e/filters/filter.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { loginAsAdmin } from "../helpers/testHelpers.js";
import { verifiyPaginationText } from "../helpers/dataGridHelpers";

describe("Search filter tests", () => {
it("has search filters", () => {
Expand Down Expand Up @@ -90,7 +91,7 @@ describe("Search filter tests", () => {

// check content of table
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 329"); // when testing with cypress locally use electron browser, otherwise text might be displayed as "1-100 of 329"
verifiyPaginationText("1 - 100 of 329"); // when testing with cypress locally use electron browser, otherwise text might be displayed as "1-100 of 329"
});

it("filters boreholes by color and uscs3", () => {
Expand All @@ -116,7 +117,7 @@ describe("Search filter tests", () => {

cy.wait("@edit_list");
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 229");
verifiyPaginationText("1 - 100 of 229");

let uscs3Dropdown = cy.contains("label", "USCS 3").next();
uscs3Dropdown.scrollIntoView().click({ force: true });
Expand All @@ -134,7 +135,7 @@ describe("Search filter tests", () => {
cy.wait("@edit_list");

// check content of table
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 39 of 39");
verifiyPaginationText("1 - 39 of 39");
cy.get(".MuiDataGrid-row").contains("Darion Rowe").should("exist");
});

Expand All @@ -151,7 +152,7 @@ describe("Search filter tests", () => {
filterByOriginalLithology();
cy.wait("@edit_list");
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 21 of 21");
verifiyPaginationText("1 - 21 of 21");
});
it("filters boreholes by creation date", () => {
loginAsAdmin();
Expand Down Expand Up @@ -179,8 +180,9 @@ describe("Search filter tests", () => {

// check content of table
cy.get('[data-cy="showTableButton"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 3 of 3");
verifiyPaginationText("1 - 3 of 3");
});

it("filters boreholes by workgroup", () => {
loginAsAdmin();
cy.visit("/");
Expand Down
29 changes: 29 additions & 0 deletions src/client/cypress/e2e/helpers/dataGridHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const verifiyPaginationText = text => {
cy.get(".MuiTablePagination-displayedRows").should("have.text", text);
};

export const sortBy = headerTextContent => {
cy.get(".MuiDataGrid-columnHeader").contains(headerTextContent).click();
cy.wait("@edit_list");
cy.get(".loading-indicator").should("not.exist");
};

export const verifyRowContains = (rowContent, rowIndex) => {
cy.get(".MuiDataGrid-row")
.eq(rowIndex)
.within(() => {
cy.contains(rowContent).should("exist");
});
};

export const waitForTableData = () => {
cy.wait("@edit_list");
cy.get(".MuiDataGrid-root").should("be.visible");
cy.get(".loading-indicator").should("not.exist");
cy.get(".MuiDataGrid-row").should("have.length.greaterThan", 0);
};

export const showTableAndWaitForData = () => {
cy.get('[data-cy="showTableButton"]').click();
waitForTableData();
};
7 changes: 2 additions & 5 deletions src/client/cypress/e2e/viewer/viewer.cy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { loginAsAdmin, loginAsViewer } from "../helpers/testHelpers";
import { showTableAndWaitForData } from "../helpers/dataGridHelpers";

describe("Viewer tests", () => {
it("Assures viewer cannot add, edit or delete boreholes", () => {
loginAsViewer();
cy.visit("/");

cy.get('[data-cy="showTableButton"]').click();
cy.wait("@edit_list");
cy.get("div[id=map]").should("be.visible");
cy.get(".MuiDataGrid-root").should("be.visible");
cy.get(".MuiDataGrid-row").should("have.length.greaterThan", 0);
showTableAndWaitForData();

cy.get('[data-cy="import-borehole-button"]').should("have.class", "Mui-disabled");
cy.get('[data-cy="new-borehole-button"]').should("have.class", "Mui-disabled");
Expand Down

0 comments on commit e2e5cf3

Please sign in to comment.