|
1 | 1 | /// <reference types="cypress" /> |
2 | 2 | import { terminalLog, testLogin } from "./utils"; |
3 | 3 |
|
4 | | -beforeEach(() => { |
5 | | - testLogin("system-owner"); |
6 | | - cy.visit("/projects/1000"); |
7 | | - cy.get("h1", { timeout: 10000 }).should("be.visible"); |
8 | | -}); |
9 | | - |
10 | 4 | afterEach(() => { |
11 | 5 | cy.injectAxe(); |
12 | 6 | cy.checkA11y(null, null, terminalLog); |
13 | 7 | }); |
14 | 8 |
|
15 | 9 | describe("Project Details Page", () => { |
| 10 | + beforeEach(() => { |
| 11 | + testLogin("system-owner"); |
| 12 | + cy.visit("/projects/1000"); |
| 13 | + cy.get("h1", { timeout: 10000 }).should("be.visible"); |
| 14 | + }); |
| 15 | + |
16 | 16 | it("loads the seeded project details and disabled tab tooltips", () => { |
17 | 17 | cy.url().should("include", "/projects/1000"); |
18 | 18 | cy.get("h1").should("contain", "Human Services Interoperability Support"); |
@@ -41,4 +41,72 @@ describe("Project Details Page", () => { |
41 | 41 | cy.get("[data-cy='alternate-project-officers-tag']").should("contain", "Dave Director"); |
42 | 42 | cy.get("[data-cy='project-team-members-tag']").should("contain", "Amelia Popham"); |
43 | 43 | }); |
| 44 | + |
| 45 | + it("enters edit mode and displays the form", () => { |
| 46 | + cy.get("[data-cy='project-details-edit-button']").click(); |
| 47 | + cy.contains("h2", "Edit Project").should("be.visible"); |
| 48 | + cy.get("input[name='title']").should("be.visible"); |
| 49 | + cy.get("input[name='short_title']").should("be.visible"); |
| 50 | + cy.get("textarea[name='description']").should("be.visible"); |
| 51 | + cy.get("[data-cy='save-btn']").should("be.visible"); |
| 52 | + cy.get("[data-cy='cancel-button']").should("be.visible"); |
| 53 | + }); |
| 54 | + |
| 55 | + it("edits project details and saves successfully", () => { |
| 56 | + const originalShortTitle = "HSS"; |
| 57 | + const updatedShortTitle = `HSS-${Date.now()}`; |
| 58 | + cy.intercept("PATCH", "**/api/v1/projects/1000").as("patchProject"); |
| 59 | + |
| 60 | + cy.get("[data-cy='project-details-edit-button']").click(); |
| 61 | + cy.get("input[name='short_title']").clear().type(updatedShortTitle); |
| 62 | + cy.get("[data-cy='save-btn']").click(); |
| 63 | + |
| 64 | + cy.wait("@patchProject").then((interception) => { |
| 65 | + expect(interception.response.statusCode).to.equal(200); |
| 66 | + expect(interception.response.body.id).to.equal(1000); |
| 67 | + }); |
| 68 | + cy.contains("Project Updated").should("be.visible"); |
| 69 | + cy.get("[data-cy='project-nickname-tag']").should("contain", updatedShortTitle); |
| 70 | + |
| 71 | + // Restore the seeded short_title so later tests (and the seeded fixture assertions |
| 72 | + // above) keep passing when the spec reruns against the same database. |
| 73 | + cy.get("[data-cy='project-details-edit-button']").click(); |
| 74 | + cy.get("input[name='short_title']").clear().type(originalShortTitle); |
| 75 | + cy.get("[data-cy='save-btn']").click(); |
| 76 | + cy.wait("@patchProject").its("response.statusCode").should("equal", 200); |
| 77 | + }); |
| 78 | + |
| 79 | + it("shows an error alert when the save request fails", () => { |
| 80 | + cy.intercept("PATCH", "**/api/v1/projects/1000", { statusCode: 500, body: { error: "boom" } }).as( |
| 81 | + "patchProjectError" |
| 82 | + ); |
| 83 | + cy.get("[data-cy='project-details-edit-button']").click(); |
| 84 | + cy.get("input[name='short_title']").clear().type("Will Not Save"); |
| 85 | + cy.get("[data-cy='save-btn']").click(); |
| 86 | + cy.wait("@patchProjectError"); |
| 87 | + cy.contains("Error Updating Project").should("be.visible"); |
| 88 | + }); |
| 89 | + |
| 90 | + it("shows confirmation modal on cancel during edit", () => { |
| 91 | + cy.get("[data-cy='project-details-edit-button']").click(); |
| 92 | + cy.get("[data-cy='cancel-button']").click(); |
| 93 | + cy.contains("Are you sure you want to cancel editing").should("be.visible"); |
| 94 | + }); |
| 95 | +}); |
| 96 | + |
| 97 | +describe("Project Details Page — unauthorized user", () => { |
| 98 | + beforeEach(() => { |
| 99 | + testLogin("basic"); |
| 100 | + cy.visit("/projects/1000"); |
| 101 | + cy.get("h1", { timeout: 10000 }).should("be.visible"); |
| 102 | + }); |
| 103 | + |
| 104 | + it("disables the edit button when the user does not have permission", () => { |
| 105 | + cy.get("[data-cy='project-details-edit-button']").should("have.attr", "aria-disabled", "true"); |
| 106 | + cy.get("[data-cy='project-details-edit-button']").should( |
| 107 | + "have.attr", |
| 108 | + "aria-label", |
| 109 | + "You do not have permission to edit this project" |
| 110 | + ); |
| 111 | + }); |
44 | 112 | }); |
0 commit comments