-
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-865: Create project workflow updates based on permits + misc (#107)
* BHBC-865: Create project workflow updates based on permits + misc * BHBC-865: Test updates * BHBC-865: Update button styling on final create project step
- Loading branch information
Showing
20 changed files
with
3,942 additions
and
2,202 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// __mocks__/popper.js.js | ||
|
||
// mocks will be picked up by Jest and applied automatically. | ||
// Required to make the material-ui select/autocomplete components work during unit tests | ||
// See https://stackoverflow.com/questions/60333156/how-to-fix-typeerror-document-createrange-is-not-a-function-error-while-testi | ||
|
||
import PopperJs from 'popper.js'; | ||
|
||
export default class Popper { | ||
constructor() { | ||
this.placements = PopperJs.placements; | ||
|
||
return { | ||
update: () => {}, | ||
destroy: () => {}, | ||
scheduleUpdate: () => {} | ||
}; | ||
} | ||
} |
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,17 +1,14 @@ | ||
import { cleanup, findByText as rawFindByText, fireEvent, render } from '@testing-library/react'; | ||
import { cleanup, findByText as rawFindByText, fireEvent, render, waitFor } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import { useBiohubApi } from 'hooks/useBioHubApi'; | ||
import { ICreateProjectResponse } from 'interfaces/useBioHubApi-interfaces'; | ||
import React from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { Router } from 'react-router'; | ||
import CreateProjectPage from './CreateProjectPage'; | ||
|
||
const history = createMemoryHistory(); | ||
|
||
jest.mock('../../hooks/useBioHubApi'); | ||
const mockUseBiohubApi = { | ||
createProject: jest.fn<Promise<ICreateProjectResponse>, []>(), | ||
getAllCodes: jest.fn<Promise<object>, []>() | ||
}; | ||
|
||
|
@@ -30,96 +27,134 @@ const renderContainer = () => { | |
describe('CreateProjectPage', () => { | ||
beforeEach(() => { | ||
// clear mocks before each test | ||
mockBiohubApi().createProject.mockClear(); | ||
mockBiohubApi().getAllCodes.mockClear(); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('shows the page title', async () => { | ||
await act(async () => { | ||
mockBiohubApi().createProject.mockResolvedValue({ | ||
id: 100 | ||
}); | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
const { findByText } = renderContainer(); | ||
const PageTitle = await findByText('Create Project'); | ||
it('renders the initial default page correctly', async () => { | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
const { getByText, asFragment } = renderContainer(); | ||
|
||
expect(PageTitle).toBeVisible(); | ||
await waitFor(() => { | ||
expect(getByText('Project Coordinator')).toBeVisible(); | ||
|
||
expect(getByText('Permits')).toBeVisible(); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
it('adds the extra create project steps if at least 1 permit is marked as having conducted sampling', async () => { | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
coordinator_agency: [{ id: 1, name: 'code 1' }] | ||
}); | ||
const { findByText, asFragment, getByText, getByTestId, getByLabelText } = renderContainer(); | ||
|
||
// wait for project coordinator form to load | ||
expect(await findByText('First Name')).toBeVisible(); | ||
|
||
fireEvent.change(getByLabelText('First Name *'), { target: { value: 'first name' } }); | ||
fireEvent.change(getByLabelText('Last Name *'), { target: { value: 'last name' } }); | ||
fireEvent.change(getByLabelText('Business Email Address *'), { target: { value: '[email protected]' } }); | ||
fireEvent.change(getByLabelText('Coordinator Agency *'), { target: { value: 'agency name' } }); | ||
|
||
fireEvent.click(getByText('Next')); | ||
|
||
// wait for permit form to load | ||
expect(await findByText('Add Another')).toBeVisible(); | ||
|
||
fireEvent.change(getByLabelText('Permit Number *'), { target: { value: 12345 } }); | ||
fireEvent.change(getByTestId('sampling_conducted'), { target: { value: 'true' } }); | ||
|
||
// wait for forms to load | ||
await waitFor(() => { | ||
expect(getByText('General Information')).toBeVisible(); | ||
|
||
expect(getByText('Project Coordinator')).toBeVisible(); | ||
|
||
expect(getByText('Permits')).toBeVisible(); | ||
|
||
expect(getByText('General Information')).toBeVisible(); | ||
|
||
expect(getByText('Objectives')).toBeVisible(); | ||
|
||
expect(getByText('Location')).toBeVisible(); | ||
|
||
expect(getByText('Species')).toBeVisible(); | ||
|
||
expect(getByText('Funding and Partnerships')).toBeVisible(); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
it('shows the page title', async () => { | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
const { findByText } = renderContainer(); | ||
const PageTitle = await findByText('Create Project'); | ||
|
||
expect(PageTitle).toBeVisible(); | ||
}); | ||
|
||
describe('Are you sure? Dialog', () => { | ||
it('shows warning dialog if the user clicks the `Cancel and Exit` button', async () => { | ||
await act(async () => { | ||
mockBiohubApi().createProject.mockResolvedValue({ | ||
id: 100 | ||
}); | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
history.push('/home'); | ||
history.push('/projects/create'); | ||
const { findByText, getByRole } = renderContainer(); | ||
const BackToProjectsButton = await findByText('Cancel and Exit', { exact: false }); | ||
|
||
fireEvent.click(BackToProjectsButton); | ||
const AreYouSureTitle = await findByText('Cancel Create Project'); | ||
const AreYouSureText = await findByText('Are you sure you want to cancel?'); | ||
const AreYouSureYesButton = await rawFindByText(getByRole('dialog'), 'Yes', { exact: false }); | ||
|
||
expect(AreYouSureTitle).toBeVisible(); | ||
expect(AreYouSureText).toBeVisible(); | ||
expect(AreYouSureYesButton).toBeVisible(); | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
history.push('/home'); | ||
history.push('/projects/create'); | ||
const { findByText, getByRole } = renderContainer(); | ||
const BackToProjectsButton = await findByText('Cancel and Exit', { exact: false }); | ||
|
||
fireEvent.click(BackToProjectsButton); | ||
const AreYouSureTitle = await findByText('Cancel Create Project'); | ||
const AreYouSureText = await findByText('Are you sure you want to cancel?'); | ||
const AreYouSureYesButton = await rawFindByText(getByRole('dialog'), 'Yes', { exact: false }); | ||
|
||
expect(AreYouSureTitle).toBeVisible(); | ||
expect(AreYouSureText).toBeVisible(); | ||
expect(AreYouSureYesButton).toBeVisible(); | ||
}); | ||
|
||
it('it calls history.push() if the user clicks `Yes`', async () => { | ||
await act(async () => { | ||
mockBiohubApi().createProject.mockResolvedValue({ | ||
id: 100 | ||
}); | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
history.push('/home'); | ||
history.push('/projects/create'); | ||
const { findByText, getByRole } = renderContainer(); | ||
const BackToProjectsButton = await findByText('Cancel and Exit', { exact: false }); | ||
|
||
fireEvent.click(BackToProjectsButton); | ||
const AreYouSureYesButton = await rawFindByText(getByRole('dialog'), 'Yes', { exact: false }); | ||
|
||
expect(history.location.pathname).toEqual('/projects/create'); | ||
fireEvent.click(AreYouSureYesButton); | ||
expect(history.location.pathname).toEqual('/projects'); | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
history.push('/home'); | ||
history.push('/projects/create'); | ||
const { findByText, getByRole } = renderContainer(); | ||
const BackToProjectsButton = await findByText('Cancel and Exit', { exact: false }); | ||
|
||
fireEvent.click(BackToProjectsButton); | ||
const AreYouSureYesButton = await rawFindByText(getByRole('dialog'), 'Yes', { exact: false }); | ||
|
||
expect(history.location.pathname).toEqual('/projects/create'); | ||
fireEvent.click(AreYouSureYesButton); | ||
expect(history.location.pathname).toEqual('/projects'); | ||
}); | ||
|
||
it('it does nothing if the user clicks `No`', async () => { | ||
await act(async () => { | ||
mockBiohubApi().createProject.mockResolvedValue({ | ||
id: 100 | ||
}); | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
history.push('/home'); | ||
history.push('/projects/create'); | ||
const { findByText, getByRole } = renderContainer(); | ||
const BackToProjectsButton = await findByText('Cancel and Exit', { exact: false }); | ||
|
||
fireEvent.click(BackToProjectsButton); | ||
const AreYouSureNoButton = await rawFindByText(getByRole('dialog'), 'No', { exact: false }); | ||
|
||
expect(history.location.pathname).toEqual('/projects/create'); | ||
fireEvent.click(AreYouSureNoButton); | ||
expect(history.location.pathname).toEqual('/projects/create'); | ||
mockBiohubApi().getAllCodes.mockResolvedValue({ | ||
code_set: [] | ||
}); | ||
history.push('/home'); | ||
history.push('/projects/create'); | ||
const { findByText, getByRole } = renderContainer(); | ||
const BackToProjectsButton = await findByText('Cancel and Exit', { exact: false }); | ||
|
||
fireEvent.click(BackToProjectsButton); | ||
const AreYouSureNoButton = await rawFindByText(getByRole('dialog'), 'No', { exact: false }); | ||
|
||
expect(history.location.pathname).toEqual('/projects/create'); | ||
fireEvent.click(AreYouSureNoButton); | ||
expect(history.location.pathname).toEqual('/projects/create'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.