/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import "@testing-library/jest-dom/extend-expect"; import { render, screen, cleanup } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import SnapshotRestoreOption from "./SnapshotRestoreOption"; const testProps = { onRestoreAllIndicesToggle: jest.fn(), onRestoreSpecificIndicesToggle: jest.fn(), width: "200" }; afterEach(() => { cleanup(); }); describe("SnapshotRestoreOption component", () => { it("renders without error", () => { const { container } = render( ); expect(screen.getByText("Restore all indices in snapshot")).toBeInTheDocument(); expect(screen.getByText("Restore specific indices")).toBeInTheDocument(); expect(container).toMatchSnapshot(); }); it("accepts user input", () => { render( ); userEvent.click(screen.getByLabelText("Restore specific indices")); expect(testProps.onRestoreSpecificIndicesToggle).toBeCalled(); cleanup(); render( ); userEvent.click(screen.getByLabelText("Restore all indices in snapshot")); expect(testProps.onRestoreAllIndicesToggle).toBeCalled(); }); });