Skip to content

Commit 8e8c6de

Browse files
Task/WG-260 add map control bar (#303)
* Keep track of mouse position using context/hook * Add docstr * Add useFeatureLoadingState hook * Add map hooks to index * Add position tracker to Map * Add missing index * Update package-lock.json * Add useFeatureLoadingState to index * Add MapControlBar * Add hook to get projects users and use in control bar * Improve project errors and handle switching to private map * Add useDesignProject hook * Rework ds project type and fixture * Update package-lock.json after merge main * Rework styling/layout * update to new react-query and lint issues * Remove unused properties * Remove error as handled elswhere * Format file * Improve style * Rework useCurrentFeatures * Fix tests * Refactor return type of useCurrentFeatures * Update useCurrentFeatures test * Add tests * Add tests * Add usefull comment to see request mocks * Fix test issue * Fix some lint errors * Fix some lint warnings * Add package-lock * Refactor MapProjectAccessError into own file Simpilfy MapProject * Fix merge conflict resoltion errors * Update package-lock.json * Use antd Text Spacing and ellipses were broken with upstream changes; unclear if my previous styles were incorrect or imcompatible. * Update useDsProjects to useDesignSafeProjects
1 parent 8acdb9e commit 8e8c6de

36 files changed

+1129
-284
lines changed

react/jest.setup.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { testDevConfiguration } from '@hazmapper/__fixtures__/appConfigurationFixture';
2-
import { server } from '@hazmapper/test/testUtil';
2+
import { server, testQueryClient } from '@hazmapper/test/testUtil';
33

44
/***** A) Setup the configuration used for unit testing *****/
55
jest.mock('@hazmapper/hooks/environment/getLocalAppConfiguration', () => ({
@@ -56,6 +56,9 @@ export function shouldIgnoreError(args: any[]): boolean {
5656
/***** C) Setup testing and also ensure that we are mocking things in tests *****/
5757

5858
beforeAll(() => {
59+
// Uncomment next line to see all handlers
60+
// console.log('Registered handlers:', server.listHandlers());
61+
5962
// Establish mocking of APIs before all tests
6063
server.listen({
6164
onUnhandledRequest: 'error',
@@ -81,6 +84,11 @@ beforeAll(() => {
8184
});
8285
});
8386

87+
// Clear the React Query cache before each test
88+
beforeEach(() => {
89+
testQueryClient.clear();
90+
});
91+
8492
// Reset any runtime request handlers we may add during the tests
8593
afterEach(() => server.resetHandlers());
8694

react/package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/src/__fixtures__/projectFixtures.ts

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,80 @@ import {
55
ProjectRequest,
66
} from '../types';
77

8+
export const designSafeProjectMock: DesignSafeProject = {
9+
uuid: 'proj-uuid',
10+
name: 'designsafe.project',
11+
created: '2019-10-31T16:04:26.327Z',
12+
lastUpdated: '2019-10-31T16:04:30.163Z',
13+
associationIds: [],
14+
value: {
15+
dois: [],
16+
coPis: [],
17+
title: 'Sample DesignSafe Project',
18+
users: [
19+
{
20+
inst: 'University of Texas at Austin (utexas.edu)',
21+
role: 'pi',
22+
email: 'test1@test.com',
23+
fname: 'Fixture First Name',
24+
lname: 'Fixture Last Name',
25+
username: 'fixture1Username',
26+
},
27+
{
28+
inst: 'University of Texas at Austin (utexas.edu)',
29+
role: 'co_pi',
30+
email: 'test2@test.com',
31+
fname: 'Tester',
32+
lname: 'Test',
33+
username: 'fixture2Username',
34+
},
35+
],
36+
authors: [],
37+
frTypes: [],
38+
nhEvent: '',
39+
nhTypes: [],
40+
fileObjs: [],
41+
fileTags: [],
42+
keywords: [],
43+
nhEvents: [],
44+
dataTypes: [],
45+
projectId: 'proj-id',
46+
tombstone: false,
47+
facilities: [],
48+
nhLatitude: '',
49+
nhLocation: '',
50+
description: 'Map Test description required.',
51+
nhLongitude: '',
52+
projectType: 'None',
53+
teamMembers: [],
54+
awardNumbers: [],
55+
guestMembers: [],
56+
hazmapperMaps: [
57+
{
58+
name: 'Hazmapper_TestProject',
59+
path: '/',
60+
uuid: '620aeaf4-f813-4b90-ba52-bc87cfa7b07b',
61+
deployment: 'production',
62+
},
63+
],
64+
referencedData: [],
65+
associatedProjects: [],
66+
},
67+
};
68+
869
export const projectMock: Project = {
970
id: 1,
1071
uuid: 'abc123',
1172
name: 'Sample Project',
1273
description: 'A sample project for testing purposes.',
1374
public: true,
1475
system_file: 'sample-file',
15-
system_id: 'sample-id',
76+
system_id:
77+
'project-1234' /* 'project-' prefix implies its a DesignSafe project system */,
1678
system_path: '/path/to/sample',
1779
deletable: true,
1880
streetview_instances: null,
19-
ds_project: {
20-
uuid: 'proj-uuid',
21-
projectId: 'proj-id',
22-
title: 'Sample DesignSafe Project',
23-
value: {
24-
dois: [],
25-
coPis: [],
26-
title: 'Hazmapper V3 PROD Map Test 2024.08.07',
27-
users: [
28-
{
29-
inst: 'University of Texas at Austin (utexas.edu)',
30-
role: 'pi',
31-
email: 'test1@test.com',
32-
fname: 'Fixture First Name',
33-
lname: 'Fixture Last Name',
34-
username: 'fixture1Username',
35-
},
36-
{
37-
inst: 'University of Texas at Austin (utexas.edu)',
38-
role: 'co_pi',
39-
email: 'test2@test.com',
40-
fname: 'Tester',
41-
lname: 'Test',
42-
username: 'fixture2Username',
43-
},
44-
],
45-
authors: [],
46-
frTypes: [],
47-
nhEvent: '',
48-
nhTypes: [],
49-
fileObjs: [],
50-
fileTags: [],
51-
keywords: [],
52-
nhEvents: [],
53-
dataTypes: [],
54-
projectId: 'PRJ-5566',
55-
tombstone: false,
56-
facilities: [],
57-
nhLatitude: '',
58-
nhLocation: '',
59-
description: 'Map Test description required.',
60-
nhLongitude: '',
61-
projectType: 'None',
62-
teamMembers: [],
63-
awardNumbers: [],
64-
guestMembers: [],
65-
hazmapperMaps: [
66-
{
67-
name: 'Hazmapper_TestProject',
68-
path: '/',
69-
uuid: '620aeaf4-f813-4b90-ba52-bc87cfa7b07b',
70-
deployment: 'production',
71-
},
72-
],
73-
referencedData: [],
74-
associatedProjects: [],
75-
},
76-
},
77-
};
78-
79-
export const designSafeProjectMock: DesignSafeProject = {
80-
uuid: 'proj-uuid',
81-
projectId: 'proj-id',
82-
title: 'Sample DesignSafe Project',
83-
value: {},
81+
ds_project: designSafeProjectMock,
8482
};
8583

8684
export const designSafeProjectCollectionMock: DesignSafeProjectCollection = {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const users = [{ id: 1, username: 'user' }];

react/src/components/FeatureFileTree/FeatureFileTree.test.tsx

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { fireEvent, waitFor } from '@testing-library/react';
2+
import { fireEvent, waitFor, act } from '@testing-library/react';
33
import { http, HttpResponse } from 'msw';
44
import FeatureFileTree from './FeatureFileTree';
55
import { server, renderInTest } from '@hazmapper/test/testUtil';
@@ -24,11 +24,13 @@ describe('FeatureFileTree', () => {
2424
jest.clearAllMocks();
2525
});
2626

27-
it('renders feature list correctly', () => {
28-
const { getByText } = renderInTest(
29-
<FeatureFileTree {...defaultTreeProps} />
30-
);
27+
it('renders feature list correctly', async () => {
28+
let rendered;
29+
await act(async () => {
30+
rendered = renderInTest(<FeatureFileTree {...defaultTreeProps} />);
31+
});
3132

33+
const { getByText } = rendered;
3234
expect(getByText('foo')).toBeDefined();
3335
expect(getByText('image1.JPG')).toBeDefined();
3436
expect(getByText('image2.JPG')).toBeDefined();
@@ -48,37 +50,51 @@ describe('FeatureFileTree', () => {
4850
)
4951
);
5052

51-
const { getByTestId } = renderInTest(
52-
<FeatureFileTree {...defaultTreeProps} />,
53-
`/?selectedFeature=${featureId}`
54-
);
53+
let rendered;
54+
await act(async () => {
55+
rendered = renderInTest(
56+
<FeatureFileTree {...defaultTreeProps} />,
57+
`/?selectedFeature=${featureId}`
58+
);
59+
});
5560

5661
// Find and click delete button (as featured is selected)
62+
const { getByTestId } = rendered;
5763
const deleteButton = getByTestId('delete-feature-button');
58-
fireEvent.click(deleteButton);
64+
await act(async () => {
65+
fireEvent.click(deleteButton);
66+
});
5967

6068
await waitFor(() => {
6169
expect(wasDeleted).toBeTruthy();
6270
});
6371
});
6472

65-
it('does not show delete button for public projects', () => {
66-
const { queryByTestId } = renderInTest(
67-
<FeatureFileTree {...defaultTreeProps} isPublicView={true} />,
68-
'/?selectedFeature=1'
69-
);
73+
it('does not show delete button for public projects', async () => {
74+
let rendered;
75+
await act(async () => {
76+
rendered = renderInTest(
77+
<FeatureFileTree {...defaultTreeProps} isPublicView={true} />,
78+
'/?selectedFeature=1'
79+
);
80+
});
7081

7182
// Verify delete button is not present
83+
const { queryByTestId } = rendered;
7284
const deleteButton = queryByTestId('delete-feature-button');
7385
expect(deleteButton).toBeNull();
7486
});
7587

76-
it('does not show delete button when no feature is selected', () => {
77-
const { queryByTestId } = renderInTest(
78-
<FeatureFileTree {...defaultTreeProps} isPublicView={false} />
79-
);
88+
it('does not show delete button when no feature is selected', async () => {
89+
let rendered;
90+
await act(async () => {
91+
rendered = renderInTest(
92+
<FeatureFileTree {...defaultTreeProps} isPublicView={false} />
93+
);
94+
});
8095

8196
// Verify delete button is not present
97+
const { queryByTestId } = rendered;
8298
const deleteButton = queryByTestId('delete-feature-button');
8399
expect(deleteButton).toBeNull();
84100
});

react/src/components/Files/FileListing.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FileListing } from './FileListing';
44
import {
55
useFiles,
66
useAuthenticatedUser,
7-
useDsProjects,
7+
useDesignSafeProjects,
88
useSystems,
99
} from '../../hooks';
1010
import { serializeToChonkyFile } from '../../utils/fileUtils';
@@ -16,7 +16,7 @@ jest.mock('../../hooks', () => ({
1616
data: [],
1717
refetch: jest.fn(),
1818
})),
19-
useDsProjects: jest.fn(() => ({ result: [] })),
19+
useDesignSafeProjects: jest.fn(() => ({ result: [] })),
2020
useAuthenticatedUser: jest.fn(() => ({ data: { username: 'test-user' } })),
2121
useSystems: jest.fn(() => ({ data: [] })),
2222
}));
@@ -43,7 +43,7 @@ describe('FileListing', () => {
4343

4444
it('renders without crashing and displays "No systems available" if no systems are returned', () => {
4545
(useSystems as jest.Mock).mockReturnValue({ data: [], myDataSystem: null });
46-
(useDsProjects as jest.Mock).mockReturnValue({
46+
(useDesignSafeProjects as jest.Mock).mockReturnValue({
4747
result: [],
4848
});
4949
(useAuthenticatedUser as jest.Mock).mockReturnValue({
@@ -66,7 +66,7 @@ describe('FileListing', () => {
6666
data: [],
6767
refetch: jest.fn(),
6868
});
69-
(useDsProjects as jest.Mock).mockReturnValue({
69+
(useDesignSafeProjects as jest.Mock).mockReturnValue({
7070
data: [],
7171
});
7272
(useAuthenticatedUser as jest.Mock).mockReturnValue({
@@ -90,7 +90,7 @@ describe('FileListing', () => {
9090
data: [],
9191
refetch: jest.fn(),
9292
});
93-
(useDsProjects as jest.Mock).mockReturnValue({
93+
(useDesignSafeProjects as jest.Mock).mockReturnValue({
9494
data: [],
9595
});
9696
(useAuthenticatedUser as jest.Mock).mockReturnValue({
@@ -131,7 +131,7 @@ describe('FileListing', () => {
131131
refetch: jest.fn(),
132132
});
133133

134-
(useDsProjects as jest.Mock).mockReturnValue({
134+
(useDesignSafeProjects as jest.Mock).mockReturnValue({
135135
data: [],
136136
});
137137

@@ -175,7 +175,7 @@ describe('FileListing', () => {
175175
refetch: jest.fn(),
176176
});
177177

178-
(useDsProjects as jest.Mock).mockReturnValue({
178+
(useDesignSafeProjects as jest.Mock).mockReturnValue({
179179
data: [],
180180
});
181181

react/src/components/Map/Map.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { renderInTest } from '@hazmapper/test/testUtil';
33
import Map from './Map';
44
import { tileServerLayers } from '../../__fixtures__/tileServerLayerFixture';
55
import { featureCollection } from '../../__fixtures__/featuresFixture';
6+
import { MapPositionProvider } from '@hazmapper/context/MapContext';
67
import { useForm, FormProvider } from 'react-hook-form';
78
import * as z from 'zod';
89
import { zodResolver } from '@hookform/resolvers/zod';
@@ -26,7 +27,9 @@ test('renders map', () => {
2627

2728
return (
2829
<FormProvider {...methods}>
29-
<Map featureCollection={featureCollection} />
30+
<MapPositionProvider>
31+
<Map featureCollection={featureCollection} />
32+
</MapPositionProvider>
3033
</FormProvider>
3134
);
3235
};

0 commit comments

Comments
 (0)