import { render, screen } from '@testing-library/react';
import { Alert } from './Alert';

vi.mock('@/assets/success.svg', () => ({ default: 'success.svg' }));
vi.mock('@/assets/warning.svg', () => ({ default: 'warning.svg' }));

describe('<Alert>', () => {
    it('should render success icon', () => {
        render(<Alert text="Text message" />);

        expect(screen.getByRole('presentation')).toBeVisible();
        expect(screen.getByRole('presentation')).toHaveAttribute(
            'src',
            expect.stringMatching(/success.svg/)
        );
    });

    it('should render text', () => {
        render(<Alert text="Text message" />);

        expect(screen.getByText('Text message')).toBeVisible();
    });

    describe('when "isError" set to "true"', () => {
        it('should render warning icon', () => {
            render(<Alert text="Text message" isError />);

            expect(screen.getByRole('presentation')).toBeVisible();
            expect(screen.getByRole('presentation')).toHaveAttribute(
                'src',
                expect.stringMatching(/warning.svg/)
            );
        });
    });
});
