Skip to content

Commit

Permalink
e2e/proposalEdit.js
Browse files Browse the repository at this point in the history
  • Loading branch information
amass01 committed May 10, 2021
1 parent a898ebe commit ad63d5a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 56 deletions.
137 changes: 83 additions & 54 deletions teste2e/cypress/e2e/proposalEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
);
});
});
5 changes: 3 additions & 2 deletions teste2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
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", () => {
cy.url().should("eq", `${Cypress.config().baseUrl}/`);
});

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)}`
Expand Down

0 comments on commit ad63d5a

Please sign in to comment.