/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import { render, screen } from 'spec/helpers/testing-library'; import userEvent from '@testing-library/user-event'; import { ExploreAlert } from './ExploreAlert'; test('renders with title and body text', () => { render( , ); expect(screen.getByText('Test Title')).toBeInTheDocument(); expect(screen.getByText('Test body text')).toBeInTheDocument(); }); test('renders info type alert', () => { const { container } = render( , ); expect(container.querySelector('.ant-alert-info')).toBeInTheDocument(); }); test('renders warning type alert', () => { const { container } = render( , ); expect(container.querySelector('.ant-alert-warning')).toBeInTheDocument(); }); test('renders error type alert', () => { const { container } = render( , ); expect(container.querySelector('.ant-alert-error')).toBeInTheDocument(); }); test('renders primary button when text and action provided', () => { const primaryAction = jest.fn(); render( , ); expect(screen.getByText('Primary Action')).toBeInTheDocument(); }); test('calls primary button action when clicked', async () => { const primaryAction = jest.fn(); render( , ); await userEvent.click(screen.getByText('Click Me')); expect(primaryAction).toHaveBeenCalledTimes(1); }); test('renders both primary and secondary buttons when provided', () => { const primaryAction = jest.fn(); const secondaryAction = jest.fn(); render( , ); expect(screen.getByText('Primary')).toBeInTheDocument(); expect(screen.getByText('Secondary')).toBeInTheDocument(); }); test('calls secondary button action when clicked', async () => { const primaryAction = jest.fn(); const secondaryAction = jest.fn(); render( , ); await userEvent.click(screen.getByText('Secondary')); expect(secondaryAction).toHaveBeenCalledTimes(1); expect(primaryAction).not.toHaveBeenCalled(); }); test('does not render buttons when only text is provided without action', () => { render( , ); expect(screen.queryByText('Primary')).not.toBeInTheDocument(); }); test('does not render buttons when only action is provided without text', () => { const primaryAction = jest.fn(); render( , ); expect(screen.queryByRole('button')).not.toBeInTheDocument(); }); test('does not render secondary button when secondary action is missing', () => { const primaryAction = jest.fn(); render( , ); expect(screen.getByText('Primary')).toBeInTheDocument(); expect(screen.queryByText('Secondary')).not.toBeInTheDocument(); }); test('does not render secondary button when secondary text is missing', () => { const primaryAction = jest.fn(); const secondaryAction = jest.fn(); render( , ); expect(screen.getByText('Primary')).toBeInTheDocument(); expect( screen.queryByRole('button', { name: /secondary/i }), ).not.toBeInTheDocument(); }); test('applies custom className', () => { const { container } = render( , ); expect(container.querySelector('.custom-class')).toBeInTheDocument(); }); test('renders with ReactNode as bodyText', () => { render( Line 1 Line 2 } type="info" />, ); expect(screen.getByText('Line 1')).toBeInTheDocument(); expect(screen.getByText('Line 2')).toBeInTheDocument(); }); test('is not closable by default', () => { const { container } = render( , ); expect( container.querySelector('.ant-alert-close-icon'), ).not.toBeInTheDocument(); }); test('shows icon by default', () => { const { container } = render( , ); expect(container.querySelector('.anticon')).toBeInTheDocument(); });