1
1
import "@testing-library/jest-dom" ;
2
2
import { act , cleanup } from "@testing-library/react" ;
3
3
4
- import { Edit , MergeUndoIds , Permission , User , UserEdit } from "api/models" ;
4
+ import { Edit , MergeUndoIds , User , UserEdit } from "api/models" ;
5
5
import * as LocalStorage from "backend/localStorage" ;
6
- import GoalTimeline from "components/GoalTimeline" ;
7
6
import {
8
7
CharInvChanges ,
9
8
CharInvData ,
@@ -32,48 +31,31 @@ import { GoalStatus, GoalType } from "types/goals";
32
31
import { Path } from "types/path" ;
33
32
import { newUser } from "types/user" ;
34
33
import * as goalUtilities from "utilities/goalUtilities" ;
35
- import { renderWithProviders } from "utilities/testingLibraryUtilities" ;
36
34
37
35
jest . mock ( "backend" , ( ) => ( {
38
36
addGoalToUserEdit : ( ...args : any [ ] ) => mockAddGoalToUserEdit ( ...args ) ,
39
- addStepToGoal : ( ... args : any [ ] ) => mockAddStepToGoal ( ... args ) ,
37
+ addStepToGoal : ( ) => jest . fn ( ) ,
40
38
createUserEdit : ( ) => mockCreateUserEdit ( ) ,
41
- findDuplicates : ( ) => Promise . resolve ( ) ,
42
- getCurrentPermissions : ( ) => mockGetCurrentPermissions ( ) ,
39
+ findDuplicates : ( ) => jest . fn ( ) ,
43
40
getGraylistEntries : ( ) => Promise . resolve ( [ ] ) ,
44
- getUser : ( id : string ) => mockGetUser ( id ) ,
45
41
getUserEditById : ( ...args : any [ ] ) => mockGetUserEditById ( ...args ) ,
46
- hasGraylistEntries : ( ) => Promise . resolve ( false ) ,
42
+ hasGraylistEntries : ( ) => jest . fn ( ) ,
47
43
retrieveDuplicates : ( ) => mockRetrieveDuplicates ( ) ,
48
- updateUser : ( user : User ) => mockUpdateUser ( user ) ,
49
44
} ) ) ;
50
- jest . mock ( "components/Project/ProjectActions" , ( ) => ( { } ) ) ;
51
- jest . mock ( "components/Pronunciations/Recorder" ) ;
52
45
jest . mock ( "router/browserRouter" , ( ) => ( {
53
46
navigate : ( path : Path ) => mockNavigate ( path ) ,
54
47
} ) ) ;
55
48
56
49
const mockAddGoalToUserEdit = jest . fn ( ) ;
57
- const mockAddStepToGoal = jest . fn ( ) ;
58
50
const mockCreateUserEdit = jest . fn ( ) ;
59
- const mockGetCurrentPermissions = jest . fn ( ) ;
60
- const mockGetUser = jest . fn ( ) ;
61
51
const mockGetUserEditById = jest . fn ( ) ;
62
52
const mockNavigate = jest . fn ( ) ;
63
53
const mockRetrieveDuplicates = jest . fn ( ) ;
64
- const mockUpdateUser = jest . fn ( ) ;
65
54
function setMockFunctions ( ) : void {
66
55
mockAddGoalToUserEdit . mockResolvedValue ( 0 ) ;
67
- mockAddStepToGoal . mockResolvedValue ( 0 ) ;
68
56
mockCreateUserEdit . mockResolvedValue ( mockUser ( ) ) ;
69
- mockGetCurrentPermissions . mockResolvedValue ( [
70
- Permission . CharacterInventory ,
71
- Permission . MergeAndReviewEntries ,
72
- ] ) ;
73
- mockGetUser . mockResolvedValue ( mockUser ( ) ) ;
74
57
mockGetUserEditById . mockResolvedValue ( mockUserEdit ( true ) ) ;
75
58
mockRetrieveDuplicates . mockResolvedValue ( goalDataMock . plannedWords ) ;
76
- mockUpdateUser . mockResolvedValue ( mockUser ( ) ) ;
77
59
}
78
60
79
61
const mockProjectId = "123" ;
@@ -124,7 +106,6 @@ describe("setCurrentGoal", () => {
124
106
it ( "calls setCurrentGoal() with no arguments" , async ( ) => {
125
107
const store = setupStore ( ) ;
126
108
await act ( async ( ) => {
127
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
128
109
store . dispatch ( setCurrentGoal ( ) ) ;
129
110
} ) ;
130
111
expect ( store . getState ( ) . goalsState . currentGoal . goalType ) . toEqual (
@@ -136,9 +117,6 @@ describe("setCurrentGoal", () => {
136
117
describe ( "asyncGetUserEdits" , ( ) => {
137
118
it ( "backend returns user edits" , async ( ) => {
138
119
const store = setupStore ( ) ;
139
- await act ( async ( ) => {
140
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
141
- } ) ;
142
120
const convertEditToGoalSpy = jest . spyOn ( goalUtilities , "convertEditToGoal" ) ;
143
121
await act ( async ( ) => {
144
122
await store . dispatch ( asyncGetUserEdits ( ) ) ;
@@ -148,14 +126,9 @@ describe("asyncGetUserEdits", () => {
148
126
} ) ;
149
127
150
128
it ( "backend returns no user edits" , async ( ) => {
151
- // render the GoalTimeline
152
129
const store = setupStore ( ) ;
153
- await act ( async ( ) => {
154
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
155
- } ) ;
156
130
157
131
// setup mocks for testing the action/reducers
158
- jest . clearAllMocks ( ) ;
159
132
const convertEditToGoalSpy = jest . spyOn ( goalUtilities , "convertEditToGoal" ) ;
160
133
mockGetUserEditById . mockResolvedValueOnce ( mockUserEdit ( false ) ) ;
161
134
@@ -169,9 +142,6 @@ describe("asyncGetUserEdits", () => {
169
142
170
143
it ( "creates new user edits" , async ( ) => {
171
144
const store = setupStore ( ) ;
172
- await act ( async ( ) => {
173
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
174
- } ) ;
175
145
LocalStorage . setCurrentUser ( newUser ( ) ) ;
176
146
await act ( async ( ) => {
177
147
await store . dispatch ( asyncGetUserEdits ( ) ) ;
@@ -184,10 +154,6 @@ describe("asyncGetUserEdits", () => {
184
154
describe ( "asyncAddGoal" , ( ) => {
185
155
it ( "adds new MergeDups goal" , async ( ) => {
186
156
const store = setupStore ( ) ;
187
- await act ( async ( ) => {
188
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
189
- } ) ;
190
-
191
157
await act ( async ( ) => {
192
158
await store . dispatch ( asyncAddGoal ( new MergeDups ( ) ) ) ;
193
159
} ) ;
@@ -201,10 +167,6 @@ describe("asyncAddGoal", () => {
201
167
202
168
it ( "adds new CreateCharInv goal" , async ( ) => {
203
169
const store = setupStore ( ) ;
204
- await act ( async ( ) => {
205
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
206
- } ) ;
207
-
208
170
await act ( async ( ) => {
209
171
await store . dispatch ( asyncAddGoal ( new CreateCharInv ( ) ) ) ;
210
172
} ) ;
@@ -225,10 +187,6 @@ describe("asyncAddGoal", () => {
225
187
describe ( "asyncLoadNewGoalData" , ( ) => {
226
188
it ( "loads data for MergeDups goal" , async ( ) => {
227
189
const store = setupStore ( ) ;
228
- await act ( async ( ) => {
229
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
230
- } ) ;
231
-
232
190
await act ( async ( ) => {
233
191
await store . dispatch ( asyncAddGoal ( new MergeDups ( ) ) ) ;
234
192
await store . dispatch ( asyncLoadNewGoalData ( ) ) ;
@@ -247,9 +205,6 @@ describe("asyncAdvanceStep", () => {
247
205
it ( "advance MergeDups goal" , async ( ) => {
248
206
// setup the test scenario
249
207
const store = setupStore ( ) ;
250
- await act ( async ( ) => {
251
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
252
- } ) ;
253
208
// create mergeDups goal
254
209
await act ( async ( ) => {
255
210
await store . dispatch ( asyncAddGoal ( new MergeDups ( ) ) ) ;
@@ -282,9 +237,6 @@ describe("asyncAdvanceStep", () => {
282
237
it ( "advance CreateCharInv goal" , async ( ) => {
283
238
// setup the test scenario
284
239
const store = setupStore ( ) ;
285
- await act ( async ( ) => {
286
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
287
- } ) ;
288
240
// create character inventory goal
289
241
const goal = new CreateCharInv ( ) ;
290
242
await act ( async ( ) => {
@@ -304,9 +256,6 @@ describe("asyncUpdateGoal", () => {
304
256
it ( "update CreateCharInv goal" , async ( ) => {
305
257
// setup the test scenario
306
258
const store = setupStore ( ) ;
307
- await act ( async ( ) => {
308
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
309
- } ) ;
310
259
// create CreateCharInv goal
311
260
const goal = new CreateCharInv ( ) ;
312
261
await act ( async ( ) => {
@@ -327,9 +276,6 @@ describe("asyncUpdateGoal", () => {
327
276
it ( "update MergeDups goal" , async ( ) => {
328
277
// setup the test scenario
329
278
const store = setupStore ( ) ;
330
- await act ( async ( ) => {
331
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
332
- } ) ;
333
279
// create MergeDups goal
334
280
const goal = new MergeDups ( ) ;
335
281
await act ( async ( ) => {
@@ -352,9 +298,6 @@ describe("asyncUpdateGoal", () => {
352
298
it ( "update ReviewDeferredDups goal" , async ( ) => {
353
299
// setup the test scenario
354
300
const store = setupStore ( ) ;
355
- await act ( async ( ) => {
356
- renderWithProviders ( < GoalTimeline /> , { store : store } ) ;
357
- } ) ;
358
301
// create ReviewDeferredDups goal
359
302
const goal = new ReviewDeferredDups ( ) ;
360
303
await act ( async ( ) => {
0 commit comments