Skip to content

Commit 7ee9946

Browse files
hmrtnboudra
andauthored
(Builder) Update Application Landing page for when applications have not opened yet (#1920)
* feat: improved conditionals * fix: dates, types * fix: show when applications have not started yet * feat: apply button component * fix: round type instead of any * feat: implement tests for application apply button --------- Co-authored-by: Mohamed Boudra <[email protected]>
1 parent 369cd0d commit 7ee9946

File tree

2 files changed

+245
-80
lines changed

2 files changed

+245
-80
lines changed

packages/builder/src/__tests__/components/rounds/Show.test.tsx

+116-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { screen } from "@testing-library/react";
3+
import { useParams } from "react-router-dom";
4+
35
import { loadAllChainsProjects, loadProjects } from "../../../actions/projects";
46
import { loadRound, unloadRounds } from "../../../actions/rounds";
57
import { web3ChainIDLoaded } from "../../../actions/web3";
@@ -17,10 +19,7 @@ jest.mock("../../../actions/projects");
1719

1820
jest.mock("react-router-dom", () => ({
1921
...jest.requireActual("react-router-dom"),
20-
useParams: () => ({
21-
roundId: addressFrom(1),
22-
chainId: 5,
23-
}),
22+
useParams: jest.fn(),
2423
}));
2524

2625
jest.mock("wagmi", () => ({
@@ -34,20 +33,53 @@ jest.mock("wagmi", () => ({
3433
}));
3534

3635
describe("<Show />", () => {
37-
describe("with a valid round", () => {
38-
let store: any;
36+
let store: any;
3937

40-
beforeEach(() => {
41-
store = setupStore();
42-
const round = buildRound({
43-
address: addressFrom(1),
44-
});
38+
beforeEach(() => {
39+
store = setupStore();
40+
const round = buildRound({
41+
address: addressFrom(1),
42+
});
4543

46-
store.dispatch(web3ChainIDLoaded(5));
47-
store.dispatch({
48-
type: "ROUNDS_ROUND_LOADED",
49-
address: addressFrom(1),
50-
round,
44+
const pastRound = buildRound({
45+
address: addressFrom(1),
46+
applicationsStartTime: 0,
47+
applicationsEndTime: 0,
48+
roundStartTime: 0,
49+
roundEndTime: 0,
50+
});
51+
52+
const futureRound = buildRound({
53+
address: addressFrom(1),
54+
applicationsStartTime: Date.now() / 1000 + 60 * 30,
55+
applicationsEndTime: Date.now() / 1000 + 60 * 60,
56+
roundStartTime: Date.now() / 1000 + 60 * 60,
57+
roundEndTime: Date.now() / 1000 + 60 * 120,
58+
});
59+
60+
store.dispatch(web3ChainIDLoaded(5));
61+
store.dispatch({
62+
type: "ROUNDS_ROUND_LOADED",
63+
address: addressFrom(1),
64+
round,
65+
});
66+
store.dispatch({
67+
type: "ROUNDS_ROUND_LOADED",
68+
address: addressFrom(2),
69+
round: pastRound,
70+
});
71+
store.dispatch({
72+
type: "ROUNDS_ROUND_LOADED",
73+
address: addressFrom(3),
74+
round: futureRound,
75+
});
76+
});
77+
78+
describe("current round", () => {
79+
beforeEach(() => {
80+
(useParams as jest.Mock).mockReturnValue({
81+
roundId: addressFrom(1),
82+
chainId: 5,
5183
});
5284
});
5385

@@ -170,4 +202,72 @@ describe("<Show />", () => {
170202
});
171203
});
172204
});
205+
206+
describe("past round", () => {
207+
beforeEach(() => {
208+
(useParams as jest.Mock).mockReturnValue({
209+
roundId: addressFrom(2),
210+
chainId: 5,
211+
});
212+
});
213+
214+
it("should not allow you to apply", async () => {
215+
(loadRound as jest.Mock).mockReturnValue({ type: "TEST" });
216+
(unloadRounds as jest.Mock).mockReturnValue({ type: "TEST" });
217+
(loadAllChainsProjects as jest.Mock).mockReturnValue({ type: "TEST" });
218+
219+
store.dispatch({
220+
type: "GRANT_METADATA_FETCHED",
221+
data: buildProjectMetadata({}),
222+
});
223+
224+
store.dispatch({
225+
type: "PROJECTS_LOADED",
226+
payload: {
227+
chainID: 0,
228+
events: {},
229+
},
230+
});
231+
232+
renderWrapped(<Show />, store);
233+
234+
expect(screen.getByText("Application Period Ended")).toBeInTheDocument();
235+
expect(screen.queryByText("Apply")).not.toBeInTheDocument();
236+
});
237+
});
238+
239+
describe("future round", () => {
240+
beforeEach(() => {
241+
(useParams as jest.Mock).mockReturnValue({
242+
roundId: addressFrom(3),
243+
chainId: 5,
244+
});
245+
});
246+
247+
it("should not allow you to apply", async () => {
248+
(loadRound as jest.Mock).mockReturnValue({ type: "TEST" });
249+
(unloadRounds as jest.Mock).mockReturnValue({ type: "TEST" });
250+
(loadAllChainsProjects as jest.Mock).mockReturnValue({ type: "TEST" });
251+
252+
store.dispatch({
253+
type: "GRANT_METADATA_FETCHED",
254+
data: buildProjectMetadata({}),
255+
});
256+
257+
store.dispatch({
258+
type: "PROJECTS_LOADED",
259+
payload: {
260+
chainID: 0,
261+
events: {},
262+
},
263+
});
264+
265+
renderWrapped(<Show />, store);
266+
267+
expect(
268+
screen.getByText("The application period for this round will start on")
269+
).toBeInTheDocument();
270+
expect(screen.getByText("Apply")).toBeDisabled();
271+
});
272+
});
173273
});

0 commit comments

Comments
 (0)