1
1
import "@testing-library/jest-dom" ;
2
2
import { screen } from "@testing-library/react" ;
3
+ import { useParams } from "react-router-dom" ;
4
+
3
5
import { loadAllChainsProjects , loadProjects } from "../../../actions/projects" ;
4
6
import { loadRound , unloadRounds } from "../../../actions/rounds" ;
5
7
import { web3ChainIDLoaded } from "../../../actions/web3" ;
@@ -17,10 +19,7 @@ jest.mock("../../../actions/projects");
17
19
18
20
jest . mock ( "react-router-dom" , ( ) => ( {
19
21
...jest . requireActual ( "react-router-dom" ) ,
20
- useParams : ( ) => ( {
21
- roundId : addressFrom ( 1 ) ,
22
- chainId : 5 ,
23
- } ) ,
22
+ useParams : jest . fn ( ) ,
24
23
} ) ) ;
25
24
26
25
jest . mock ( "wagmi" , ( ) => ( {
@@ -34,20 +33,53 @@ jest.mock("wagmi", () => ({
34
33
} ) ) ;
35
34
36
35
describe ( "<Show />" , ( ) => {
37
- describe ( "with a valid round" , ( ) => {
38
- let store : any ;
36
+ let store : any ;
39
37
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
+ } ) ;
45
43
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 ,
51
83
} ) ;
52
84
} ) ;
53
85
@@ -170,4 +202,72 @@ describe("<Show />", () => {
170
202
} ) ;
171
203
} ) ;
172
204
} ) ;
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
+ } ) ;
173
273
} ) ;
0 commit comments