Skip to content

Commit

Permalink
Various improvements regarding cypress tests #132
Browse files Browse the repository at this point in the history
  • Loading branch information
danjov authored Oct 24, 2022
2 parents 777e33b + 0ec6fe5 commit 649f91f
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
wait-on-timeout: 120
working-directory: ./src/client
env:
REACT_APP_VERSION: 0.1.99+cypress
REACT_APP_VERSION: 0.0.99+dev
16 changes: 7 additions & 9 deletions src/client/cypress/e2e/admin/aboutSettings.cy.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { interceptApiCalls } from "../testHelpers";
import { login } from "../testHelpers";
import license from "../../fixtures/license.json";

describe("Admin about page tests", () => {
beforeEach(() => {
interceptApiCalls();
cy.visit("/setting/about");
cy.contains("button", "Login").click();
});

it("shows version information linking the corresponding release on GitHub.", () => {
login("/setting/about");

cy.get('[data-cy="version"]')
.should("contain", "0.1.99+cypress")
.should("contain", "0.0.99+dev")
.should(
"have.attr",
"href",
"https://github.com/geoadmin/suite-bdms/releases/tag/v0.1.99",
"https://github.com/geoadmin/suite-bdms/releases/tag/v0.0.99",
);
});

it("shows license information (with fixtures)", () => {
cy.intercept("/license.json", license);
login("/setting/about");

cy.get('[data-cy^="credits-"]').should("have.length", 2);
cy.get('[data-cy="[email protected]"]').should(
Expand All @@ -33,6 +30,7 @@ describe("Admin about page tests", () => {
});

it("shows license information (without fixtures)", () => {
login("/setting/about");
cy.get('[data-cy^="credits-"]').should("have.length.above", 0);
});
});
12 changes: 3 additions & 9 deletions src/client/cypress/e2e/admin/userAdministration.cy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { interceptApiCalls } from "../testHelpers";
import { interceptApiCalls, login } from "../testHelpers";

describe("Admin settings test", () => {
it("displays correct message when enabling user.", () => {
interceptApiCalls();

// login
cy.visit("/setting/admin");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
login("/setting/admin");

cy.get('[data-cy="user-list-table-body"]')
.children()
Expand Down Expand Up @@ -75,10 +72,7 @@ describe("Admin settings test", () => {
it("can add user with admin role.", () => {
interceptApiCalls();

// login
cy.visit("/setting/admin");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
login("/setting/admin");

cy.get('[data-cy="user-list-table-body"]')
.children()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import editorUser from "../fixtures/editorUser.json";
import adminUser from "../fixtures/adminUser.json";
import { loginAsAdmin, loginAsEditor } from "../e2e/testHelpers";

describe("Bore hole list tests", () => {
describe("Borehole list tests", () => {
it("Boreholes are displayed in correct order with editor login", () => {
// Login as editor
cy.intercept("/api/v1/geoapi/canton").as("geoapi");
cy.intercept("/api/v1/borehole").as("borehole");
loginAsEditor();

cy.intercept("/api/v1/user", editorUser);

cy.visit("/");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
cy.get("div[id=map]").should("be.visible");

cy.get("tbody").children().should("have.length", 27);
Expand Down Expand Up @@ -94,7 +87,7 @@ describe("Bore hole list tests", () => {
secondRow.contains("td", "09.11.2021");
thirdRow.contains("td", "12.10.2021");

// sort by bore hole type (column of original name)
// sort by borehole type (column of original name)
cy.contains("div", "Borehole type").click();
cy.wait("@borehole");
firstRow = cy.get("tbody").children().first();
Expand All @@ -107,14 +100,7 @@ describe("Bore hole list tests", () => {
});

it("Boreholes are displayed in correct order with admin login", () => {
// Login as admin
cy.intercept("/api/v1/geoapi/canton").as("geoapi");

cy.intercept("/api/v1/user", adminUser);

cy.visit("/editor");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
loginAsAdmin("/editor");
cy.get("div[id=map]").should("be.visible");

// sort by creation date
Expand Down
25 changes: 4 additions & 21 deletions src/client/cypress/e2e/codeList.cy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import adminUser from "../fixtures/adminUser.json";
import editorUser from "../fixtures/editorUser.json";
import { loginAsAdmin, loginAsEditor } from "../e2e/testHelpers";

describe("Codelist translations tests", () => {
it("Admin can open codelist translation section", () => {
// Login and navigate to editor settings
cy.intercept("/api/v1/geoapi/canton").as("geoapi");
cy.intercept("/api/v1/user", adminUser);

cy.visit("/");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
loginAsAdmin();
cy.get("div[id=map]").should("be.visible");

cy.get("i[class='th big icon']").click();
Expand All @@ -27,12 +21,7 @@ describe("Codelist translations tests", () => {
});

it("Admin can edit translations", () => {
cy.intercept("/api/v1/geoapi/canton").as("geoapi");
cy.intercept("/api/v1/user", adminUser);

cy.visit("/");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
loginAsAdmin();
cy.get("div[id=map]").should("be.visible");

cy.get("i[class='th big icon']").click();
Expand Down Expand Up @@ -101,13 +90,7 @@ describe("Codelist translations tests", () => {
});

it("Editor cannot open codelist translation section", () => {
// login as editor
cy.intercept("/api/v1/geoapi/canton").as("geoapi");
cy.intercept("/api/v1/user", editorUser);

cy.visit("/");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
loginAsEditor();
cy.get("div[id=map]").should("be.visible");

cy.get("i[class='th big icon']").click();
Expand Down
8 changes: 2 additions & 6 deletions src/client/cypress/e2e/editor/bulkedit.cy.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { createBorehole, deleteBorehole } from "../testHelpers";
import { createBorehole, deleteBorehole, login } from "../testHelpers";

describe("Test the borehole bulk edit feature.", () => {
beforeEach(() => {
cy.intercept("/api/v1/geoapi/canton").as("geoapi");
cy.intercept("/api/v1/borehole").as("borehole");
cy.intercept("/api/v1/borehole/edit", req => {
return (req.alias = `edit_${req.body.action.toLowerCase()}`);
});

// login
cy.visit("/editor");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
login("/editor");
});

it("opens the bulk edit dialog with all boreholes selected", () => {
Expand Down
6 changes: 2 additions & 4 deletions src/client/cypress/e2e/editor/emptyMessages.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import {
interceptApiCalls,
newUneditableBorehole,
deleteBorehole,
login,
} from "../testHelpers";

describe("Messages for empty profiles", () => {
beforeEach(() => {
interceptApiCalls();

cy.visit("/editor");
cy.contains("button", "Login").click();
cy.wait("@geoapi");

login("/editor");
newUneditableBorehole();
});

Expand Down
6 changes: 2 additions & 4 deletions src/client/cypress/e2e/editor/instrumentation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import {
interceptApiCalls,
newUneditableBorehole,
deleteBorehole,
login,
} from "../testHelpers";

describe("Instrumentation tests", () => {
beforeEach(() => {
interceptApiCalls();

// login
cy.visit("/editor");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
login("/editor");

newUneditableBorehole().as("borehole_id");
cy.get('[data-cy="completion-menu-item"]').click();
Expand Down
6 changes: 2 additions & 4 deletions src/client/cypress/e2e/editor/location.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import {
deleteBorehole,
interceptApiCalls,
newEditableBorehole,
login,
} from "../testHelpers";

describe("Tests for 'Location' edit page.", () => {
beforeEach(() => {
interceptApiCalls();

// login
cy.visit("/");
cy.contains("button", "Login").click();
cy.wait("@geoapi");
login();

// go to edit
cy.get('[data-cy="menu"]').click();
Expand Down
8 changes: 3 additions & 5 deletions src/client/cypress/e2e/filter.cy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { login } from "../e2e/testHelpers";

describe("Search filter tests", () => {
beforeEach(() => {
cy.intercept("/api/v1/geoapi/canton").as("geoapi");

cy.visit("/");
cy.contains("button", "Enter as viewer").click();
cy.wait("@geoapi");
login();
});

it("has search filters", () => {
Expand Down
33 changes: 32 additions & 1 deletion src/client/cypress/e2e/testHelpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import adminUser from "../fixtures/adminUser.json";
import editorUser from "../fixtures/editorUser.json";

const adminUserAuth = {
user: "admin",
password: "swissforages",
};

export const interceptApiCalls = () => {
cy.intercept("/api/v1/geoapi/canton").as("geoapi");
cy.intercept("/api/v1/borehole").as("borehole");
cy.intercept("/api/v1/borehole/profile/layer").as("layer");
cy.intercept("/api/v1/borehole/edit", req => {
Expand All @@ -18,6 +20,35 @@ export const interceptApiCalls = () => {
});
};

/**
* Login into the application with the pre-filled user for the development environment.
* @param {string} visitUrl The url to visit after logging in. Default is the root path.
*/
export const login = (visitUrl = "/") => {
cy.intercept("/api/v1/geoapi/canton").as("geoapi");
cy.visit(visitUrl);
cy.contains("button", "Login").click();
cy.wait("@geoapi");
};

/**
* Login into the application as admin.
* @param {string} visitUrl The url to visit after logging in. Default is the root path.
*/
export const loginAsAdmin = (visitUrl = "/") => {
cy.intercept("/api/v1/user", adminUser);
login(visitUrl);
};

/**
* Login into the application as editor.
* @param {string} visitUrl The url to visit after logging in. Default is the root path.
*/
export const loginAsEditor = (visitUrl = "/") => {
cy.intercept("/api/v1/user", editorUser);
login(visitUrl);
};

export const newEditableBorehole = () => {
const id = newUneditableBorehole();
cy.contains("a", "Start editing").click();
Expand Down

0 comments on commit 649f91f

Please sign in to comment.