Skip to content

Commit ded7e25

Browse files
committed
Clean up some warnings for project.test.js
Signed-off-by: Taylor Smock <[email protected]>
1 parent bb527c9 commit ded7e25

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

frontend/src/components/projectDetail/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,21 @@ export const ProjectDetail = (props) => {
370370
);
371371
};
372372

373+
const GeometryPropType = PropTypes.shape({
374+
type: PropTypes.oneOf(['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon', 'GeometryCollection']),
375+
coordinates: PropTypes.array,
376+
geometries: PropTypes.array
377+
});
378+
const FeaturePropType = PropTypes.shape({
379+
type: PropTypes.oneOf(['Feature']),
380+
geometry: GeometryPropType,
381+
properties: PropTypes.object,
382+
});
383+
const FeatureCollectionPropType = PropTypes.shape({
384+
type: PropTypes.oneOf(['FeatureCollection']),
385+
features: PropTypes.arrayOf(FeaturePropType).isRequired
386+
});
387+
373388
ProjectDetail.propTypes = {
374389
project: PropTypes.shape({
375390
projectId: PropTypes.number,
@@ -393,10 +408,11 @@ ProjectDetailMap.propTypes = {
393408
areaOfInterest: PropTypes.object,
394409
priorityAreas: PropTypes.arrayOf(PropTypes.object),
395410
}).isRequired,
396-
tasks: PropTypes.arrayOf(PropTypes.object),
411+
// Tasks are a GeoJSON FeatureCollection
412+
tasks: FeatureCollectionPropType,
397413
navigate: PropTypes.func,
398414
type: PropTypes.string,
399-
tasksError: PropTypes.string,
415+
tasksError: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
400416
projectLoading: PropTypes.bool,
401417
};
402418

@@ -406,7 +422,7 @@ ProjectDetailLeft.propTypes = {
406422
shortDescription: PropTypes.string,
407423
}),
408424
projectId: PropTypes.number,
409-
tasks: PropTypes.arrayOf(PropTypes.object),
425+
tasks: FeatureCollectionPropType,
410426
}).isRequired,
411427
contributors: PropTypes.arrayOf(PropTypes.object),
412428
className: PropTypes.string,

frontend/src/network/tests/mockData/projects.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export const taskDetail = (taskId) => ({
323323
export const projectComments = {
324324
chat: [
325325
{
326+
id: 1,
326327
message:
327328
"<p>@happy_me we do want 'significant' roads that lead to houses. Rule of thumb I use for picking classification is the usage over condition/what it looks like. If it's the main 'path' to one or maybe several homes, I would pick service; even if a vehicle can't drive it, that can be reflected with additional tags, but the road still functions as access to the home(s).</p>",
328329
pictureUrl:
@@ -331,20 +332,23 @@ export const projectComments = {
331332
username: 'helnershingthapa',
332333
},
333334
{
335+
id: 2,
334336
message: '<p>hello world</p>',
335337
pictureUrl:
336338
'https://www.openstreetmap.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBNXQ2Q3c9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--fe41f1b2a5d6cf492a7133f15c81f105dec06ff7/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBPZ2h3Ym1jNkZISmxjMmw2WlY5MGIxOXNhVzFwZEZzSGFXbHBhUT09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--058ac785867b32287d598a314311e2253bd879a3/unnamed.webp',
337339
timestamp: '2023-01-03T10:54:25.805150Z',
338340
username: 'helnershingthapa',
339341
},
340342
{
343+
id: 3,
341344
message: '<p>asdadadasdasdasd</p>',
342345
pictureUrl:
343346
'https://www.openstreetmap.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBeFJheFE9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--a765e2377a288bccae85da6604300251d9de6d39/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2RkhKbGMybDZaVjkwYjE5c2FXMXBkRnNIYVdscGFRPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--1d22b8d446683a272d1a9ff04340453ca7c374b4/bitmoji.jpg',
344347
timestamp: '2022-10-19T09:32:52.231545Z',
345348
username: 'Hel Nershing Thapa',
346349
},
347350
{
351+
id: 4,
348352
message:
349353
'<p><code>test of \ncode block\nhmmm\npreview showed it as a block\nand monospace font\nbut not indented</code></p>',
350354
pictureUrl:
@@ -353,6 +357,7 @@ export const projectComments = {
353357
username: 'wireguy',
354358
},
355359
{
360+
id: 5,
356361
message:
357362
'<p><code>this is a code\nblock\nshould it\nbe indented\nby 4 space?\nminor...</code></p>',
358363
pictureUrl:

frontend/src/views/tests/project.test.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,13 @@ describe('Project Detail Page', () => {
221221
Line: () => null,
222222
}));
223223

224-
it('should render component details', async () => {
225-
act(() => {
226-
store.dispatch({ type: 'SET_LOCALE', locale: 'es-AR' });
227-
});
228-
renderWithRouter(
229-
<QueryClientProviders>
230-
<ReduxIntlProviders>
231-
<ProjectDetailPage />
232-
</ReduxIntlProviders>
233-
</QueryClientProviders>,
234-
);
235-
await waitFor(() => {
236-
expect(screen.getByText(/sample project/i)).toBeInTheDocument();
237-
expect(screen.getByText(/hello world/i)).toBeInTheDocument();
238-
});
239-
});
240-
241-
it('should display private project error message', async () => {
242-
setupFaultyHandlers();
224+
/**
225+
* Set up a ProjectDetailPage given an initial entry; this avoids issues where there is no project id.
226+
* @param {Array<string>} initialEntries The initial entries. This should be in the form of `[projects/:id]`.
227+
*/
228+
function setup(initialEntries) {
243229
render(
244-
<MemoryRouter initialEntries={['/projects/123']}>
230+
<MemoryRouter initialEntries={initialEntries}>
245231
<Routes>
246232
<Route
247233
path="projects/:id"
@@ -256,6 +242,22 @@ describe('Project Detail Page', () => {
256242
</Routes>
257243
</MemoryRouter>,
258244
);
245+
}
246+
247+
it('should render component details', async () => {
248+
act(() => {
249+
store.dispatch({ type: 'SET_LOCALE', locale: 'es-AR' });
250+
});
251+
setup(['/projects/123']);
252+
await waitFor(() => {
253+
expect(screen.getByText(/sample project/i)).toBeInTheDocument();
254+
expect(screen.getByText(/hello world/i)).toBeInTheDocument();
255+
});
256+
});
257+
258+
it('should display private project error message', async () => {
259+
setupFaultyHandlers();
260+
setup(['/projects/123']);
259261

260262
await waitFor(() =>
261263
expect(

0 commit comments

Comments
 (0)