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 e2e5cf3 commit 55d62d4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 35 deletions.
19 changes: 7 additions & 12 deletions src/client/cypress/e2e/editor/bulkedit.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBorehole, loginAsAdmin, startBoreholeEditing, stopBoreholeEditing } from "../helpers/testHelpers";
import adminUser from "../../fixtures/adminUser.json";
import { showTableAndWaitForData } from "../helpers/dataGridHelpers";
import { checkAllVisibleRows, checkRowWithText, showTableAndWaitForData } from "../helpers/dataGridHelpers";

beforeEach(() => {
loginAsAdmin();
Expand All @@ -10,13 +10,13 @@ beforeEach(() => {

describe("Test the borehole bulk edit feature.", () => {
it("opens the bulk edit dialog with all boreholes selected", () => {
cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").find('input[type="checkbox"]').check({ force: true });
checkAllVisibleRows();
cy.contains("button", "Bulk editing").click({ force: true });
cy.get(".ui .header").should("have.text", "Bulk modification");
});

it("checks if all toggle buttons do something", () => {
cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").find('input[type="checkbox"]').check({ force: true });
checkAllVisibleRows();
cy.contains("button", "Bulk editing").click({ force: true });
cy.get(".modal .toggle")
.should("have.length", 18)
Expand All @@ -29,7 +29,7 @@ describe("Test the borehole bulk edit feature.", () => {
});

it("displays workgroup toggle only if user has permission for more than one workgroup", () => {
cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").find('input[type="checkbox"]').check({ force: true });
checkAllVisibleRows();
cy.contains("button", "Bulk editing").click({ force: true });
cy.get(".modal .toggle").should("have.length", 18);

Expand All @@ -48,7 +48,7 @@ describe("Test the borehole bulk edit feature.", () => {
}).as("adminUser2Workgroups");
cy.visit("/");
showTableAndWaitForData();
cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").find('input[type="checkbox"]').check({ force: true });
checkAllVisibleRows();
cy.contains("button", "Bulk editing").click({ force: true });

cy.get(".modal .toggle").should("have.length", 19);
Expand All @@ -74,13 +74,8 @@ describe("Test the borehole bulk edit feature.", () => {

// select the boreholes for bulk edit
cy.get('[data-cy="borehole-table"]').within(() => {
cy.contains(".MuiDataGrid-row", "AAA_NINTIC")
.find('.MuiCheckbox-root input[type="checkbox"]')
.check({ force: true });

cy.contains(".MuiDataGrid-row", "AAA_LOMONE")
.find('.MuiCheckbox-root input[type="checkbox"]')
.check({ force: true });
checkRowWithText("AAA_NINTIC");
checkRowWithText("AAA_LOMONE");
});
cy.contains("button", "Bulk editing").click();

Expand Down
7 changes: 3 additions & 4 deletions src/client/cypress/e2e/editor/location.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newEditableBorehole, returnToOverview, stopBoreholeEditing } from "../helpers/testHelpers";
import { showTableAndWaitForData } from "../helpers/dataGridHelpers";
import { checkRowWithText, showTableAndWaitForData } from "../helpers/dataGridHelpers";

describe("Tests for 'Location' edit page.", () => {
it("creates and deletes a borehole.", () => {
Expand All @@ -16,10 +16,9 @@ describe("Tests for 'Location' edit page.", () => {

// search the newly created borehole and delete it
cy.get('[data-cy="borehole-table"]').within(() => {
cy.contains(".MuiDataGrid-row", "AAA_SCATORPS")
.find('.MuiCheckbox-root input[type="checkbox"]')
.check({ force: true });
checkRowWithText("AAA_SCATORPS");
});

cy.get('[data-cy="delete-button"]').click();
cy.get('.MuiButton-containedPrimary[data-cy="delete-button"]').click();
cy.wait(["@edit_deletelist", "@edit_list"]);
Expand Down
12 changes: 6 additions & 6 deletions src/client/cypress/e2e/filters/filter.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loginAsAdmin } from "../helpers/testHelpers.js";
import { verifiyPaginationText } from "../helpers/dataGridHelpers";
import { showTableAndWaitForData, verifiyPaginationText } from "../helpers/dataGridHelpers";

describe("Search filter tests", () => {
it("has search filters", () => {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe("Search filter tests", () => {
cy.wait("@edit_list");

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

Expand All @@ -116,7 +116,7 @@ describe("Search filter tests", () => {
});

cy.wait("@edit_list");
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();
verifiyPaginationText("1 - 100 of 229");

let uscs3Dropdown = cy.contains("label", "USCS 3").next();
Expand Down Expand Up @@ -151,7 +151,7 @@ describe("Search filter tests", () => {
cy.get('[data-cy="show-filter-button"]').click();
filterByOriginalLithology();
cy.wait("@edit_list");
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();
verifiyPaginationText("1 - 21 of 21");
});
it("filters boreholes by creation date", () => {
Expand Down Expand Up @@ -179,15 +179,15 @@ describe("Search filter tests", () => {
cy.wait("@edit_list");

// check content of table
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();
verifiyPaginationText("1 - 3 of 3");
});

it("filters boreholes by workgroup", () => {
loginAsAdmin();
cy.visit("/");
cy.get('[data-cy="show-filter-button"]').click();
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();
cy.contains("Workgroup").click();
cy.contains("Name").click();
cy.wait("@borehole");
Expand Down
12 changes: 6 additions & 6 deletions src/client/cypress/e2e/filters/identifierFilter.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { newEditableBorehole, returnToOverview, stopBoreholeEditing } from "../helpers/testHelpers.js";
import { checkAllVisibleRows, verifiyPaginationText } from "../helpers/dataGridHelpers";

describe("Tests for filtering data by identifier.", () => {
it("can filter by identifier", () => {
Expand All @@ -20,7 +21,7 @@ describe("Tests for filtering data by identifier.", () => {
// show all options
cy.get('[class="ui fitted toggle checkbox"]').eq(0).children().first().check({ force: true });

cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 1627"); // when testing with cypress locally use electron browser, otherwise text might be displayed as "1-100 of 1627"
verifiyPaginationText("1 - 100 of 1627"); // when testing with cypress locally use electron browser, otherwise text might be displayed as "1-100 of 1627"

cy.get('[data-cy="domain-dropdown"]')
.first()
Expand All @@ -29,10 +30,10 @@ describe("Tests for filtering data by identifier.", () => {
.eq(1)
.click({ force: true });

cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 1 of 1");
verifiyPaginationText("1 - 1 of 1");
// click reset label
cy.get('[data-cy="reset-filter-button"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 1627");
verifiyPaginationText("1 - 100 of 1627");
});

it("can bulk edit boreholes while filter by identifier is set", () => {
Expand Down Expand Up @@ -73,9 +74,8 @@ describe("Tests for filtering data by identifier.", () => {
.find('[role="option"]')
.eq(1)
.click({ force: true });
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 2 of 2");

cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").find('input[type="checkbox"]').check({ force: true });
verifiyPaginationText("1 - 2 of 2");
checkAllVisibleRows();
cy.contains("button", "Bulk editing").click({ force: true });

// Bulk edit dialog should open.
Expand Down
9 changes: 5 additions & 4 deletions src/client/cypress/e2e/filters/srsFilter.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { loginAsAdmin, newEditableBorehole, returnToOverview, stopBoreholeEditing } from "../helpers/testHelpers.js";
import { verifiyPaginationText } from "../helpers/dataGridHelpers";

describe("Tests for filtering data by reference system.", () => {
function goToEditorLocationFilter() {
Expand Down Expand Up @@ -50,18 +51,18 @@ describe("Tests for filtering data by reference system.", () => {
cy.contains("h6", "Location").click();
cy.get('[class="ui fitted toggle checkbox"]').eq(0).children().first().check({ force: true });
cy.get('[data-cy="radiobutton-all"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 1627"); // when testing with cypress locally use electron browser, otherwise text might be displayed as "1-100 of 1627"
verifiyPaginationText("1 - 100 of 1627"); // when testing with cypress locally use electron browser, otherwise text might be displayed as "1-100 of 1627"

cy.get('[data-cy="spatial-reference-filter"]').should("exist");

cy.get('[data-cy="radiobutton-LV95"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 813");
verifiyPaginationText("1 - 100 of 813");

cy.get('[data-cy="radiobutton-LV03"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 814");
verifiyPaginationText("1 - 100 of 814");

// click reset label
cy.get('[data-cy="reset-filter-button"]').click();
cy.get(".MuiTablePagination-displayedRows").should("have.text", "1 - 100 of 1627");
verifiyPaginationText("1 - 100 of 1627");
});
});
12 changes: 12 additions & 0 deletions src/client/cypress/e2e/helpers/dataGridHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ export const showTableAndWaitForData = () => {
cy.get('[data-cy="showTableButton"]').click();
waitForTableData();
};

export const checkAllVisibleRows = () => {
cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").find('input[type="checkbox"]').check({ force: true });
};

export const checkRowWithText = text => {
cy.contains(".MuiDataGrid-row", text).find('.MuiCheckbox-root input[type="checkbox"]').check({ force: true });
};

export const clickOnRowWithText = text => {
cy.contains(".MuiDataGrid-row", text).click();
};
6 changes: 3 additions & 3 deletions src/client/cypress/e2e/viewer/viewer.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loginAsAdmin, loginAsViewer } from "../helpers/testHelpers";
import { showTableAndWaitForData } from "../helpers/dataGridHelpers";
import { clickOnRowWithText, showTableAndWaitForData } from "../helpers/dataGridHelpers";

describe("Viewer tests", () => {
it("Assures viewer cannot add, edit or delete boreholes", () => {
Expand All @@ -12,7 +12,7 @@ describe("Viewer tests", () => {
cy.get('[data-cy="new-borehole-button"]').should("have.class", "Mui-disabled");

// click on borehole
cy.contains(".MuiDataGrid-row", "Aaron Rempel").click();
clickOnRowWithText("Aaron Rempel");
// verify all text inputs are readonly on Location tab
cy.get('input[type="text"]').each(i => {
cy.wrap(i).should("have.attr", "readonly");
Expand All @@ -31,7 +31,7 @@ describe("Viewer tests", () => {
it("Assures viewer cannot multiselect boreholes", () => {
loginAsAdmin();
cy.visit("/");
cy.get('[data-cy="showTableButton"]').click();
showTableAndWaitForData();
cy.wait("@edit_list");
cy.get(".MuiDataGrid-columnHeaderCheckbox .MuiCheckbox-root").should("be.visible");

Expand Down

0 comments on commit 55d62d4

Please sign in to comment.