-
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.
BHBC-1972: Delete a Draft Project (#837)
- Loading branch information
Showing
5 changed files
with
251 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ const mockUseBiohubApi = { | |
draft: { | ||
createDraft: jest.fn<Promise<object>, []>(), | ||
updateDraft: jest.fn<Promise<object>, []>(), | ||
deleteDraft: jest.fn(), | ||
getDraft: jest.fn() | ||
}, | ||
external: { | ||
|
@@ -174,6 +175,190 @@ describe('CreateProjectPage', () => { | |
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe('Delete Draft Button', () => { | ||
it('does not display delete draft button if not in draft', async () => { | ||
const { queryByText } = render( | ||
<MemoryRouter> | ||
<CreateProjectPage /> | ||
</MemoryRouter> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(queryByText('Delete Draft', { exact: false })).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('does display delete draft button if in draft', async () => { | ||
mockBiohubApi().codes.getAllCodeSets.mockResolvedValue(({ | ||
coordinator_agency: [{ id: 1, name: 'A Rocha Canada' }] | ||
} as unknown) as IGetAllCodeSetsResponse); | ||
|
||
mockBiohubApi().draft.getDraft.mockResolvedValue({ | ||
id: 1, | ||
name: 'My draft', | ||
data: { | ||
coordinator: { | ||
first_name: 'Draft first name', | ||
last_name: 'Draft last name', | ||
email_address: '[email protected]', | ||
coordinator_agency: '', | ||
share_contact_details: 'false' | ||
}, | ||
project: ProjectDetailsFormInitialValues.project, | ||
objectives: ProjectObjectivesFormInitialValues.objectives, | ||
location: ProjectLocationFormInitialValues.location, | ||
iucn: ProjectIUCNFormInitialValues.iucn, | ||
funding: ProjectFundingFormInitialValues.funding, | ||
partnerships: ProjectPartnershipsFormInitialValues.partnerships | ||
} | ||
}); | ||
|
||
const { queryAllByText } = render( | ||
<MemoryRouter initialEntries={['?draftId=1']}> | ||
<CreateProjectPage /> | ||
</MemoryRouter> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(queryAllByText('Delete Draft', { exact: false }).length).toEqual(2); | ||
}); | ||
}); | ||
|
||
it('dispalys a Delete draft Yes/No Dialog', async () => { | ||
mockBiohubApi().codes.getAllCodeSets.mockResolvedValue(({ | ||
coordinator_agency: [{ id: 1, name: 'A Rocha Canada' }] | ||
} as unknown) as IGetAllCodeSetsResponse); | ||
|
||
mockBiohubApi().draft.getDraft.mockResolvedValue({ | ||
id: 1, | ||
name: 'My draft', | ||
data: { | ||
coordinator: { | ||
first_name: 'Draft first name', | ||
last_name: 'Draft last name', | ||
email_address: '[email protected]', | ||
coordinator_agency: '', | ||
share_contact_details: 'false' | ||
}, | ||
project: ProjectDetailsFormInitialValues.project, | ||
objectives: ProjectObjectivesFormInitialValues.objectives, | ||
location: ProjectLocationFormInitialValues.location, | ||
iucn: ProjectIUCNFormInitialValues.iucn, | ||
funding: ProjectFundingFormInitialValues.funding, | ||
partnerships: ProjectPartnershipsFormInitialValues.partnerships | ||
} | ||
}); | ||
|
||
const { getByText, findAllByText } = render( | ||
<MemoryRouter initialEntries={['?draftId=1']}> | ||
<CreateProjectPage /> | ||
</MemoryRouter> | ||
); | ||
|
||
const deleteButton = await findAllByText('Delete Draft', { exact: false }); | ||
|
||
fireEvent.click(deleteButton[0]); | ||
|
||
await waitFor(() => { | ||
expect(getByText('Are you sure you want to delete this draft?', { exact: false })).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('closes dialog on No click', async () => { | ||
mockBiohubApi().codes.getAllCodeSets.mockResolvedValue(({ | ||
coordinator_agency: [{ id: 1, name: 'A Rocha Canada' }] | ||
} as unknown) as IGetAllCodeSetsResponse); | ||
|
||
mockBiohubApi().draft.getDraft.mockResolvedValue({ | ||
id: 1, | ||
name: 'My draft', | ||
data: { | ||
coordinator: { | ||
first_name: 'Draft first name', | ||
last_name: 'Draft last name', | ||
email_address: '[email protected]', | ||
coordinator_agency: '', | ||
share_contact_details: 'false' | ||
}, | ||
project: ProjectDetailsFormInitialValues.project, | ||
objectives: ProjectObjectivesFormInitialValues.objectives, | ||
location: ProjectLocationFormInitialValues.location, | ||
iucn: ProjectIUCNFormInitialValues.iucn, | ||
funding: ProjectFundingFormInitialValues.funding, | ||
partnerships: ProjectPartnershipsFormInitialValues.partnerships | ||
} | ||
}); | ||
|
||
const { getByText, findAllByText, getByTestId, queryByText } = render( | ||
<MemoryRouter initialEntries={['?draftId=1']}> | ||
<CreateProjectPage /> | ||
</MemoryRouter> | ||
); | ||
|
||
const deleteButton = await findAllByText('Delete Draft', { exact: false }); | ||
|
||
fireEvent.click(deleteButton[0]); | ||
|
||
await waitFor(() => { | ||
expect(getByText('Are you sure you want to delete this draft?')).toBeInTheDocument(); | ||
}); | ||
|
||
const NoButton = await getByTestId('no-button'); | ||
fireEvent.click(NoButton); | ||
|
||
await waitFor(() => { | ||
expect(queryByText('Are you sure you want to delete this draft?')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('deletes draft on Yes click', async () => { | ||
mockBiohubApi().codes.getAllCodeSets.mockResolvedValue(({ | ||
coordinator_agency: [{ id: 1, name: 'A Rocha Canada' }] | ||
} as unknown) as IGetAllCodeSetsResponse); | ||
|
||
mockBiohubApi().draft.getDraft.mockResolvedValue({ | ||
id: 1, | ||
name: 'My draft', | ||
data: { | ||
coordinator: { | ||
first_name: 'Draft first name', | ||
last_name: 'Draft last name', | ||
email_address: '[email protected]', | ||
coordinator_agency: '', | ||
share_contact_details: 'false' | ||
}, | ||
project: ProjectDetailsFormInitialValues.project, | ||
objectives: ProjectObjectivesFormInitialValues.objectives, | ||
location: ProjectLocationFormInitialValues.location, | ||
iucn: ProjectIUCNFormInitialValues.iucn, | ||
funding: ProjectFundingFormInitialValues.funding, | ||
partnerships: ProjectPartnershipsFormInitialValues.partnerships | ||
} | ||
}); | ||
|
||
const { getByText, findAllByText, getByTestId } = render( | ||
<MemoryRouter initialEntries={['?draftId=1']}> | ||
<CreateProjectPage /> | ||
</MemoryRouter> | ||
); | ||
|
||
const deleteButton = await findAllByText('Delete Draft', { exact: false }); | ||
|
||
fireEvent.click(deleteButton[0]); | ||
|
||
await waitFor(() => { | ||
expect(getByText('Are you sure you want to delete this draft?')).toBeInTheDocument(); | ||
}); | ||
|
||
const YesButton = await getByTestId('yes-button'); | ||
fireEvent.click(YesButton); | ||
|
||
await waitFor(() => { | ||
expect(mockBiohubApi().draft.deleteDraft).toBeCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('preloads draft data and populates on form fields', async () => { | ||
mockBiohubApi().codes.getAllCodeSets.mockResolvedValue(({ | ||
coordinator_agency: [{ id: 1, name: 'A Rocha Canada' }] | ||
|
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