Skip to content

Commit

Permalink
Implement OIDC lifecycle in cypress tests
Browse files Browse the repository at this point in the history
Remove some UI navigations
  • Loading branch information
Philippluca committed Dec 22, 2023
1 parent 5dfc8c7 commit 08d4359
Show file tree
Hide file tree
Showing 23 changed files with 380 additions and 309 deletions.
11 changes: 7 additions & 4 deletions src/client/cypress/e2e/admin/aboutSettings.cy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { login } from "../testHelpers";
import { loginAsAdmin } from "../testHelpers";
import license from "../../fixtures/license.json";

describe("Admin about page tests", () => {
it("shows version information linking the corresponding release on GitHub.", () => {
login("/setting/about");
loginAsAdmin();
cy.visit("/setting/about");

cy.get('[data-cy="version"]')
.should("contain", "0.0.99+dev")
Expand All @@ -16,7 +17,8 @@ describe("Admin about page tests", () => {

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

cy.get('[data-cy^="credits-"]').should("have.length", 2);
cy.get('[data-cy="credits-example-js@0.0.999"]').should(
Expand All @@ -30,7 +32,8 @@ describe("Admin about page tests", () => {
});

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

describe("Admin login preview tests", () => {
it("displays correct message when publishing a new welcome message.", () => {
login("/setting/login");
loginAsAdmin();
cy.visit("/setting/login");

// Initial button state
cy.get('[data-cy="save-welcome-message-button"]').should("not.be.visible");
Expand Down
3 changes: 2 additions & 1 deletion src/client/cypress/e2e/admin/userAdministration.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { loginAsAdmin } from "../testHelpers";

describe("Admin settings test", () => {
beforeEach(() => {
loginAsAdmin("/setting/admin");
loginAsAdmin();
cy.visit("/setting/admin");

cy.get('[data-cy="user-list-table-body"]')
.children()
Expand Down
3 changes: 3 additions & 0 deletions src/client/cypress/e2e/app.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loginAsAdmin, loginAsEditorInViewerMode } from "./testHelpers";
describe("General app tests", () => {
it("Displays the login page in the correct language", () => {
// default is english
cy.session("logged out", () => cy.visit("/"));
cy.visit("/");
cy.contains("Sign in");
cy.contains("Welcome to");
Expand All @@ -25,12 +26,14 @@ describe("General app tests", () => {

it("Displays the current host as app title", () => {
loginAsEditorInViewerMode();
cy.visit("/");
cy.get('[data-cy="app-title"]').contains("localhost");
});

it("Correctly navigates back and forth from settings", () => {
// correctly navigate back to viewer mode
loginAsAdmin();
cy.visit("/");
cy.get('[data-cy="menu"]').click();
cy.get('[data-cy="settings-list-item"]').click();
cy.contains("h3", "Done").click();
Expand Down
5 changes: 4 additions & 1 deletion src/client/cypress/e2e/boreholeList.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe("Borehole list tests", () => {
it("Boreholes are displayed in correct order with editor login", () => {
cy.intercept("/api/v1/borehole").as("borehole");
loginAsEditorInViewerMode();
cy.visit("/");

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

Expand Down Expand Up @@ -80,7 +81,8 @@ describe("Borehole list tests", () => {
it("Boreholes are displayed in correct order with admin login", () => {
cy.intercept("/api/v1/borehole").as("borehole");
cy.intercept("/api/v1/borehole/edit").as("editorBorehole");
loginAsAdmin("/editor");
loginAsAdmin();
cy.visit("/editor");

cy.wait("@editorBorehole");
cy.get("div[id=map]").should("be.visible");
Expand Down Expand Up @@ -173,6 +175,7 @@ describe("Borehole list tests", () => {

it("preserves column sorting and active page when navigating", () => {
loginAsEditorInViewerMode();
cy.visit("/");

// sort by name ascending
cy.contains("div", "Original name")
Expand Down
23 changes: 4 additions & 19 deletions src/client/cypress/e2e/codeList.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ describe("Codelist translations tests", () => {
it("Admin can open codelist translation section", () => {
// Login and navigate to editor settings
loginAsAdmin();
cy.get("div[id=map]").should("be.visible");
cy.visit("/setting/editor");

cy.get("i[class='th big icon']").click();
cy.contains("h4", "Settings").click();
cy.contains("h3", "Editor").click();
cy.get("button").should("not.contain", "Collapse");

cy.contains("div", "Codelist translations")
Expand All @@ -22,11 +19,7 @@ describe("Codelist translations tests", () => {

it("Admin can edit translations", () => {
loginAsAdmin();
cy.get("div[id=map]").should("be.visible");

cy.get("i[class='th big icon']").click();
cy.contains("h4", "Settings").click();
cy.contains("h3", "Editor").click();
cy.visit("/setting/editor");
cy.contains("div", "Codelist translations")
.parent("div")
.children("div")
Expand Down Expand Up @@ -88,22 +81,14 @@ describe("Codelist translations tests", () => {

it("Editor cannot open codelist translation section", () => {
loginAsEditorInViewerMode();
cy.get("div[id=map]").should("be.visible");

cy.get("i[class='th big icon']").click();
cy.contains("h4", "Settings").click();
cy.contains("h3", "Editor").click();
cy.visit("/setting/editor");
// Codelist translation section is not available
cy.get("div").should("not.contain", "Codelist translations");
});

it("Admin can edit order", () => {
loginAsAdmin();
cy.get("div[id=map]").should("be.visible");

cy.get("i[class='th big icon']").click();
cy.contains("h4", "Settings").click();
cy.contains("h3", "Editor").click();
cy.visit("/setting/editor");
cy.contains("div", "Codelist translations")
.parent("div")
.children("div")
Expand Down
5 changes: 3 additions & 2 deletions src/client/cypress/e2e/editor/boreholeEditorTable.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { login } from "../../e2e/testHelpers";
import { loginAsAdmin } from "../../e2e/testHelpers";

describe("Borehole editor table tests", () => {
it("preserves column sorting and active page when navigating", () => {
login("/editor");
loginAsAdmin();
cy.visit("/editor");

// sort by name ascending
cy.contains("th", "Original name").click();
Expand Down
77 changes: 26 additions & 51 deletions src/client/cypress/e2e/editor/bulkedit.cy.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,18 @@
import { createBorehole, login, adminUserAuth } from "../testHelpers";

export const changeWorkgroupRoleForUser = (
workgroupId,
userId,
role,
action,
) => {
return cy
.request({
method: "POST",
url: "/api/v1/user/workgroup/edit",
body: {
action: action,
id: workgroupId,
},
auth: adminUserAuth,
})
.then(res => {
expect(res.body).to.have.property("success", true);
cy.request({
method: "POST",
url: "/api/v1/user/workgroup/edit",
body: {
action: "SET",
user_id: userId,
workgroup_id: workgroupId,
role_name: role,
active: action === "ENABLE" ? true : false,
},
auth: adminUserAuth,
}).then(res => {
expect(res.body).to.have.property("success", true);
cy.request({
method: "GET",
url: "/api/v2/user",
auth: adminUserAuth,
});
});
});
};
import { createBorehole, loginAsAdmin } from "../testHelpers";
import adminUser from "../../fixtures/adminUser.json";

describe("Test the borehole bulk edit feature.", () => {
it("opens the bulk edit dialog with all boreholes selected", () => {
login("/editor");
loginAsAdmin();
cy.visit("/editor");
cy.get('[data-cy="borehole-table"] thead .checkbox').click({ force: true });
cy.contains("button", "Bulk editing").click({ force: true });
cy.wait("@edit_ids");
});

it("checks if all toggle buttons do something", () => {
login("/editor");
loginAsAdmin();
cy.visit("/editor");
cy.get('[data-cy="borehole-table"] thead .checkbox').click({ force: true });
cy.contains("button", "Bulk editing").click({ force: true });

Expand All @@ -64,13 +27,26 @@ describe("Test the borehole bulk edit feature.", () => {
});

it("displays workgroup toggle only if user has permission for more than one workgroup", () => {
login("/editor");
loginAsAdmin();
cy.visit("/editor");
cy.get('[data-cy="borehole-table"] thead .checkbox').click({ force: true });
cy.contains("button", "Bulk editing").click({ force: true });

cy.get(".modal .toggle").should("have.length", 30);
changeWorkgroupRoleForUser(6, 1, "EDIT", "ENABLE");
login("/editor");

loginAsAdmin("admin");
const adminUser2Workgroups = Object.assign({}, adminUser);
adminUser2Workgroups.data.workgroups.push({
id: 6,
workgroup: "Blue",
roles: ["EDIT"],
disabled: null,
supplier: false,
});
cy.intercept("/api/v1/user", {
statusCode: 200,
body: JSON.stringify(adminUser2Workgroups),
}).as("adminUser2Workgroups");
cy.visit("/editor");
cy.get('[data-cy="borehole-table"] thead .checkbox').click({ force: true });
cy.contains("button", "Bulk editing").click({ force: true });

Expand All @@ -83,16 +59,15 @@ describe("Test the borehole bulk edit feature.", () => {
cy.wrap(el).scrollIntoView().click();
cy.get('.modal [role="option"]').eq(0).click({ force: true });
});
changeWorkgroupRoleForUser(6, 1, "EDIT", "DISABLE");
});

it("fills all bulkedit fields and saves.", () => {
login("/editor");

// create boreholes
createBorehole({ "extended.original_name": "NINTIC" }).as("borehole_id_1");
createBorehole({ "extended.original_name": "LOMONE" }).as("borehole_id_2");
cy.contains("a", "Refresh").click();

loginAsAdmin();
cy.visit("/editor");
cy.wait("@borehole");

// select the boreholes for bulk edit
Expand Down
45 changes: 24 additions & 21 deletions src/client/cypress/e2e/editor/chronostratigraphy.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
createBorehole,
createStratigraphy,
adminUserAuth,
login,
loginAsAdmin,
bearerAuth,
} from "../testHelpers";

describe("Tests for the chronostratigraphy editor.", () => {
Expand Down Expand Up @@ -49,31 +49,34 @@ describe("Tests for the chronostratigraphy editor.", () => {
],
};
Object.entries(layers).forEach(([key, value]) => {
value.forEach(layer => {
cy.request({
method: "POST",
url: "/api/v2/" + key,
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
body: {
stratigraphyId: response.body.id,
...layer,
},
auth: adminUserAuth,
}).then(response => {
expect(response).to.have.property("status", 200);
cy.get("@id_token").then(token => {
value.forEach(layer => {
cy.request({
method: "POST",
url: "/api/v2/" + key,
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
body: {
stratigraphyId: response.body.id,
...layer,
},
auth: bearerAuth(token),
}).then(response => {
expect(response).to.have.property("status", 200);
});
});
});
});
});

// open chronostratigraphy editor
cy.get("@borehole_id").then(id =>
login(`editor/${id}/stratigraphy/chronostratigraphy`),
);
cy.get("@borehole_id").then(id => {
loginAsAdmin();
cy.visit(`editor/${id}/stratigraphy/chronostratigraphy`);
});
cy.wait("@layer-by-profileId");

// start editing session
Expand Down
5 changes: 3 additions & 2 deletions src/client/cypress/e2e/editor/copyBorehole.cy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createBorehole, login } from "../testHelpers";
import { createBorehole, loginAsAdmin } from "../testHelpers";

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

loginAsAdmin();
cy.visit("/editor");
cy.get('[data-cy="borehole-table"] tbody')
.children()
.eq(1)
Expand Down
13 changes: 9 additions & 4 deletions src/client/cypress/e2e/editor/fieldMeasurement.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createBorehole, createStratigraphy, login } from "../testHelpers";
import {
createBorehole,
createStratigraphy,
loginAsAdmin,
} from "../testHelpers";

describe("Tests for the field measurement editor.", () => {
beforeEach(function () {
Expand All @@ -11,9 +15,10 @@ describe("Tests for the field measurement editor.", () => {
});

// open field measurement editor
cy.get("@borehole_id").then(id =>
login(`editor/${id}/hydrogeology/fieldmeasurement`),
);
cy.get("@borehole_id").then(id => {
loginAsAdmin();
cy.visit(`editor/${id}/hydrogeology/fieldmeasurement`);
});

// start editing session
cy.contains("a", "Start editing").click();
Expand Down
Loading

0 comments on commit 08d4359

Please sign in to comment.