From a2dc320049dec87120a96b44461d56fc467732ea Mon Sep 17 00:00:00 2001 From: Victor Guedes Date: Wed, 1 Dec 2021 17:21:10 -0300 Subject: [PATCH 1/2] fix: votes timestamps download bug --- src/components/Proposal/Proposal.jsx | 2 +- .../Download/DownloadVotesTimestamps.jsx | 4 +--- teste2e/cypress/e2e/proposal/votes.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 teste2e/cypress/e2e/proposal/votes.js diff --git a/src/components/Proposal/Proposal.jsx b/src/components/Proposal/Proposal.jsx index fb8930157..844085f17 100644 --- a/src/components/Proposal/Proposal.jsx +++ b/src/components/Proposal/Proposal.jsx @@ -530,7 +530,7 @@ const Proposal = React.memo(function Proposal({ )} {votesCount > 0 && ( diff --git a/src/containers/Proposal/Download/DownloadVotesTimestamps.jsx b/src/containers/Proposal/Download/DownloadVotesTimestamps.jsx index eb0e3dee7..98f2c69ba 100644 --- a/src/containers/Proposal/Download/DownloadVotesTimestamps.jsx +++ b/src/containers/Proposal/Download/DownloadVotesTimestamps.jsx @@ -28,9 +28,7 @@ const DownloadVotesTimestampsWrapper = ({ label, recordToken, votesCount }) => { const DownloadVotesTimestamps = ({ recordToken, votesCount }) => { const { - policy: { - policyTicketVote: { timestampspagesize: timestampsPageSize } - } + policyTicketVote: { timestampspagesize: timestampsPageSize } } = usePolicy(); const { timestamps, progress, loading, error, multiPage } = useDownloadVoteTimestamps(recordToken, votesCount, timestampsPageSize); diff --git a/teste2e/cypress/e2e/proposal/votes.js b/teste2e/cypress/e2e/proposal/votes.js new file mode 100644 index 000000000..2d017ea0c --- /dev/null +++ b/teste2e/cypress/e2e/proposal/votes.js @@ -0,0 +1,18 @@ +beforeEach(function mockApiCalls() { + // currently mocking pi and ticketvote summaries calls with any status, since + // they aren't used for assertions. the `Missing` status will show up, but it + // doesn't affect the list behavior. + cy.useTicketvoteApi(); + cy.useRecordsApi(); + cy.usePiApi(); + cy.useWwwApi(); + cy.useCommentsApi(); + cy.userEnvironment("noLogin"); +}); + +describe("Given an approved proposal", () => { + beforeEach(() => { + cy.ticketvoteMiddleware(); + }); + it("should be able to download votes timestamps", () => {}); +}); From 8624adb5ac5e2e62c3817a64f974013a0f04b7e2 Mon Sep 17 00:00:00 2001 From: Victor Guedes Date: Wed, 1 Dec 2021 18:43:35 -0300 Subject: [PATCH 2/2] test: e2e for votes timestamps download --- teste2e/cypress/e2e/proposal/votes.js | 41 ++++++++++++++++++- teste2e/cypress/support/ticketvote/api.js | 15 ++++++- .../cypress/support/ticketvote/commands.js | 1 + .../cypress/support/ticketvote/generate.js | 10 +++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/teste2e/cypress/e2e/proposal/votes.js b/teste2e/cypress/e2e/proposal/votes.js index 2d017ea0c..ed09842ec 100644 --- a/teste2e/cypress/e2e/proposal/votes.js +++ b/teste2e/cypress/e2e/proposal/votes.js @@ -11,8 +11,45 @@ beforeEach(function mockApiCalls() { }); describe("Given an approved proposal", () => { + const yes = 250, + no = 50; + const total = yes + no; beforeEach(() => { - cy.ticketvoteMiddleware(); + cy.ticketvoteMiddleware("summaries", { + amountByStatus: { approved: 1 }, + resultsByStatus: { approved: { yes, no } } + }); + cy.ticketvoteMiddleware("timestamps", { + votesAmount: 100, + authsAmount: 100 + }); + cy.recordsMiddleware("details", { status: 2, state: 2 }); + cy.piMiddleware("summaries", { amountByStatus: { active: 1 } }); + }); + it("should be able to download votes timestamps from a single page", () => { + cy.ticketvoteMiddleware("timestamps", { + votesAmount: total, + authsAmount: total + }); + cy.visit("/record/abcdefg"); + cy.wait("@records.details"); + cy.wait("@pi.summaries"); + cy.findByTestId("record-links").click(); + cy.findByText(/votes timestamps/i).click(); + cy.wait(1000); + cy.get("@ticketvote.timestamps.all").should("have.length.of.at.most", 2); + }); + it("should be able to download paginated votes timestamps", () => { + cy.ticketvoteMiddleware("timestamps", { + votesAmount: total / 2, + authsAmount: total / 2 + }); + cy.visit("/record/abcdefg"); + cy.wait("@records.details"); + cy.wait("@pi.summaries"); + cy.findByTestId("record-links").click(); + cy.findByText(/votes timestamps/i).click(); + cy.findByText(/50%/i).should("be.visible"); + cy.get("@ticketvote.timestamps.all").should("have.length.of.at.most", 3); }); - it("should be able to download votes timestamps", () => {}); }); diff --git a/teste2e/cypress/support/ticketvote/api.js b/teste2e/cypress/support/ticketvote/api.js index 48c514626..1572149b2 100644 --- a/teste2e/cypress/support/ticketvote/api.js +++ b/teste2e/cypress/support/ticketvote/api.js @@ -1,7 +1,8 @@ import { inventoryReply as recordsInventoryReply } from "../core/api"; -import { Summary } from "./generate"; +import { Summary, Timestamp } from "./generate"; import { statusToString, stringToStatus, typeFromStatus } from "./utils"; import { chunkByStatusAmount } from "../core/utils"; +import times from "lodash/fp/times"; export const API_BASE_URL = "/api/ticketvote/v1"; @@ -85,8 +86,18 @@ export function policyReply() { }; } +export function timestampsReply({ + testParams: { votesAmount = 0, authsAmount = 0 } +}) { + const timestamp = new Timestamp(); + const votes = times(() => timestamp)(votesAmount); + const auths = times(() => timestamp)(authsAmount); + return { auths, details: timestamp, votes }; +} + export const repliers = { inventory: inventoryReply, + policy: policyReply, summaries: summariesReply, - policy: policyReply + timestamps: timestampsReply }; diff --git a/teste2e/cypress/support/ticketvote/commands.js b/teste2e/cypress/support/ticketvote/commands.js index a2baeb25a..5588a302b 100644 --- a/teste2e/cypress/support/ticketvote/commands.js +++ b/teste2e/cypress/support/ticketvote/commands.js @@ -15,4 +15,5 @@ Cypress.Commands.add("useTicketvoteApi", (config = {}) => { cy.ticketvoteMiddleware("summaries", config.summaries); cy.ticketvoteMiddleware("inventory", config.inventory); cy.ticketvoteMiddleware("policy", config.policy); + cy.ticketvoteMiddleware("timestamps", config.timestamps); }); diff --git a/teste2e/cypress/support/ticketvote/generate.js b/teste2e/cypress/support/ticketvote/generate.js index 376885a5e..cf6465f79 100644 --- a/teste2e/cypress/support/ticketvote/generate.js +++ b/teste2e/cypress/support/ticketvote/generate.js @@ -1,3 +1,5 @@ +import faker from "faker"; + export function Results({ yes = 0, no = 0 } = {}) { return [ { @@ -30,3 +32,11 @@ export function Summary({ results, status, type = 0 } = {}) { this.results = type ? new Results(results) : 0; this.bestblock = 200; } + +export function Timestamp({ data } = {}) { + this.data = JSON.stringify(data || { key: faker.random.word() }); + this.digest = faker.datatype.hexaDecimal(128, false, /[0-9a-z]/); + this.txid = faker.datatype.hexaDecimal(64, false, /[0-9a-z]/); + this.merkleroot = faker.datatype.hexaDecimal(64, false, /[0-9a-z]/); + this.proofs = faker.random.arrayElements(); +}