Skip to content

Commit

Permalink
fix: Under Review pagination issues for big screens.
Browse files Browse the repository at this point in the history
- Fix pagination for records pages where the returned inventory was the 
exact amount needed to fill all the screen. Big screens only.

- Add e2e to cover this case.
  • Loading branch information
victorgcramos authored Sep 21, 2021
1 parent 71c0a36 commit edb0cb4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/hooks/api/useProposalsBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ export default function useProposalsBatch({
actions: {
initial: () => send(START),
start: () => {
if (remainingTokens.length >= proposalPageSize) return send(VERIFY);

if (remainingTokens.length > proposalPageSize) return send(VERIFY);
// If remaining tokens length is smaller than proposal page size.
// Find more tokens from inventory or scan from the next status

// scanNextStatus: inventory is initialized and
// there are no tokens to be fetched from the next page
const scanNextStatus =
initializedInventory &&
!(tokens.length % INVENTORY_PAGE_SIZE === 0 && tokens.length > 0);
(!(tokens.length % INVENTORY_PAGE_SIZE === 0 && tokens.length > 0) ||
remainingTokens.length === proposalPageSize);
if (scanNextStatus) {
const { index, tokens } = scanNextStatusTokens(
statusIndex + 1,
Expand Down Expand Up @@ -198,12 +198,19 @@ export default function useProposalsBatch({
const tokens = [...newTokens, ...remainingTokens];
setRemainingTokens(tokens);

// Go to the next status when the remaining tokens still be smaller
// than proposal page size and current status is not the last one.
if (
// Means the current batch request accepts more tokens than
// the current amount.
const needsToCompletePaginationBatch =
tokens.length < proposalPageSize &&
statusIndex + 1 < currentStatuses.length
) {
statusIndex + 1 < currentStatuses.length;

// can scan more tokens from next status list in order to
// populate the remainingTokens array and don't lose any token
const needsNextStatusScan =
tokens.length === proposalPageSize ||
needsToCompletePaginationBatch;

if (needsNextStatusScan) {
const nextIndex = statusIndex + 1;
const nextStatus = currentStatuses[nextIndex];
const nextStatusTokens = getUnfetchedTokens(
Expand Down
60 changes: 60 additions & 0 deletions teste2e/cypress/e2e/proposal/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,64 @@ describe("Records list", () => {
cy.assertListLengthByTestId("record-title", 10);
});
});

describe("Big screens and inventory length multiple of proposals page size", () => {
beforeEach(() => {
cy.viewport(1500, 1500);
});
it("can render under review records with 5 autorized tokens", () => {
// setup
cy.middleware("ticketvote.inventory", {
authorized: 5,
started: 0,
unauthorized: 13
});
cy.middleware("records.records");
// test
cy.visit(`/`);
cy.wait("@ticketvote.inventory");
// Should trigger at least 2 records batch requests
cy.wait("@records.records");
cy.wait("@records.records");
cy.assertListLengthByTestId("record-title", 10);
cy.scrollTo("bottom");
cy.wait(1000);
cy.assertListLengthByTestId("record-title", 15);
});
it("can render under review records with 5 started tokens", () => {
cy.middleware("ticketvote.inventory", {
authorized: 0,
started: 5,
unauthorized: 13
});
cy.middleware("records.records");
});
it("can render under review records with 5 tokens started and authorized", () => {
cy.middleware("ticketvote.inventory", {
authorized: 5,
started: 5,
unauthorized: 13
});
cy.middleware("records.records");
});
it("can render 10 authorized proposals", () => {
cy.middleware("ticketvote.inventory", {
authorized: 10,
started: 0,
unauthorized: 13
});
cy.middleware("records.records");
});
afterEach(() => {
cy.visit(`/`);
cy.wait("@ticketvote.inventory");
// Should trigger at least 2 records batch requests
cy.wait("@records.records");
cy.wait("@records.records");
cy.assertListLengthByTestId("record-title", 10);
cy.scrollTo("bottom");
cy.wait(1000);
cy.assertListLengthByTestId("record-title", 15);
});
});
});

0 comments on commit edb0cb4

Please sign in to comment.