Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ export default defineConfig({
e2e: {
redirectionLimit: 50,
setupNodeEvents(on, config) {
// implement node event listeners here
on("task", {
log(message) {
console.log(message);
return null;
},
});
return config;
},
},
});

97 changes: 50 additions & 47 deletions cypress/e2e/functionality/06-tables-and-wizard.cy.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
import { goodPassword, goodUser } from "../../support/constants";

describe('Another Test Suite', () => {
beforeEach(() => {
cy.loginAndGoTo(goodUser, goodPassword, 'http://localhost:3000/table');
cy.location("pathname").should("include", "/table");
});
describe("Creating Tables using the Wizard", () => {
beforeEach(() => {
cy.loginAndGoTo(goodUser, goodPassword, "http://localhost:3000/table");
cy.location("pathname").should("include", "/table");
});

context("Basic Add/Delete tests", () => {
// Skipped test: known issue where error not appearing for invalid shorname.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor spelling mistake in comment: "shorname".

it.skip("should fail to save new table with invalid shortname", () => {
cy.get('[data-target="#newTableModal"]').click();
cy.get("#shortName").type("This value wont $4v£");
cy.get("#name").type("table to fail");
cy.get(".btn-js-next").first().click();
cy.get(".btn-js-save").first().click();

//attempt save with incorrect (fails)
it.skip('should fail to save new table with invalid shortname ', () => {
cy.get('[data-target="#newTableModal"]').click();
cy.get('#shortName').type('This value wont $4v£');
cy.get("#name").type("table to fail");
cy.get('.btn-js-next').eq(0).click();
cy.get('.btn-js-save').eq(0).click();
cy.get('div.alert.alert-danger')
.should('be.visible')
.and('contain', 'Invalid short name for table');
// Check for failed save error
cy.get("div.alert.alert-danger")
.should("be.visible")
.and("contain", "Invalid short name for table");
});

it('should save a new table successfully', () => {
cy.get('[data-target="#newTableModal"]').click();
cy.get('#shortName').type('1-test_table');
cy.get("#name").type("1-test-table");
cy.get('.btn-js-next').eq(0).click();
cy.get('.btn-js-save').eq(0).click();
cy.location("pathname").should("include", "/table");
cy.contains('1-test-table').should('exist');
it("should save a new empty table successfully", () => {
cy.createInstance("1-test-table");

// Check new table is displayed on table page
cy.location("pathname").should("include", "/table");
cy.contains("1-test-table").should("exist");
});

it("should make the new table accessible", () => {
// Check table edit page is accessible
cy.contains("tr", "1-test-table")
.contains("a", "Edit table")
.click();

it('table is accessible', () => {
cy.contains('tr', '1-test-table')
.contains('a', 'Edit table')
.click();
cy.location("pathname").should("include", "1-test_table/edit");
cy.location("pathname").should("include", "1-test-table/edit");
});

it('table can be deleted', () => {
cy.visit('http://localhost:3000/1-test_table/edit');
cy.location("pathname").should("include", "1-test_table/edit");
cy.contains('button', 'Delete table').click();
cy.get('.modal-dialog').within(() => {
cy.contains('h3.modal-title', 'Delete - 1-test-table').should('exist');
});
cy.get('.modal-footer__right').contains('button', 'Delete').click();
cy.location("pathname").should("include", "/table");
cy.contains('.alert.alert-success', 'The table has been deleted successfully').should('exist');
cy.contains('1-test-table').should('not.exist');
it("should delete the table successfully", () => {
cy.deleteInstanceByShortName("1-test-table");

// Check table no longer appears on table page
cy.location("pathname").should("include", "/table");
cy.contains(
".alert.alert-success",
"The table has been deleted successfully"
).should("exist");
cy.contains("1-test-table").should("not.exist");
});

it('Deleted table no longer accessible', () => {
cy.request({
url: 'http://localhost:3000/1-test_table/edit',
failOnStatusCode: false // Prevent Cypress from failing the test on non-2xx status codes
}).then((response) => {
// Check if the response status is either 302 or 404
expect(response.status).to.be.oneOf([302, 404]);
});
it("should confirm deleted table is no longer accessible", () => {
// Attempt to access the deleted table URL directly
cy.request({
url: "http://localhost:3000/1-test-table/edit",
failOnStatusCode: false, // Prevent Cypress from failing on 404/302
}).then((response) => {
expect(response.status).to.be.oneOf([302, 404]);
});
});
});
});

7 changes: 7 additions & 0 deletions cypress/e2e/functionality/07-layouts.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { goodPassword, goodUser } from "../../support/constants";

describe("Layout creation tests", () => {
const refShortName = "tr";

before(() => {
cy.log("login").login(goodUser, goodPassword);
cy.log("update user groups").addUserToDefaultGroup("test@example.com", "check");
cy.logout();
});


beforeEach(() => {
cy.login(goodUser, goodPassword);
Expand Down
66 changes: 0 additions & 66 deletions cypress/e2e/functionality/08-data-view.cy.ts

This file was deleted.

165 changes: 165 additions & 0 deletions cypress/e2e/functionality/08-set-table-permissions.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { goodPassword, goodUser } from "../../support/constants";

describe("Layout creation tests", () => {
const table_shortname = "table1";

before(() => {
cy.login(goodUser, goodPassword);
cy.log("update user groups").addUserToDefaultGroup("test@example.com", "check");
cy.logout();
});

beforeEach(() => {
cy.login(goodUser, goodPassword);
});

after(() => {
// Clear permissions and reset user group
cy.clearAllTablePermissions("table1");
cy.addUserToDefaultGroup("test@example.com", "uncheck");
});


// Set individual table permissions
context("Set individual permissions", () => {
[
"Bulk import record",
"Purge deleted records",
"Download records",
"Delete records",
"Bulk update records",
"Bulk delete records",
"Manage linked records",
"Manage child records",
"Manage views",
"Manage group views",
"Select extra view limits",
"Manage fields",
"Send messages",
].forEach((permissionName) => {
it(`should set ${permissionName} for table: ${table_shortname}`, () => {
cy.setTablePermissionsByShortName(table_shortname, {
[permissionName]: true,
});
});
});
});

// Check Manage Views dropdown visibility and options
context("Check view options are available", () => {
it("should navigate to data page and click the Manage views dropdown", () => {
cy.visit(`http://localhost:3000/${table_shortname}/data`);

cy.get("button#manage_views")
.should("be.visible")
.and("contain", "Manage views")
.click();

cy.get(".dropdown__list").first().within(() => {
cy.contains("a", "Add a view").should("be.visible");
cy.contains("a", "Manage views of another user").should("be.visible");
cy.contains("a", "Historic view").should("be.visible");
});
});
});

// Check Actions dropdown visibility and options
context("Check view options are available", () => {
it("should navigate to data page and click the Actions dropdown", () => {
cy.visit(`http://localhost:3000/${table_shortname}/data`);

cy.get("span")
.contains("Actions")
.should("be.visible")
.click();

cy.get('.dropdown-menu.dropdown__menu.show .dropdown__list').within(() => {

//commented out the following because they require records in the table to appear
//cy.contains("a", "Download records").should("be.visible");
//cy.contains("a", "Field Data Purge").should("be.visible");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these commented out lines above needed if not used?


//know issue: purge options dont display unless there is live records in the table
//cy.contains("a", "Field Data Purge").should("be.visible");
//cy.contains("a", "Manage deleted records").should("be.visible");

cy.contains('a', 'Import records').should('be.visible');
cy.contains('a', 'Delete all records in this view').should('be.visible');
cy.contains("a", "Update all records in this view").should("be.visible");
cy.contains("a", "Clone all records in this view").should("be.visible");
});
});
});

// Ensure related endpoints load successfully
context("Check related endpoints are accessible", () => {
const urls = [
`/historic_purge/`,
`/purge/`,
`/bulk/clone/`,
`/bulk/update/`,
`/import/`,
`/view/0`,
];

urls.forEach((path) => {
it(`should successfully load ${path}`, () => {
cy.visit(`http://localhost:3000/${table_shortname}${path}`);

// Basic sanity check: body exists and is not empty
cy.get("body").should("exist").and("not.be.empty");
});
});
});

// Clear permissions
context("Clear all table permissions", () => {
it(`Should clear all permissions for ${table_shortname}`, () => {
cy.clearAllTablePermissions(table_shortname);
});
});

// Verify that restricted UI elements are gone
context("Ensure both dropdown lists are no longer present", () => {
it("Ensure the Actions dropdown does not exist on the page", () => {
cy.visit(`http://localhost:3000/${table_shortname}/data`);

cy.get("span")
.contains("Actions")
.should("not.exist");
});

it("Ensure the manage views dropdown does not exist on the page", () => {
cy.visit(`http://localhost:3000/${table_shortname}/data`);

cy.get("span")
.contains("manage_views")
.should("not.exist");
});
});

// Check endpoints after permissions are cleared
context("Check restricted endpoints show permission error", () => {
const urls = [
`/historic_purge/`,
`/purge/`,
`/bulk/clone/`,
`/bulk/update/`,
`/import/`,
// `/view/0`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this commented code needed?
If there is an issue, maybe it could be stated why for clarity.

];

urls.forEach((path) => {
it(`should block access to ${path}`, () => {
cy.visit(`http://localhost:3000/${table_shortname}${path}`, {
failOnStatusCode: false,
});

cy.get('div.alert.alert-danger[role="alert"]')
.should("be.visible")
.and("contain.text", "You do not have permission to");
});
});
});
});

Loading
Loading