2022-03-17 06:19:35 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { fireEvent, render } from "@testing-library/react";
|
|
|
|
|
|
|
|
|
|
import SelectButton, { SelectButtonProps } from "./SelectButton";
|
|
|
|
|
|
|
|
|
|
const defaultProps: SelectButtonProps = {
|
|
|
|
|
disabled: false,
|
|
|
|
|
displayText: "0",
|
|
|
|
|
handleCancelClick: jest.fn(),
|
2022-03-17 06:26:44 +00:00
|
|
|
spanRef: null,
|
2022-03-17 06:19:35 +00:00
|
|
|
togglePopoverVisibility: jest.fn(),
|
2022-03-17 06:26:44 +00:00
|
|
|
tooltipText: "",
|
2022-03-17 06:19:35 +00:00
|
|
|
value: "0",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderComponent = (props: SelectButtonProps = defaultProps) => {
|
|
|
|
|
return render(<SelectButton {...props} />);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe("SelectButton", () => {
|
|
|
|
|
it("should render correctly", () => {
|
|
|
|
|
const { getByText } = renderComponent();
|
|
|
|
|
expect(getByText("0")).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
it("should trigger handleCancelClick method on cancel click", () => {
|
|
|
|
|
const { getByTestId } = renderComponent();
|
|
|
|
|
fireEvent.click(getByTestId("selectbutton.btn.cancel"));
|
|
|
|
|
expect(defaultProps.handleCancelClick).toBeCalled();
|
|
|
|
|
});
|
|
|
|
|
it("should toggle popover visibility method on button click", () => {
|
|
|
|
|
const { getByTestId } = renderComponent();
|
|
|
|
|
fireEvent.click(getByTestId("selectbutton.btn.main"));
|
|
|
|
|
expect(defaultProps.togglePopoverVisibility).toBeCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|