-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lizzypy/participant-list-and-tests-for-hooks
Add participants list view and tests for hooks
- Loading branch information
Showing
15 changed files
with
20,977 additions
and
9,889 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const nextJest = require("next/jest"); | ||
const createJestConfig = nextJest({ | ||
dir: "./", | ||
}); | ||
const customJestConfig = { | ||
moduleDirectories: ["node_modules", "<rootDir>/"], | ||
testEnvironment: "jest-environment-jsdom", | ||
}; | ||
module.exports = createJestConfig(customJestConfig); |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Participants as default } from "../../src/pages/Participants" |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Users as default } from "../../src/pages/Users" |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
import Box from '@mui/material/Box'; | ||
import {AppBar, Toolbar } from "@mui/material"; | ||
import useParticipants from "../hooks/useParticipants"; | ||
import type {NextPage} from 'next'; | ||
import SignUpForm from "../components/signUpForm"; | ||
import {Typography} from "@material-ui/core"; | ||
|
||
const ParticipantsList = () => { | ||
const { participants, isLoading } = useParticipants(); | ||
|
||
const columns = [ | ||
{ | ||
field: 'id', | ||
headerName: 'ID', | ||
width: 90 | ||
}, | ||
{ | ||
field: 'first_name', | ||
headerName: 'First Name', | ||
width: 300, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'last_name', | ||
headerName: 'Last Name', | ||
width: 300, | ||
editable: true, | ||
}, | ||
] | ||
|
||
return ( | ||
<div> | ||
<Box sx={{textAlign:'left', height: 400, width: '100%'}}> | ||
<Typography variant={'h6'}> Participants </Typography> | ||
<div style={{ height: 250, width: '100%' }}> | ||
<DataGrid | ||
rows={participants} | ||
columns={columns} | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { | ||
pageSize: 5, | ||
}, | ||
}, | ||
}} | ||
pageSizeOptions={[5]} | ||
checkboxSelection | ||
disableRowSelectionOnClick | ||
/> | ||
</div> | ||
</Box> | ||
</div> | ||
); | ||
} | ||
|
||
export default ParticipantsList; |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {waitFor, render, screen, act} from "@testing-library/react"; | ||
import {AxiosInstance} from "axios"; | ||
import useParticipants from "./useParticipants"; | ||
import React from "react"; | ||
import {useHttpClient} from "./useHttpClient"; | ||
|
||
jest.mock("./useHttpClient") | ||
|
||
const mockedUseHttpClient = jest.mocked(useHttpClient, true) | ||
const TestParticipantsComponent = () => { | ||
const {participants, isLoading} = useParticipants() | ||
return ( | ||
<>{ | ||
isLoading ? | ||
<></> : | ||
<div> | ||
{ | ||
participants.map((p) => { | ||
return ( | ||
<> | ||
<li>First Name: {p.first_name}</li> | ||
<li>Last Name: {p.last_name}</li> | ||
<li>ID: {p.id}</li> | ||
</> | ||
) | ||
}) | ||
} | ||
</div> | ||
} | ||
</> | ||
) | ||
} | ||
|
||
describe('useParticipants', () => { | ||
const mockHttpClient = { | ||
get: jest.fn(), | ||
post: jest.fn() | ||
} | ||
beforeEach(async () => { | ||
const expectedParticipantsResponse = { | ||
data: [ | ||
{ | ||
"id":1, | ||
"first_name":"clayton", | ||
"last_name":"johnson", | ||
"birthdate":"2016-04-16", | ||
} | ||
] | ||
} | ||
mockedUseHttpClient.mockReturnValue(((mockHttpClient as unknown) as AxiosInstance)) | ||
mockHttpClient.get.mockReturnValue(Promise.resolve(expectedParticipantsResponse)) | ||
mockHttpClient.post.mockReturnValue(expectedParticipantsResponse) | ||
}); | ||
|
||
it('should return renderable participant data', async () => { | ||
act(() => { | ||
render ( | ||
<TestParticipantsComponent/> | ||
) | ||
}) | ||
|
||
expect(mockHttpClient.get.mock.calls[0][0]).toEqual(`/participants`) | ||
await waitFor(() => { | ||
expect(mockHttpClient.get).toHaveBeenCalledWith('/participants') | ||
expect(screen.getByText(/clayton/)).not.toBeNull() | ||
expect(screen.getByText(/1/)).not.toBeNull() | ||
}) | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import ParticipantsList from "../components/ParticipantsList"; | ||
import {AppBar, Toolbar } from "@mui/material"; | ||
import SignUpForm from "../components/signUpForm"; | ||
import type {NextPage} from 'next'; | ||
|
||
export const Participants: NextPage = () => { | ||
return ( | ||
<> | ||
<AppBar position="static" sx={{ bgcolor: "pink" }}> | ||
<section aria-label={"toolbar-section"} | ||
style={{display: "flex", flexDirection: "row", justifyContent: "right"}}> | ||
<Toolbar> | ||
<SignUpForm/> | ||
</Toolbar> | ||
</section> | ||
</AppBar> | ||
<section aria-label={"participants-section"} | ||
style={{ | ||
padding: "40px 30px", | ||
display: "flex", | ||
flexDirection: "column", | ||
justifyContent: "space-around" | ||
}}> | ||
<ParticipantsList/> | ||
</section> | ||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
import Box from '@mui/material/Box'; | ||
import {AppBar, Toolbar } from "@mui/material"; | ||
import useUsers from "../hooks/useUsers"; | ||
import type {NextPage} from 'next'; | ||
import SignUpForm from "../components/signUpForm"; | ||
import {Typography} from "@material-ui/core"; | ||
|
||
export const Users: NextPage = () => { | ||
const { users, isLoading } = useUsers(); | ||
|
||
const columns = [ | ||
{ field: 'id', headerName: 'ID', width: 90 }, | ||
{ | ||
field: 'email', | ||
headerName: 'Email', | ||
width: 300, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'updated_at', | ||
headerName: 'Last Updated', | ||
width: 300, | ||
editable: true, | ||
}, | ||
] | ||
|
||
return ( | ||
<div> | ||
<AppBar position="static" sx={{ bgcolor: "pink" }}> | ||
<section aria-label={"toolbar-section"} | ||
style={{display: "flex", flexDirection: "row", justifyContent: "right"}}> | ||
<Toolbar> | ||
<SignUpForm/> | ||
</Toolbar> | ||
</section> | ||
</AppBar> | ||
<section aria-label={"participants-section"} | ||
style={{ | ||
padding: "40px 30px", | ||
display: "flex", | ||
flexDirection: "column", | ||
justifyContent: "space-around" | ||
}}> | ||
<Box sx={{textAlign:'left', height: 400, width: '100%'}}> | ||
<Typography variant={'h6'}> Users </Typography> | ||
<div style={{ height: 250, width: '100%' }}> | ||
<DataGrid | ||
rows={users} | ||
columns={columns} | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { | ||
pageSize: 5, | ||
}, | ||
}, | ||
}} | ||
pageSizeOptions={[5]} | ||
checkboxSelection | ||
disableRowSelectionOnClick | ||
/> | ||
</div> | ||
</Box> | ||
</section> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.