Skip to content

Commit

Permalink
add tests for visitTable, and add aria labels to visit table component
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeyManoguerra committed Dec 29, 2020
1 parent c98be2c commit a3a54ad
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
8 changes: 4 additions & 4 deletions frontend/src/components/VisitRouter/VisitTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const VisitTable = ({
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [fullName])

const mockHeaderTitles = [
const headerTitles = [
{ title: "Program", mobile: true },
{ title: "Service", mobile: true },
{ title: "Date", mobile: true },
Expand All @@ -51,12 +51,12 @@ const VisitTable = ({
<Paper>
<Table className={classes.visitTable} aria-label="visits table">
<PrevPointTableHead
headerTitles={mockHeaderTitles}
headerTitles={headerTitles}
forParticipantTable={false}
/>
<TableBody>
{participantVisits.map(visit => (
<TableRow key={visit.id}>
<TableRow aria-label="visit row" key={visit.id}>
<TableCell>
<PrevPointCopy>{visit.program.name}</PrevPointCopy>
</TableCell>
Expand All @@ -80,7 +80,7 @@ const VisitTable = ({
<Fab
color="primary"
size="small"
aria-label="add"
aria-label="get protected visit data"
onClick={() => getProtectedVisitData(visit.id)}
>
<VerifiedUserIcon />
Expand Down
2 changes: 1 addition & 1 deletion frontend/test/PrevPointTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import PrevPointTable from "./../src/components/ParticipantTableComponent/PrevPo

describe("<PrevPointTable />", () => {
it("should render a PrevPointTable component", () => {
render(<PrevPointTable participants={[]} />)
render(<PrevPointTable participants={[]} headerTitles={[]} />)
})
})
81 changes: 78 additions & 3 deletions frontend/test/VisitTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,32 @@ import { render } from "@testing-library/react"
import React from "react"
import VisitTable from "../src/components/VisitRouter/VisitTable"

const defaultVisitCount = 5
function generateMockVisit(index) {
return {
id: index,
created_at: new Date(),
program: {
name: `program-${index}`,
},
service: {
name: `service-${index}`,
},
}
}

function generateMockVisits(visitCount = defaultVisitCount) {
const visits = []
for (let i = 0; i < visitCount; i++) {
visits.push(generateMockVisit(i))
}

return visits
}

describe("<VisitTable />", () => {
const aName = "Kamala Harris"

it("Renders", () => {
render(
<VisitTable
Expand All @@ -13,16 +38,66 @@ describe("<VisitTable />", () => {
)
})

it("Renders", () => {
const aName = "Kamala Harris"
it("Displays the participant nane", () => {
const { getByText } = render(
<VisitTable
fullName={aName}
getParticipantVisits={() => {}}
participantVisits={[]}
getProtectedVisitData={() => {}}
/>
)

expect(getByText(`${aName}'s Previous Visits`)).toBeInTheDocument()
})

it("calls fn passed to getParticipantVisits on mount", () => {
const mockVisitsRequest = jest.fn()

render(
<VisitTable
fullName={aName}
getParticipantVisits={() => {}}
getParticipantVisits={mockVisitsRequest}
participantVisits={[]}
getProtectedVisitData={() => {}}
/>
)

expect(mockVisitsRequest).toHaveBeenCalled()
})

it("displays mock visits", () => {
const { getAllByLabelText } = render(
<VisitTable
fullName={aName}
getParticipantVisits={() => {}}
participantVisits={generateMockVisits()}
getProtectedVisitData={() => {}}
/>
)

const visitRows = getAllByLabelText("visit row")
expect(visitRows.length).toEqual(defaultVisitCount)
})

it("calls getProtectedVisitData with id on click", () => {
const mockDataRequest = jest.fn(x => {
x
})
const visitId = 0

const { getAllByLabelText } = render(
<VisitTable
fullName={aName}
getParticipantVisits={() => {}}
participantVisits={generateMockVisits(2)}
getProtectedVisitData={x => mockDataRequest(x)}
/>
)

const icon = getAllByLabelText("get protected visit data")[0]
icon.click()

expect(mockDataRequest).toBeCalledWith(visitId)
})
})

0 comments on commit a3a54ad

Please sign in to comment.