/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { useState } from "react"; import "@testing-library/jest-dom/extend-expect"; import { render } from "@testing-library/react"; import ErrorNotificationContainer, { ErrorNotificationProps } from "./ErrorNotification"; import { ServicesContext } from "../../services"; import { browserServicesMock, coreServicesMock } from "../../../test/mocks"; import { ErrorNotification as IErrorNotification } from "../../../models/interfaces"; import { CoreServicesContext } from "../../components/core_services"; const ErrorNotification = (props: Pick) => { const [value, onChange] = useState(props.value); return ( ); }; function renderErrorNotification(errorNotification: IErrorNotification) { return { ...render( ), }; } describe(" spec", () => { it("renders the component", () => { const { container } = render( ); expect(container.firstChild).toMatchSnapshot(); }); it("renders the channel ui editor for channels", () => { const errorNotification = { channel: { id: "some_id" }, message_template: { source: "some source message" } }; const { queryByTestId, queryByText } = renderErrorNotification(errorNotification); expect(queryByTestId("channel-notification-refresh")).not.toBeNull(); expect(queryByText("Switch to using Channel ID")).toBeNull(); }); it("renders the json legacy editor for destinations", () => { const errorNotification = { destination: { slack: { url: "https://slack.com" } }, message_template: { source: "some source message" } }; const { queryByTestId, queryByText } = renderErrorNotification(errorNotification); expect(queryByTestId("channel-notification-refresh")).toBeNull(); expect(queryByText("Switch to using Channel ID")).not.toBeNull(); }); });