Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #238 from kcdraidgroup/revert-228-tigerabrodi-repo…
Browse files Browse the repository at this point in the history
…rt-incident-test

Revert "test(report-incident): improvements"
  • Loading branch information
JacobMGEvans committed Jan 7, 2021
2 parents e94d817 + f3139e8 commit 8693002
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/__tests__/incidents/report/ReportIncident.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { render as rtlRender, screen } from '@testing-library/react'
/* eslint-disable no-console */
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { createMemoryHistory } from 'history'
import React, { ReactNode } from 'react'
import React from 'react'
import { Provider } from 'react-redux'
import { Route, Router } from 'react-router-dom'
import createMockStore from 'redux-mock-store'
Expand All @@ -18,11 +19,6 @@ import { expectOneConsoleError } from '../../test-utils/console.utils'

const mockStore = createMockStore<RootState, any>([thunk])

type WrapperProps = {
// eslint-disable-next-line react/require-default-props
children?: ReactNode
}

describe('Report Incident', () => {
let history: any

Expand All @@ -31,7 +27,7 @@ describe('Report Incident', () => {
})

let setButtonToolBarSpy: any
const render = (permissions: Permissions[]) => {
const setup = (permissions: Permissions[]) => {
jest.spyOn(breadcrumbUtil, 'default')
setButtonToolBarSpy = jest.fn()
jest.spyOn(ButtonBarProvider, 'useButtonToolbarSetter').mockReturnValue(setButtonToolBarSpy)
Expand All @@ -47,24 +43,22 @@ describe('Report Incident', () => {
},
} as any)

function Wrapper({ children }: WrapperProps) {
return (
<ButtonBarProvider.ButtonBarProvider>
<Provider store={store}>
<Router history={history}>
<Route path="/incidents/new">
<titleUtil.TitleProvider> {children} </titleUtil.TitleProvider>
</Route>
</Router>
</Provider>
</ButtonBarProvider.ButtonBarProvider>
)
}

return rtlRender(<ReportIncident />, { wrapper: Wrapper })
return render(
<ButtonBarProvider.ButtonBarProvider>
<Provider store={store}>
<Router history={history}>
<Route path="/incidents/new">
<titleUtil.TitleProvider>
<ReportIncident />
</titleUtil.TitleProvider>
</Route>
</Router>
</Provider>
</ButtonBarProvider.ButtonBarProvider>,
)
}
test('type into department field', async () => {
render([Permissions.ViewIncident, Permissions.ResolveIncident])
setup([Permissions.ViewIncident, Permissions.ResolveIncident])
const depInput = await screen.findByPlaceholderText(/incidents\.reports\.department/i)

expect(depInput).toBeEnabled()
Expand All @@ -75,7 +69,7 @@ describe('Report Incident', () => {
})

test('type into category field', async () => {
render([Permissions.ViewIncident, Permissions.ResolveIncident])
setup([Permissions.ViewIncident, Permissions.ResolveIncident])
const catInput = await screen.findByPlaceholderText(/incidents\.reports\.category\b/i)

expect(catInput).toBeEnabled()
Expand All @@ -86,7 +80,7 @@ describe('Report Incident', () => {
})

test('type into category item field', async () => {
render([Permissions.ViewIncident, Permissions.ResolveIncident])
setup([Permissions.ViewIncident, Permissions.ResolveIncident])
const catItemInput = await screen.findByPlaceholderText(/incidents\.reports\.categoryitem/i)

expect(catItemInput).toBeInTheDocument()
Expand All @@ -97,7 +91,7 @@ describe('Report Incident', () => {
})

test('type into description field', async () => {
render([Permissions.ViewIncident, Permissions.ResolveIncident])
setup([Permissions.ViewIncident, Permissions.ResolveIncident])
const inputArr = await screen.findAllByRole('textbox', { name: /required/i })
const descInput = inputArr[inputArr.length - 1]

Expand All @@ -108,7 +102,7 @@ describe('Report Incident', () => {
expect(descInput).toHaveDisplayValue('Geordi requested analysis')
})
test('action save after all the input fields are filled out', async () => {
render([Permissions.ViewIncident, Permissions.ResolveIncident])
setup([Permissions.ViewIncident, Permissions.ResolveIncident])
const depInput = await screen.findByPlaceholderText(/incidents\.reports\.department/i)
const catInput = await screen.findByPlaceholderText(/incidents\.reports\.category\b/i)
const catItemInput = await screen.findByPlaceholderText(/incidents\.reports\.categoryitem/i)
Expand Down Expand Up @@ -139,7 +133,7 @@ describe('Report Incident', () => {
}
expectOneConsoleError(error)
jest.spyOn(validationUtil, 'default').mockReturnValue(error)
render([Permissions.ReportIncident])
const { container } = setup([Permissions.ReportIncident])

userEvent.click(
screen.getByRole('button', {
Expand All @@ -154,22 +148,28 @@ describe('Report Incident', () => {
const descInput = inputArr[inputArr.length - 2]
const dateInput = inputArr[0]

screen.debug(undefined, Infinity)
const invalidInputs = container.querySelectorAll('.is-invalid')
expect(invalidInputs).toHaveLength(5)

// expect(dateInput).toBeInvalid()
expect(dateInput).toHaveClass('is-invalid')

// expect(depInput).toBeInvalid()
expect(depInput).toHaveClass('is-invalid')

// expect(catInput).toBeInvalid()
expect(catInput).toHaveClass('is-invalid')

// expect(catItemInput).toBeInvalid()
expect(catItemInput).toHaveClass('is-invalid')

// expect(descInput).toBeInvalid()
expect(descInput).toHaveClass('is-invalid')
})

describe('on cancel', () => {
it('should navigate to /incidents', () => {
render([Permissions.ReportIncident])
it('should navigate to /incidents', async () => {
setup([Permissions.ReportIncident])

expect(history.location.pathname).toBe('/incidents/new')

Expand Down

0 comments on commit 8693002

Please sign in to comment.