-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d99c12
commit 1d50531
Showing
2 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
// import { render } from "@testing-library/react" | ||
// import React from "react" | ||
// import VisitData from "../src/components/VisitRouter/VisitData" | ||
import { render } from "@testing-library/react" | ||
import React from "react" | ||
import VisitData from "../src/components/VisitRouter/VisitData" | ||
import { createMemoryHistory } from "history" | ||
import { Router, Route } from "react-router-dom" | ||
|
||
// describe("<VisitData />", () => {}) | ||
const history = createMemoryHistory() | ||
|
||
const mockVisitData = { | ||
id: 1, | ||
needles_in: 1, | ||
needles_out: 2, | ||
created_at: new Date(), | ||
site: { site_name: "a-site" }, | ||
} | ||
|
||
// need router to test because the component uses params to redirect if necessary | ||
// redirect testing happens in ExistingParticipantView.test.js, we are assuming the data coming in is correct here for now | ||
const renderWithRouter = (children, /*state = null,*/ { route = "/" } = {}) => { | ||
history.push(route) | ||
return render( | ||
<Router history={history}> | ||
<Route path="/"> {children} </Route> | ||
<Route path="/404">the 404 page</Route> | ||
</Router> | ||
) | ||
} | ||
|
||
describe("<VisitData />", () => { | ||
it("renders the visitData component", () => { | ||
renderWithRouter(<VisitData visitData={mockVisitData} />) | ||
}) | ||
|
||
it("has needles in value in dom", () => { | ||
const { getByText } = renderWithRouter( | ||
<VisitData visitData={mockVisitData} /> | ||
) | ||
expect(getByText(/needles in: 1/i)).toBeInTheDocument() | ||
}) | ||
|
||
it("has needles out value in dom", () => { | ||
const { getByText } = renderWithRouter( | ||
<VisitData visitData={mockVisitData} /> | ||
) | ||
expect(getByText(/needles out: 2/i)).toBeInTheDocument() | ||
}) | ||
|
||
it("has site value in dom", () => { | ||
const { getByText } = renderWithRouter( | ||
<VisitData visitData={mockVisitData} /> | ||
) | ||
expect(getByText(/exchange site: a-site/i)).toBeInTheDocument() | ||
}) | ||
|
||
it("has visit date in dom", () => { | ||
const { getByText } = renderWithRouter( | ||
<VisitData visitData={mockVisitData} /> | ||
) | ||
expect(getByText(/visit date:.*/i)).toBeInTheDocument() | ||
}) | ||
}) |