/**
 * @jest-environment jsdom
 */
import { cleanup, render } from '@testing-library/react';
import React from 'react';
import LoadingIndicator from '../LoadingIndicator';

describe('LoadingIndicator Component', () => {
    afterEach(cleanup);

    it('starts showing loading by default when we have no attribute', () => {
        const { getByText } = render(<LoadingIndicator />);
        const loadingText = getByText('Loading...');
        expect(loadingText).toBeInTheDocument();
        expect(loadingText).toHaveClass('sr-only');
    });

    it('shows the loading when show prop is true', () => {
        const { getByText } = render(<LoadingIndicator show={true}/>);
        expect(getByText('Loading...')).toBeInTheDocument();
    });

    it('hides the loading when show prop is false', () => {
        const { container } = render(<LoadingIndicator show={false}/>);
        expect(container).toBeEmpty();
    });

    it('shows message when it is set', () => {
        const { getByText } = render(<LoadingIndicator message="test message"/>);
        const messageText = getByText('test message');
        expect(messageText).toHaveClass('spinner-message');
        expect(messageText).toBeInTheDocument();
    });

    it('adds correct class name when size prop is set', () => {
        const { container } = render(<LoadingIndicator size="sm"/>);
        expect(container.firstChild).toHaveClass('spinner-sm');
    });

    it('adds inline class name when inline prop is true', () => {
        const { container } = render(<LoadingIndicator isInline={true}/>);
        expect(container.firstChild).toHaveClass('spinner-inline');
    });
});
