-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and clean up code duplication (#140)
* refactor and clean up code duplication * more refactoring * remove map as separate link in header
- Loading branch information
1 parent
1b2a3f1
commit bb4eb80
Showing
14 changed files
with
77 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,12 @@ | ||
import { render } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import { IProjectWithDetails } from 'interfaces/project-interfaces'; | ||
import { projectWithDetailsData } from 'test-helpers/projectWithDetailsData'; | ||
import React from 'react'; | ||
import { Router } from 'react-router'; | ||
import ProjectAttachments from './ProjectAttachments'; | ||
|
||
const history = createMemoryHistory(); | ||
|
||
const projectWithDetailsData: IProjectWithDetails = { | ||
id: 1, | ||
project: { | ||
project_name: 'Test Project Name', | ||
project_type: '1', | ||
start_date: '1998-10-10', | ||
end_date: '2021-02-26', | ||
climate_change_initiatives: [], | ||
project_activities: [] | ||
}, | ||
location: { | ||
location_description: 'here and there', | ||
regions: [], | ||
geometry: [] | ||
}, | ||
objectives: { | ||
objectives: 'Et ad et in culpa si', | ||
caveats: 'sjwer bds' | ||
}, | ||
coordinator: { | ||
first_name: 'Amanda', | ||
last_name: 'Christensen', | ||
email_address: '[email protected]', | ||
coordinator_agency: 'Amanda and associates', | ||
share_contact_details: 'true' | ||
} | ||
}; | ||
|
||
describe('ProjectAttachments', () => { | ||
it('renders correctly', () => { | ||
const { asFragment } = render( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,23 @@ | ||
import { render } from '@testing-library/react'; | ||
import { IProjectWithDetails } from 'interfaces/project-interfaces'; | ||
import { IGetAllCodesResponse } from 'interfaces/useBioHubApi-interfaces'; | ||
import { codes } from 'test-helpers/projectCodes'; | ||
import { projectWithDetailsData } from 'test-helpers/projectWithDetailsData'; | ||
import React from 'react'; | ||
import ProjectDetails from './ProjectDetails'; | ||
|
||
const projectWithDetailsData: IProjectWithDetails = { | ||
id: 1, | ||
project: { | ||
project_name: 'Test Project Name', | ||
project_type: '1', | ||
start_date: '1998-10-10', | ||
end_date: '2021-02-26', | ||
climate_change_initiatives: [1], | ||
project_activities: [1] | ||
}, | ||
location: { | ||
location_description: 'here and there', | ||
regions: [], | ||
geometry: [ | ||
{ | ||
id: 'myGeo', | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [125.6, 10.1] | ||
}, | ||
properties: { | ||
name: 'Dinagat Islands' | ||
} | ||
} | ||
] | ||
}, | ||
objectives: { | ||
objectives: 'Et ad et in culpa si', | ||
caveats: 'sjwer bds' | ||
}, | ||
|
||
coordinator: { | ||
first_name: 'Amanda', | ||
last_name: 'Christensen', | ||
email_address: '[email protected]', | ||
coordinator_agency: 'Amanda and associates', | ||
share_contact_details: 'true' | ||
} | ||
}; | ||
|
||
const codes: IGetAllCodesResponse = { | ||
coordinator_agency: [], | ||
management_action_type: [], | ||
climate_change_initiative: [{ id: 1, name: 'climate code' }], | ||
first_nations: [], | ||
funding_source: [], | ||
investment_action_category: [], | ||
activity: [{ id: 1, name: 'activity code' }], | ||
project_type: [], | ||
region: [], | ||
species: [], | ||
iucn_conservation_action_level_1_classification: [], | ||
iucn_conservation_action_level_2_subclassification: [], | ||
iucn_conservation_action_level_3_subclassification: [] | ||
}; | ||
|
||
describe('ProjectDetails', () => { | ||
it('renders correctly', () => { | ||
projectWithDetailsData.location.geometry.push({ | ||
id: 'myGeo', | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [125.6, 10.1] | ||
}, | ||
properties: { | ||
name: 'Dinagat Islands' | ||
} | ||
}); | ||
|
||
const { asFragment } = render(<ProjectDetails projectWithDetailsData={projectWithDetailsData} codes={codes} />); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { createMemoryHistory } from 'history'; | |
import { useBiohubApi } from 'hooks/useBioHubApi'; | ||
import { IProjectWithDetails } from 'interfaces/project-interfaces'; | ||
import { IGetAllCodesResponse } from 'interfaces/useBioHubApi-interfaces'; | ||
import { projectWithDetailsData } from 'test-helpers/projectWithDetailsData'; | ||
import React from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { Router } from 'react-router'; | ||
|
@@ -43,33 +44,7 @@ describe('ProjectPage', () => { | |
|
||
it('renders project page when project is loaded', async () => { | ||
await act(async () => { | ||
mockBiohubApi().getProject.mockResolvedValue({ | ||
id: 1, | ||
project: { | ||
project_name: 'Test Project Name', | ||
project_type: '1', | ||
start_date: '1998-10-10', | ||
end_date: '2021-02-26', | ||
climate_change_initiatives: [], | ||
project_activities: [] | ||
}, | ||
location: { | ||
location_description: 'here and there', | ||
regions: [], | ||
geometry: [] | ||
}, | ||
objectives: { | ||
objectives: 'Et ad et in culpa si', | ||
caveats: 'sjwer bds' | ||
}, | ||
coordinator: { | ||
first_name: 'Amanda', | ||
last_name: 'Christensen', | ||
email_address: '[email protected]', | ||
coordinator_agency: 'Amanda and associates', | ||
share_contact_details: 'true' | ||
} | ||
}); | ||
mockBiohubApi().getProject.mockResolvedValue(projectWithDetailsData); | ||
|
||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
activity: [{ id: 1, name: 'activity 1' }], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 2 additions & 47 deletions
49
app/src/features/projects/view/components/GeneralInformation.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,9 @@ | ||
import { render } from '@testing-library/react'; | ||
import { IProjectWithDetails } from 'interfaces/project-interfaces'; | ||
import { IGetAllCodesResponse } from 'interfaces/useBioHubApi-interfaces'; | ||
import { projectWithDetailsData } from 'test-helpers/projectWithDetailsData'; | ||
import { codes } from 'test-helpers/projectCodes'; | ||
import React from 'react'; | ||
import GeneralInformation from './GeneralInformation'; | ||
|
||
const projectWithDetailsData: IProjectWithDetails = { | ||
id: 1, | ||
project: { | ||
project_name: 'Test Project Name', | ||
project_type_name: 'Type name', | ||
project_type: '1', | ||
start_date: '1998-10-10', | ||
end_date: '2021-02-26', | ||
climate_change_initiatives: [1], | ||
project_activities: [1] | ||
}, | ||
location: { | ||
location_description: 'here and there', | ||
regions: [], | ||
geometry: [] | ||
}, | ||
objectives: { | ||
objectives: 'Et ad et in culpa si', | ||
caveats: 'sjwer bds' | ||
}, | ||
coordinator: { | ||
first_name: 'Amanda', | ||
last_name: 'Christensen', | ||
email_address: '[email protected]', | ||
coordinator_agency: 'Amanda and associates', | ||
share_contact_details: 'true' | ||
} | ||
}; | ||
|
||
const codes: IGetAllCodesResponse = { | ||
coordinator_agency: [], | ||
management_action_type: [], | ||
climate_change_initiative: [{ id: 1, name: 'climate code' }], | ||
first_nations: [], | ||
funding_source: [], | ||
investment_action_category: [], | ||
activity: [{ id: 1, name: 'activity code' }], | ||
project_type: [], | ||
region: [], | ||
species: [], | ||
iucn_conservation_action_level_1_classification: [], | ||
iucn_conservation_action_level_2_subclassification: [], | ||
iucn_conservation_action_level_3_subclassification: [] | ||
}; | ||
|
||
describe('GeneralInformation', () => { | ||
it('renders correctly', () => { | ||
const { asFragment } = render(<GeneralInformation projectWithDetailsData={projectWithDetailsData} codes={codes} />); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 1 addition & 30 deletions
31
app/src/features/projects/view/components/ProjectCoordinator.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,8 @@ | ||
import { render } from '@testing-library/react'; | ||
import { IProjectWithDetails } from 'interfaces/project-interfaces'; | ||
import { projectWithDetailsData } from 'test-helpers/projectWithDetailsData'; | ||
import React from 'react'; | ||
import ProjectCoordinator from './ProjectCoordinator'; | ||
|
||
const projectWithDetailsData: IProjectWithDetails = { | ||
id: 1, | ||
project: { | ||
project_name: 'Test Project Name', | ||
project_type_name: 'Type name', | ||
project_type: '1', | ||
start_date: '1998-10-10', | ||
end_date: '2021-02-26', | ||
climate_change_initiatives: [1], | ||
project_activities: [1] | ||
}, | ||
location: { | ||
location_description: 'here and there', | ||
regions: [], | ||
geometry: [] | ||
}, | ||
objectives: { | ||
objectives: 'Et ad et in culpa si', | ||
caveats: 'sjwer bds' | ||
}, | ||
coordinator: { | ||
first_name: 'Amanda', | ||
last_name: 'Christensen', | ||
email_address: '[email protected]', | ||
coordinator_agency: 'Amanda and associates', | ||
share_contact_details: 'true' | ||
} | ||
}; | ||
|
||
describe('ProjectCoordinator', () => { | ||
it('renders correctly', () => { | ||
const { asFragment } = render(<ProjectCoordinator projectWithDetailsData={projectWithDetailsData} />); | ||
|
Oops, something went wrong.