Skip to content
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

fix: Votes timestamps download bug. #2685

Merged
merged 2 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Proposal/Proposal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ const Proposal = React.memo(function Proposal({
)}
{votesCount > 0 && (
<DownloadVotesTimestamps
label="Votes Timestamp"
label="Votes Timestamps"
votesCount={votesCount}
recordToken={shortToken}
/>
Expand Down
4 changes: 1 addition & 3 deletions src/containers/Proposal/Download/DownloadVotesTimestamps.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 55 additions & 0 deletions teste2e/cypress/e2e/proposal/votes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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", () => {
const yes = 250,
no = 50;
const total = yes + no;
beforeEach(() => {
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);
});
});
15 changes: 13 additions & 2 deletions teste2e/cypress/support/ticketvote/api.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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
};
1 change: 1 addition & 0 deletions teste2e/cypress/support/ticketvote/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
10 changes: 10 additions & 0 deletions teste2e/cypress/support/ticketvote/generate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import faker from "faker";

export function Results({ yes = 0, no = 0 } = {}) {
return [
{
Expand Down Expand Up @@ -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();
}