/**
 * @jest-environment jsdom
 */

import * as React from 'react';

import {
    MmuiTableComponent,
    MmuiProps,
    MmuiState,
} from '../../../src/ts/mmui-react-component/common';
import { render } from '@testing-library/react';

export interface TestProps extends MmuiProps {
    empty?: boolean;
    error?: boolean;
}
class TestTableComponent extends MmuiTableComponent<TestProps, MmuiState> {
    render() {
        const row0 = this.props.empty ? this.createEmptyRow(1) : null;
        const row1 = this.props.error ? this.createErrorRow(1) : null;

        return (
            <table>
                <tbody>
                    {row0}
                    {row1}
                </tbody>
            </table>
        );
    }
}

describe('MmuiTableComponent', () => {
    test('createEmptyRow', () => {
        const { getByText } = render(<TestTableComponent empty={true} />);
        const emptyRow = getByText('No data available');
        expect(emptyRow).toBeTruthy();
    });
    test('createErrorRow', () => {
        const { getByText } = render(<TestTableComponent error={true} />);
        const errorRow = getByText('Unfortunately an error occurred.');
        expect(errorRow).toBeTruthy();
    });
});
