-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for ConfirmNotFoundLocationDialog component
- Loading branch information
1 parent
585d7dc
commit 904f47d
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
src/react/src/__tests__/components/ConfirmNotFoundLocationDialog.test.js
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,101 @@ | ||
import React from "react"; | ||
import renderWithProviders from "../../util/testUtils/renderWithProviders"; | ||
import ConfirmNotFoundLocationDialog from "../../components/Contribute/ConfirmNotFoundLocationDialog"; | ||
import history from "../../util/history"; | ||
import { contributeProductionLocationRoute } from "../../util/constants"; | ||
|
||
jest.mock("../../util/history", () => ({ | ||
push: jest.fn(), | ||
})); | ||
|
||
const mockHandleConfirmDialogClose = jest.fn(); | ||
const mockClearLocations = jest.fn(); | ||
|
||
describe("ConfirmNotFoundLocationDialog component", () => { | ||
const defaultProps = { | ||
confirmDialogIsOpen: true, | ||
handleConfirmDialogClose: mockHandleConfirmDialogClose, | ||
clearLocations: mockClearLocations, | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("renders the dialog with the correct title and buttons", () => { | ||
const { getByText, getByRole } = renderWithProviders( | ||
<ConfirmNotFoundLocationDialog {...defaultProps} />, | ||
); | ||
|
||
expect( | ||
getByText( | ||
/Are you sure you have reviewed the entire list and could not find the production location?/i, | ||
), | ||
).toBeInTheDocument(); | ||
expect( | ||
getByRole("button", { | ||
name: /No, I would like to try searching again/i, | ||
}), | ||
).toBeInTheDocument(); | ||
expect( | ||
getByRole("button", { | ||
name: /Yes, add a new production location/i, | ||
}), | ||
).toBeInTheDocument(); | ||
expect(getByRole("button", { name: /Close/i })).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls handleSearchAgain when "No, I would like to try searching again" button is clicked', () => { | ||
const { getByRole } = renderWithProviders( | ||
<ConfirmNotFoundLocationDialog {...defaultProps} />, | ||
); | ||
const button = getByRole("button", { | ||
name: /No, I would like to try searching again/i, | ||
}); | ||
button.click(); | ||
|
||
expect(mockHandleConfirmDialogClose).toHaveBeenCalledTimes(1); | ||
expect(mockClearLocations).toHaveBeenCalledTimes(1); | ||
expect(history.push).toHaveBeenCalledWith( | ||
`${contributeProductionLocationRoute}?tab=name-address`, | ||
); | ||
}); | ||
|
||
test('calls handleAddNewLocation when "Yes, add a new production location" button is clicked', () => { | ||
const { getByRole } = renderWithProviders( | ||
<ConfirmNotFoundLocationDialog {...defaultProps} />, | ||
); | ||
const button = getByRole("button", { | ||
name: /Yes, add a new production location/i, | ||
}); | ||
button.click(); | ||
|
||
expect(mockHandleConfirmDialogClose).toHaveBeenCalledTimes(1); | ||
expect(mockClearLocations).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("closes the dialog when the close button is clicked", () => { | ||
const { getByRole } = renderWithProviders( | ||
<ConfirmNotFoundLocationDialog {...defaultProps} />, | ||
); | ||
const button = getByRole("button", { name: /Close/i }); | ||
button.click(); | ||
|
||
expect(mockHandleConfirmDialogClose).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("does not render the dialog when confirmDialogIsOpen is false", () => { | ||
const { queryByText } = renderWithProviders( | ||
<ConfirmNotFoundLocationDialog | ||
{...defaultProps} | ||
confirmDialogIsOpen={false} | ||
/>, | ||
); | ||
|
||
expect( | ||
queryByText( | ||
/Are you sure you have reviewed the entire list and could not find the production location?/i, | ||
), | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); |