Skip to content

Commit

Permalink
Test prevpointbutton 477 (#479)
Browse files Browse the repository at this point in the history
* First attempt at PrevPointButtonTest

* Made text into variable.
  • Loading branch information
JackRyan1989 authored Jan 11, 2021
1 parent 24894c0 commit ea60f08
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
54 changes: 54 additions & 0 deletions frontend/test/PrevPointButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { render } from "@testing-library/react"
import { shallow } from "enzyme"
import React from "react"
import PrevPointButton from "../src/components/PrevPointButton"

// Test the following things:
// 1. Button type: submit or button
// 2. Disabled: true or false
// 3. onclick function
describe("<PrevPointButton />", () => {
const mockOnClick = jest.fn()
const text = "Search"
let props

beforeEach(() => {
props = {
size: "small",
type: "submit",
disabled: false,
color: "primary",
onClick: mockOnClick,
}
})
it("should render a PrevPointButton component", () => {
const buttonWrapper = render(
<PrevPointButton {...props}>{text}</PrevPointButton>
)
expect(buttonWrapper).toMatchSnapshot()
})

it("should render a PrevPointButton component with Search text", () => {
const buttonWrapper = render(
<PrevPointButton {...props}>{text}</PrevPointButton>
)
const button = buttonWrapper.queryByText("Search")
expect(button).toHaveTextContent("Search")
})

it("Should have a button type of submit", () => {
const button = shallow(<PrevPointButton {...props}>{text}</PrevPointButton>)
expect(button.props().type).toBe("submit")
})

it("should have disabled set to false", () => {
const button = shallow(<PrevPointButton {...props}>{text}</PrevPointButton>)
expect(button.props().disabled).toBe(false)
})

it("should have working onclick function", () => {
const button = shallow(<PrevPointButton {...props}>{text}</PrevPointButton>)
button.simulate("click")
expect(mockOnClick).toHaveBeenCalledTimes(1)
})
})
92 changes: 92 additions & 0 deletions frontend/test/__snapshots__/PrevPointButton.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<PrevPointButton /> should render a PrevPointButton component 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
<button
class="MuiButtonBase-root MuiButton-root MuiButton-contained makeStyles-PrevPointButton-1 MuiButton-containedPrimary MuiButton-containedSizeSmall MuiButton-sizeSmall"
tabindex="0"
type="submit"
>
<span
class="MuiButton-label"
>
Search
</span>
<span
class="MuiTouchRipple-root"
/>
</button>
</div>
</body>,
"container": <div>
<button
class="MuiButtonBase-root MuiButton-root MuiButton-contained makeStyles-PrevPointButton-1 MuiButton-containedPrimary MuiButton-containedSizeSmall MuiButton-sizeSmall"
tabindex="0"
type="submit"
>
<span
class="MuiButton-label"
>
Search
</span>
<span
class="MuiTouchRipple-root"
/>
</button>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

0 comments on commit ea60f08

Please sign in to comment.