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 #74 from codyarose/codyarose
Browse files Browse the repository at this point in the history
Convert ViewIncidents.test.tsx to RTL
  • Loading branch information
JacobMGEvans authored Dec 23, 2020
2 parents 161e11b + 71afbf7 commit 3fbee70
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions src/__tests__/incidents/list/ViewIncidents.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { act } from '@testing-library/react'
import { mount, ReactWrapper } from 'enzyme'
import { render } from '@testing-library/react'
import { createMemoryHistory } from 'history'
import React from 'react'
import { Provider } from 'react-redux'
Expand All @@ -9,7 +8,6 @@ import thunk from 'redux-thunk'

import IncidentFilter from '../../../incidents/IncidentFilter'
import ViewIncidents from '../../../incidents/list/ViewIncidents'
import ViewIncidentsTable from '../../../incidents/list/ViewIncidentsTable'
import * as breadcrumbUtil from '../../../page-header/breadcrumbs/useAddBreadcrumbs'
import * as ButtonBarProvider from '../../../page-header/button-toolbar/ButtonBarProvider'
import * as titleUtil from '../../../page-header/title/TitleContext'
Expand Down Expand Up @@ -52,29 +50,24 @@ describe('View Incidents', () => {
},
} as any)

let wrapper: any
await act(async () => {
wrapper = await mount(
<ButtonBarProvider.ButtonBarProvider>
<Provider store={store}>
<Router history={history}>
<Route path="/incidents">
<titleUtil.TitleProvider>
<ViewIncidents />
</titleUtil.TitleProvider>
</Route>
</Router>
</Provider>
</ButtonBarProvider.ButtonBarProvider>,
)
})
wrapper.find(ViewIncidents).props().updateTitle = jest.fn()
wrapper.update()
return { wrapper: wrapper as ReactWrapper }
return render(
<ButtonBarProvider.ButtonBarProvider>
<Provider store={store}>
<Router history={history}>
<Route path="/incidents">
<titleUtil.TitleProvider>
<ViewIncidents />
</titleUtil.TitleProvider>
</Route>
</Router>
</Provider>
</ButtonBarProvider.ButtonBarProvider>,
)
}

it('should have called the useUpdateTitle hook', async () => {
await setup([Permissions.ViewIncidents])

expect(titleUtil.useUpdateTitle).toHaveBeenCalledTimes(1)
})

Expand All @@ -87,11 +80,11 @@ describe('View Incidents', () => {

describe('layout', () => {
it('should render a table with the incidents', async () => {
const { wrapper } = await setup([Permissions.ViewIncidents])
const table = wrapper.find(ViewIncidentsTable)
const { container } = await setup([Permissions.ViewIncidents])
const table = container.querySelector('table')

expect(table.exists()).toBeTruthy()
expect(table.prop('searchRequest')).toEqual({ status: IncidentFilter.reported })
expect(table).toBeTruthy()
expect(table).toHaveTextContent(IncidentFilter.reported)
})
})
})

0 comments on commit 3fbee70

Please sign in to comment.