Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKurt committed May 2, 2024
1 parent 383aa47 commit 38eb70a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ import {
import { ProgressStatus } from "../../api/types";
import { errorModalDelayMs } from "../../../constants";
import { useApplicationsByRoundId } from "../../common/useApplicationsByRoundId";
import { AlloOperation, useAllo } from "common";
import { AlloOperation, useAllo, AlloV1 } from "common";

jest.mock("common", () => ({
...jest.requireActual("common"),
useAllo: jest.fn(),
}));

jest.mock("common/src/allo/backends/allo-v1");

const mockBulkUpdateApplicationStatus = jest.fn().mockResolvedValue({
type: "success",
});

jest
.spyOn(AlloV1.prototype, "bulkUpdateApplicationStatus")
.mockImplementation(mockBulkUpdateApplicationStatus);

jest.mock("../../api/application");
jest.mock("../../api/subgraph");
jest.mock("react-router-dom", () => ({
Expand Down Expand Up @@ -288,46 +298,34 @@ describe("<ApplicationsApproved />", () => {
});

// TODO -- can't get this to pass -- expect(updateApplicationStatuses).toBeCalled() fails even though updateApplicationStatuses is called
// it("update round contract", async () => {
// (updateApplicationStatuses as jest.Mock).mockResolvedValue({
// transactionBlockNumber: 99,
// });
// (waitForSubgraphSyncTo as jest.Mock).mockResolvedValue({});
//
// renderWithContext(
// <ApplicationsApproved />,
// {
// applications: grantApplications,
// isLoading: false,
// },
// {
// IPFSCurrentStatus: ProgressStatus.IS_SUCCESS,
// contractUpdatingStatus: ProgressStatus.IS_SUCCESS,
// }
// );
// fireEvent.click(
// screen.getByRole("button", {
// name: /Select/i,
// })
// );
// fireEvent.click(screen.queryAllByTestId("reject-button")[0]);
// fireEvent.click(
// screen.getByRole("button", {
// name: /Continue/i,
// })!
// );
//
// fireEvent.click(screen.getByRole("button", { name: /Confirm/i })!);
//
// await screen.findByTestId("progress-modal");
// await screen.findByTestId("Updating-complete-icon");
//
// expect(updateApplicationStatuses).toBeCalled();
// const updateApplicationStatusesFirstCall = (updateApplicationStatuses as jest.Mock)
// .mock.calls[0];
// const actualRoundId = updateApplicationStatusesFirstCall[0];
// expect(actualRoundId).toEqual(roundIdOverride);
// });
it("update round contract", async () => {
renderWithContext(<ApplicationsApproved />, {
applications: grantApplications,
});
fireEvent.click(
screen.getByRole("button", {
name: /Select/i,
})
);
fireEvent.click(screen.queryAllByTestId("reject-button")[0]);
fireEvent.click(
screen.getByRole("button", {
name: /Continue/i,
})!
);

fireEvent.click(screen.getByRole("button", { name: /Confirm/i })!);

await screen.findByTestId("progress-modal");

expect(mockBulkUpdateApplicationStatus).toBeCalled();
const updateApplicationStatusesFirstCall = (
mockBulkUpdateApplicationStatus as jest.Mock
).mock.calls[0][0].roundId;

const actualRound = updateApplicationStatusesFirstCall;
expect(actualRound).toEqual(roundIdOverride);
});

it("closes confirmation when cancel is selected", async () => {
setupInBulkSelectionMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@ import {
BulkUpdateGrantApplicationState,
initialBulkUpdateGrantApplicationState,
} from "../../../context/application/BulkUpdateGrantApplicationContext";
import { updateApplicationStatuses } from "../../api/application";
import { ProgressStatus } from "../../api/types";
import { errorModalDelayMs } from "../../../constants";
import { useApplicationsByRoundId } from "../../common/useApplicationsByRoundId";
import { ROUND_PAYOUT_DIRECT_OLD as ROUND_PAYOUT_DIRECT } from "common";
import { AlloOperation, useAllo } from "common";
import { AlloOperation, useAllo, AlloV1 } from "common";

jest.mock("common", () => ({
...jest.requireActual("common"),
useAllo: jest.fn(),
}));

jest.mock("common/src/allo/backends/allo-v1");

const mockBulkUpdateApplicationStatus = jest.fn().mockResolvedValue({
type: "success",
});

jest
.spyOn(AlloV1.prototype, "bulkUpdateApplicationStatus")
.mockImplementation(mockBulkUpdateApplicationStatus);

jest.mock("../../api/application");
jest.mock("../../common/Auth", () => ({
useWallet: () => ({
Expand Down Expand Up @@ -321,7 +330,6 @@ describe("<ApplicationsReceived />", () => {
});

it("starts the bulk update process when confirm is selected", async () => {
(updateApplicationStatuses as jest.Mock).mockResolvedValue("");
setupInBulkSelectionMode();

const inReviewButton = screen.queryAllByTestId("in-review-button")[0];
Expand All @@ -339,12 +347,12 @@ describe("<ApplicationsReceived />", () => {
fireEvent.click(confirmationModalConfirmButton);

await waitFor(() => {
expect(updateApplicationStatuses).toBeCalled();
expect(mockBulkUpdateApplicationStatus).toBeCalled();
});

expect(updateApplicationStatuses).toBeCalled();
const calls = (updateApplicationStatuses as jest.Mock).mock.calls;
expect(calls[0][0]).toEqual(payoutStrategyId);
expect(mockBulkUpdateApplicationStatus).toBeCalled();
const calls = (mockBulkUpdateApplicationStatus as jest.Mock).mock.calls;
expect(calls[0][0].strategyAddress).toEqual(payoutStrategyId);
});

it("closes confirmation when cancel is selected", async () => {
Expand Down Expand Up @@ -384,7 +392,7 @@ describe("<ApplicationsReceived />", () => {
describe("when processing bulk action fails", () => {
beforeEach(() => {
const transactionBlockNumber = 10;
(updateApplicationStatuses as jest.Mock).mockResolvedValue({
(mockBulkUpdateApplicationStatus as jest.Mock).mockResolvedValue({
transactionBlockNumber,
});

Expand Down

0 comments on commit 38eb70a

Please sign in to comment.