Skip to content

Commit

Permalink
fix(extractfullname.ts): scaffolds extractFullName()
Browse files Browse the repository at this point in the history
Previously, the extractUserName() function was returning a mocked "some user." We scaffolded out
this function for when we complete the user model.

fix HospitalRun#2539

fixed extractFullName import

remove reportedBy

make app test less spurious
  • Loading branch information
jameszheng405 committed Apr 18, 2021
1 parent b67b598 commit 85414d5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react'
import { render, screen, waitFor } from '@testing-library/react'
import React from 'react'
import { Provider } from 'react-redux'
import createMockStore from 'redux-mock-store'
Expand Down Expand Up @@ -32,9 +32,9 @@ it('renders without crashing', async () => {
</Provider>,
)

expect(
await screen.findByRole('heading', { name: /dashboard\.label/i }, { timeout: 8000 }),
).toBeInTheDocument()
await waitFor(() => {
expect(screen.getByRole('heading', { name: /dashboard\.label/i })).toBeInTheDocument()
})

// eslint-disable-next-line no-console
;(console.log as jest.Mock).mockRestore()
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/incidents/hooks/useReportIncident.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('useReportIncident', () => {
const expectedCode = '123456'
const expectedDate = new Date(Date.now())
const expectedStatus = 'reported'
const expectedReportedBy = 'some user'
Date.now = jest.fn().mockReturnValue(expectedDate)

const givenIncidentRequest = {
Expand All @@ -34,7 +33,6 @@ describe('useReportIncident', () => {
code: `I-${expectedCode}`,
reportedOn: expectedDate.toISOString(),
status: expectedStatus,
reportedBy: expectedReportedBy,
} as Incident
jest.spyOn(shortid, 'generate').mockReturnValue(expectedCode)
jest.spyOn(IncidentRepository, 'save').mockResolvedValue(expectedIncident)
Expand Down
2 changes: 1 addition & 1 deletion src/incidents/hooks/useReportIncident.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const getIncidentCode = (): string => `I-${shortid.generate()}`

export function reportIncident(incident: Incident): Promise<Incident> {
const error = validateIncident(incident)

if (isEmpty(error)) {
const updatedIncident: Incident = {
...incident,
code: getIncidentCode(),
status: 'reported',
reportedBy: 'some user',
reportedOn: new Date(Date.now()).toISOString(),
}
return IncidentRepository.save(updatedIncident)
Expand Down
4 changes: 4 additions & 0 deletions src/incidents/report/ReportIncident.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, Row, Column, Typeahead, Label } from '@hospitalrun/components'
import React, { useState, useEffect } from 'react'
import { useSelector } from 'react-redux'
import { useHistory } from 'react-router-dom'

import useAddBreadcrumbs from '../../page-header/breadcrumbs/useAddBreadcrumbs'
Expand All @@ -11,6 +12,7 @@ import PatientRepository from '../../shared/db/PatientRepository'
import useTranslator from '../../shared/hooks/useTranslator'
import Incident from '../../shared/model/Incident'
import Patient from '../../shared/model/Patient'
import { RootState } from '../../shared/store'
import useReportIncident from '../hooks/useReportIncident'
import { IncidentError } from '../util/validate-incident'

Expand All @@ -19,6 +21,7 @@ const ReportIncident = () => {
const history = useHistory()
const { t } = useTranslator()
const updateTitle = useUpdateTitle()
const { user } = useSelector((state: RootState) => state.user)
useEffect(() => {
updateTitle(t('incidents.reports.new'))
})
Expand All @@ -30,6 +33,7 @@ const ReportIncident = () => {
]
useAddBreadcrumbs(breadcrumbs)
const [incident, setIncident] = useState({
reportedBy: user?.id || 'some user',
date: new Date().toISOString(),
department: '',
category: '',
Expand Down
4 changes: 2 additions & 2 deletions src/incidents/view/ViewIncidentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TextFieldWithLabelFormGroup from '../../shared/components/input/TextField
import TextInputWithLabelFormGroup from '../../shared/components/input/TextInputWithLabelFormGroup'
import useTranslator from '../../shared/hooks/useTranslator'
import Permissions from '../../shared/model/Permissions'
import { extractUsername } from '../../shared/util/extractUsername'
import { extractFullName } from '../../shared/util/extractFullName'
import useIncident from '../hooks/useIncident'
import useResolveIncident from '../hooks/useResolveIncident'

Expand Down Expand Up @@ -83,7 +83,7 @@ function ViewIncidentDetails(props: Props) {
<Column>
<div className="form-group incident-reported-by">
<h4>{t('incidents.reports.reportedBy')}</h4>
<h5>{extractUsername(data.reportedBy)}</h5>
<h5>{extractFullName(data.reportedBy)}</h5>
</div>
</Column>
<Column>
Expand Down
2 changes: 2 additions & 0 deletions src/shared/util/extractFullName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO: extract fullname from userID when we have information on other users
export const extractFullName = (userID: string) => userID

0 comments on commit 85414d5

Please sign in to comment.