diff --git a/teste2e/cypress/e2e/proposalEdit.js b/teste2e/cypress/e2e/proposalEdit.js index 3d7d484ea..9e55da837 100644 --- a/teste2e/cypress/e2e/proposalEdit.js +++ b/teste2e/cypress/e2e/proposalEdit.js @@ -17,70 +17,99 @@ describe("Proposal Edit", () => { // create proposal const proposal = buildProposal(); const { description: newDescription } = buildProposal(); - cy.createProposal(proposal).then((res) => { - cy.approveProposal(res.body.censorshiprecord); - cy.visit(`proposals/${res.body.censorshiprecord.token.substring(0, 7)}`); - // user is able to edit the proposal - cy.findByTestId(/record-edit-button/i).click(); - cy.findByRole("button", { name: /submit/i }).should("be.disabled"); - cy.findByTestId("text-area").type(newDescription); - cy.route("POST", "/api/v1/proposals/edit").as("editProposal"); - cy.findByRole("button", { name: /submit/i }).click(); - cy.wait("@editProposal", { timeout: 10000 }) - .its("status") - .should("eq", 200); - cy.findByText(/version 2/).should("exist"); - }); + cy.createProposal(proposal).then( + ({ + body: { + record: { censorshiprecord } + } + }) => { + cy.approveProposal(censorshiprecord); + cy.visit(`record/${censorshiprecord.token.substring(0, 7)}`); + // user is able to edit the proposal + cy.wait(1000); + cy.findByTestId(/record-edit-button/i).click(); + cy.findByRole("button", { name: /submit/i }).should("be.disabled"); + cy.findByTestId("text-area").type(newDescription); + cy.route("POST", "/api/records/v1/edit").as("editProposal"); + cy.findByRole("button", { name: /submit/i }).click(); + cy.wait("@editProposal", { timeout: 10000 }) + .its("status") + .should("eq", 200); + cy.findByText(/version 2/).should("exist"); + } + ); }); + it("Can't edit a proposal if not the owner", () => { // create proposal const proposal = buildProposal(); - cy.createProposal(proposal).then((res) => { - cy.approveProposal(res.body.censorshiprecord); - // logout - cy.logout(user); - // login paid user - const user1 = { - email: "user1@example.com", - username: "user1", - password: "password" - }; - cy.login(user1); - cy.identity(); - cy.visit(`proposals/${res.body.censorshiprecord.token.substring(0, 7)}`); - cy.findByTestId(/record-edit-button/i).should("not.exist"); - }); + cy.createProposal(proposal).then( + ({ + body: { + record: { censorshiprecord } + } + }) => { + cy.approveProposal(censorshiprecord); + // logout + cy.logout(user); + // login paid user + const user1 = { + email: "user1@example.com", + username: "user1", + password: "password" + }; + cy.login(user1); + cy.identity(); + cy.visit(`record/${censorshiprecord.token.substring(0, 7)}`); + cy.findByTestId(/record-edit-button/i).should("not.exist"); + } + ); }); + it("Can't edit an authorized voting proposal", () => { const proposal = buildProposal(); - cy.createProposal(proposal).then((res) => { - cy.approveProposal(res.body.censorshiprecord); - cy.visit(`proposals/${res.body.censorshiprecord.token.substring(0, 7)}`); - cy.route("POST", "api/v1/proposals/authorizevote").as("authorizeVote"); - cy.findByRole("button", { name: /authorize voting/i }).click(); - cy.findByRole("button", { name: /confirm/i }).click(); - cy.wait("@authorizeVote", { timeout: 3000 }) - .its("status") - .should("eq", 200); - cy.findByTestId(/close-confirm-msg/i).click(); - cy.findByTestId(/record-edit-button/i).should( - "have.css", - "pointer-events", - "none" - ); - }); + cy.createProposal(proposal).then( + ({ + body: { + record: { censorshiprecord } + } + }) => { + cy.approveProposal(censorshiprecord); + cy.visit(`record/${censorshiprecord.token.substring(0, 7)}`); + cy.route("POST", "api/ticketvote/v1/authorize").as("authorizeVote"); + cy.findByRole("button", { name: /authorize voting/i }).click(); + cy.findByRole("button", { name: /confirm/i }).click(); + cy.wait("@authorizeVote", { timeout: 3000 }) + .its("status") + .should("eq", 200); + cy.findByTestId(/close-confirm-msg/i).click(); + cy.findByTestId(/record-edit-button/i).should( + "have.css", + "pointer-events", + "none" + ); + } + ); }); + it("Can't edit without making any changes", () => { // create proposal const proposal = buildProposal(); - cy.createProposal(proposal).then((res) => { - cy.approveProposal(res.body.censorshiprecord); - cy.visit(`proposals/${res.body.censorshiprecord.token.substring(0, 7)}`); - cy.findByTestId(/record-edit-button/i).click(); - cy.findByRole("button", { name: /submit/i }).should("be.disabled"); - cy.findByTestId("proposal-name").type(`{selectAll}${proposal.name}`); - cy.findByTestId("text-area").type(`{selectAll}${proposal.description}`); - cy.findByRole("button", { name: /submit/i }).should("be.disabled"); - }); + cy.createProposal(proposal).then( + ({ + body: { + record: { censorshiprecord } + } + }) => { + cy.approveProposal(censorshiprecord); + cy.visit(`record/${censorshiprecord.token.substring(0, 7)}`); + cy.wait(1000); + cy.findByTestId(/record-edit-button/i).click(); + cy.findByRole("button", { name: /submit/i }).should("be.disabled"); + cy.findByTestId("proposal-name").type(`{selectAll}${proposal.name}`); + cy.findByTestId("text-area").type(`{selectAll}${proposal.description}`); + cy.findByRole("button", { name: /submit/i }).should("be.disabled"); + } + ); }); }); diff --git a/teste2e/cypress/support/commands.js b/teste2e/cypress/support/commands.js index 6a30b047c..6c5ca6c40 100644 --- a/teste2e/cypress/support/commands.js +++ b/teste2e/cypress/support/commands.js @@ -26,7 +26,8 @@ import { sha3_256 } from "js-sha3"; import { requestWithCsrfToken, setProposalStatus } from "../utils"; import * as pki from "../pki"; -// TODO: consider moving general functions like makeProposal and signRegister to a more general lib file other than api +// TODO: consider moving general functions like makeProposal and signRegister +// to a more general lib file other than api. import { makeProposal, signRegister } from "../utils"; Cypress.Commands.add("assertHome", () => { @@ -34,7 +35,7 @@ Cypress.Commands.add("assertHome", () => { }); Cypress.Commands.add("assertProposalPage", (proposal) => { - cy.findByText(proposal.name, { timeout: 20000 }).should("be.visible"); + cy.findAllByText(proposal.name, { timeout: 20000 }).should("be.visible"); cy.url().should( "eq", `${Cypress.config().baseUrl}/record/${proposal.token.substring(0, 7)}`