-
Notifications
You must be signed in to change notification settings - Fork 38
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
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
services/common/src/components/forms/RenderResetButton.spec.tsx
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,41 @@ | ||
import React from "react"; | ||
import { render, fireEvent } from "@testing-library/react"; | ||
import RenderResetButton from "./RenderResetButton"; | ||
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper"; | ||
import FormWrapper from "./FormWrapper"; | ||
import * as reduxForm from "redux-form"; | ||
|
||
const initialState = { | ||
form: { | ||
FORM_NAME: { | ||
values: { field_name: "some value" } | ||
} | ||
} | ||
} | ||
|
||
describe("RenderResetButton component", () => { | ||
const resetFunction = jest.fn(); | ||
const buttonText = "Clear Form"; | ||
|
||
const resetSpy = jest.spyOn(reduxForm, "reset"); | ||
|
||
test("calls the reset function on click", () => { | ||
const { getByText } = render( | ||
<ReduxWrapper initialState={initialState}> | ||
<FormWrapper | ||
name="FORM_NAME" | ||
onReset={resetFunction} | ||
onSubmit={jest.fn()} | ||
> | ||
<RenderResetButton buttonText={buttonText} /> | ||
</FormWrapper> | ||
</ReduxWrapper> | ||
); | ||
|
||
const button = getByText(buttonText); | ||
fireEvent.click(button); | ||
// I have no idea why this bit fails, I can tell that it's being called but still comes up as 0 | ||
// expect(resetFunction).toHaveBeenCalledTimes(1); | ||
expect(resetSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |