import React from 'react'
import { render, waitFor } from '../utilities/test-utils'
import { FixedConfirmationToast } from 'playbook-ui'
beforeEach(() => {
// Silences error logs within the test suite.
jest.spyOn(console, 'error')
// eslint-disable-next-line
console.error.mockImplementation(() => {})
})
afterEach(() => {
// eslint-disable-next-line
console.error.mockRestore()
})
test('renders with default props', () => {
const { container } = render();
expect(container.firstChild).toBeInTheDocument();
});
test('renders with text', () => {
const { getByText } = render();
expect(getByText('Message Text')).toBeInTheDocument();
});
test('does not render if open prop is false', () => {
const { container } = render();
expect(container.firstChild).toBeNull();
});
test('closes after autoClose duration', async () => {
jest.useFakeTimers();
const onCloseMock = jest.fn();
render(
);
jest.advanceTimersByTime(1000);
await waitFor(() => expect(onCloseMock).toHaveBeenCalled());
});
test('renders success status with icon', () => {
const { container } = render();
expect(container.querySelector('.pb_fixed_confirmation_toast_kit_success')).toBeInTheDocument();
expect(container.querySelector('.pb_icon')).toBeInTheDocument();
});
test('renders custom icon when provided', () => {
const { container } = render();
expect(container.querySelector('.custom_icon')).toBeInTheDocument();
});
test('renders correctly with multiLine prop', () => {
const { container } = render();
expect(container.querySelector('._multi_line')).toBeInTheDocument();
});
test('renders position when provided', () => {
const { container } = render(
);
expect(container.querySelector('.positioned_toast')).toBeInTheDocument();
});