-
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.
* First attempt at PrevPointButtonTest * Made text into variable.
- Loading branch information
1 parent
24894c0
commit ea60f08
Showing
2 changed files
with
146 additions
and
0 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,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) | ||
}) | ||
}) |
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,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], | ||
} | ||
`; |