-
Notifications
You must be signed in to change notification settings - Fork 9
Adds Cypress Axe and addition e2e tests #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
| 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]); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
This file was deleted.
| 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"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this commented code needed? |
||
| ]; | ||
|
|
||
| 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"); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
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".