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 #87 from kcdraidgroup/jacobmgevans
Browse files Browse the repository at this point in the history
ReportIncident
  • Loading branch information
JacobMGEvans authored Dec 24, 2020
2 parents f01b3dc + 912a557 commit f73e458
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 208 deletions.
28 changes: 13 additions & 15 deletions src/__tests__/incidents/Incidents.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render as rtlRender } from '@testing-library/react'
import { render } from '@testing-library/react'
import React from 'react'
import type { ReactElement, ReactNode } from 'react'
import { Provider } from 'react-redux'
Expand All @@ -21,7 +21,7 @@ type WrapperProps = {
}

describe('Incidents', () => {
function render(permissions: Permissions[], path: string) {
function setup(permissions: Permissions[], path: string) {
const expectedIncident = {
id: '1234',
code: '1234',
Expand All @@ -47,55 +47,53 @@ describe('Incidents', () => {
)
}

const results = rtlRender(<Incidents />, { wrapper: Wrapper })

return results
return render(<Incidents />, { wrapper: Wrapper })
}

describe('title', () => {
it('should have called the useUpdateTitle hook', () => {
render([Permissions.ViewIncidents], '/incidents')
setup([Permissions.ViewIncidents], '/incidents')
expect(titleUtil.useUpdateTitle).toHaveBeenCalledTimes(1)
})
})

describe('routing', () => {
describe('/incidents/new', () => {
it('should render the new incident screen when /incidents/new is accessed', () => {
const { container } = render([Permissions.ReportIncident], '/incidents/new')
it('The new incident screen when /incidents/new is accessed', () => {
const { container } = setup([Permissions.ReportIncident], '/incidents/new')

expect(container).toHaveTextContent('incidents.reports')
})

it('should not navigate to /incidents/new if the user does not have ReportIncident permissions', () => {
const { container } = render([], '/incidents/new')
const { container } = setup([], '/incidents/new')

expect(container).not.toHaveTextContent('incidents.reports')
})
})

describe('/incidents/visualize', () => {
it('should render the incident visualize screen when /incidents/visualize is accessed', () => {
const { container } = render([Permissions.ViewIncidentWidgets], '/incidents/visualize')
it('The incident visualize screen when /incidents/visualize is accessed', () => {
const { container } = setup([Permissions.ViewIncidentWidgets], '/incidents/visualize')

expect(container.querySelector('.chartjs-render-monitor')).toBeInTheDocument()
})

it('should not navigate to /incidents/visualize if the user does not have ViewIncidentWidgets permissions', () => {
const { container } = render([], '/incidents/visualize')
const { container } = setup([], '/incidents/visualize')

expect(container.querySelector('.chartjs-render-monitor')).not.toBeInTheDocument()
})
})

describe('/incidents/:id', () => {
it('should render the view incident screen when /incidents/:id is accessed', () => {
const { container } = render([Permissions.ViewIncident], '/incidents/1234')
it('The view incident screen when /incidents/:id is accessed', () => {
const { container } = setup([Permissions.ViewIncident], '/incidents/1234')
expect(container.querySelectorAll('div').length).toBe(3)
})

it('should not navigate to /incidents/:id if the user does not have ViewIncident permissions', () => {
const { container } = render([], '/incidents/1234')
const { container } = setup([], '/incidents/1234')
expect(container.querySelectorAll('div').length).not.toBe(3)
})
})
Expand Down
Loading

0 comments on commit f73e458

Please sign in to comment.