-
-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathtaskAction.test.js
More file actions
279 lines (254 loc) · 9.21 KB
/
taskAction.test.js
File metadata and controls
279 lines (254 loc) · 9.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import '@testing-library/jest-dom';
import { screen, act, waitFor } from '@testing-library/react';
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
import { QueryParamProvider } from 'use-query-params';
import { MapTask, TaskAction, ValidateTask } from '../taskAction';
import {
createComponentWithMemoryRouter,
QueryClientProviders,
ReduxIntlProviders,
renderWithRouter,
} from '../../utils/testWithIntl';
import { store } from '../../store';
describe('Submitting Mapping Status for a Task', () => {
const setup = () => {
const { user, router } = createComponentWithMemoryRouter(
<QueryClientProviders>
<QueryParamProvider adapter={ReactRouter6Adapter}>
<ReduxIntlProviders>
<MapTask />
</ReduxIntlProviders>
</QueryParamProvider>
</QueryClientProviders>,
{
route: '/projects/:id/map/',
entryRoute: '/projects/123/map/',
},
);
return { user, router };
};
jest.retryTimes(2);
it('should stop mapping and direct to tasks selection page', async () => {
await act(() => {
store.dispatch({ type: 'SET_LOCALE', locale: 'en-US' });
store.dispatch({ type: 'SET_TOKEN', token: 'validToken' });
store.dispatch({
type: 'SET_USER_DETAILS',
userDetails: { id: 123 },
});
});
const { user, router } = setup();
expect(
await screen.findByRole('button', {
name: /submit task/i,
}),
).toBeInTheDocument();
await user.click(await screen.findByRole('button', { name: /select another task/i }));
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should suggest the user to update status of previously locked task', async () => {
// Not using the setup function here to have different result for project detail
renderWithRouter(
<QueryClientProviders>
<QueryParamProvider adapter={ReactRouter6Adapter}>
<ReduxIntlProviders>
<TaskAction project={555} action="MAPPING" />
</ReduxIntlProviders>
</QueryParamProvider>
</QueryClientProviders>,
);
await waitFor(() =>
expect(screen.getByRole('heading')).toHaveTextContent(
'We found another mapping task already locked by you',
),
);
});
it('should submit task mapping status (YES option) and direct to tasks selection page', async () => {
const { user, router } = setup();
const submitBtn = await screen.findByRole('button', {
name: /submit task/i,
});
expect(submitBtn).toBeDisabled();
await user.click(
screen.getByRole('radio', {
name: /yes/i,
}),
);
expect(submitBtn).toBeEnabled();
await user.click(submitBtn);
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should submit task mapping status (NO option) and direct to tasks selection page', async () => {
const { user, router } = setup();
const submitBtn = await screen.findByRole('button', {
name: /submit task/i,
});
expect(submitBtn).toBeDisabled();
await user.click(
screen.getByRole('radio', {
name: /no/i,
}),
);
expect(submitBtn).toBeEnabled();
await user.click(submitBtn);
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should submit task mapping status (bad imagery option) and direct to tasks selection page', async () => {
// The button requires either the user's mapping level to be advanced
act(() => {
store.dispatch({
type: 'SET_USER_DETAILS',
userDetails: { id: 123, mappingLevel: 'ADVANCED' },
});
});
const { user, router } = setup();
const submitBtn = await screen.findByRole('button', {
name: /submit task/i,
});
expect(submitBtn).toBeDisabled();
await user.click(
screen.getByRole('radio', {
name: /the imagery is bad/i,
}),
);
expect(submitBtn).toBeEnabled();
await user.click(submitBtn);
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should submit task mapping status (bad imagery option) and direct to tasks selection page', async () => {
// The button requires either the user's mapping level to be advanced
act(() => {
store.dispatch({
type: 'SET_USER_DETAILS',
userDetails: { id: 123, mappingLevel: 'ADVANCED' },
});
});
const { user, router } = setup();
const submitBtn = await screen.findByRole('button', {
name: /submit task/i,
});
expect(submitBtn).toBeDisabled();
await user.click(
screen.getByRole('radio', {
name: /the imagery is bad/i,
}),
);
expect(submitBtn).toBeEnabled();
await user.click(submitBtn);
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should split the task and direct to tasks selection page', async () => {
const { user, router } = setup();
await screen.findByRole('button', {
name: /submit task/i,
});
await user.click(
screen.getByRole('button', {
name: /split task/i,
}),
);
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should redirect to login page if the user is not logged in', async () => {
act(() => {
store.dispatch({ type: 'SET_TOKEN', token: null });
});
const { router } = setup();
await waitFor(() => expect(router.state.location.pathname).toBe('/login'));
});
});
describe('Submitting Validation Status for Tasks', () => {
const setup = () => {
const { user, router } = createComponentWithMemoryRouter(
<QueryClientProviders>
<QueryParamProvider adapter={ReactRouter6Adapter}>
<ReduxIntlProviders>
<ValidateTask />
</ReduxIntlProviders>
</QueryParamProvider>
</QueryClientProviders>,
{
route: '/projects/:id/validate/',
entryRoute: '/projects/123/validate',
},
);
return { user, router };
};
it('should stop validation and direct to tasks selection page', async () => {
act(() => {
store.dispatch({ type: 'SET_LOCALE', locale: 'en-US' });
store.dispatch({ type: 'SET_TOKEN', token: 'validToken' });
store.dispatch({
type: 'SET_USER_DETAILS',
userDetails: { id: 123 },
});
});
const { user, router } = setup();
await waitFor(() => {
expect(
screen.getByRole('button', {
name: /submit task/i,
}),
).toBeInTheDocument();
});
await user.click(screen.getByRole('button', { name: /stop validation/i }));
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should submit task validation status (YES option) and direct to tasks selection page', async () => {
const { user, router } = setup();
const submitBtn = await screen.findByRole('button', {
name: /submit task/i,
});
expect(submitBtn).toBeDisabled();
await user.click(screen.getAllByRole('radio')[0]);
expect(submitBtn).toBeEnabled();
await user.click(submitBtn);
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
});
it('should submit task validation status (NO option) and direct to tasks selection page', async () => {
const { user, router } = setup();
const submitBtn = await screen.findByRole('button', {
name: /submit task/i,
});
expect(submitBtn).toBeDisabled();
await user.click(screen.getAllByRole('radio')[1]);
expect(submitBtn).toBeEnabled();
await user.click(submitBtn);
await waitFor(() => expect(router.state.location.pathname).toBe('/projects/123/tasks/'));
expect(router.state.location.search).toBe('?filter=MAPPED');
});
});
describe('Tabs in Task Action Page', () => {
const setup = async () => {
const { user, router } = createComponentWithMemoryRouter(
<QueryClientProviders>
<QueryParamProvider adapter={ReactRouter6Adapter}>
<ReduxIntlProviders>
<ValidateTask />
</ReduxIntlProviders>
</QueryParamProvider>
</QueryClientProviders>,
{
route: '/projects/:id/validate/',
entryRoute: '/projects/123/validate',
},
);
await screen.findByRole('button', { name: /submit task/i });
return { user, router };
};
it('should display project instructions on the instruction tab', async () => {
const { user } = await setup();
await user.click(screen.getByRole('button', { name: /instructions/i }));
expect(screen.getByText(/Project Specific Mapping Notes:/i)).toBeInTheDocument();
});
it('should display task history on the history tab', async () => {
const { user } = await setup();
await user.click(screen.getByRole('button', { name: /history/i }));
expect(screen.getByRole('radio', { name: /comments/i })).toBeChecked();
});
it('should display resources on the resources tab', async () => {
const { user } = await setup();
await user.click(screen.getByRole('button', { name: /resources/i }));
expect(screen.getByRole('button', { name: 'Download Tasks Grid' })).toBeInTheDocument();
});
});