import React from 'react';
import { renderInAppContext } from '@theorchard/suite-testing';
import { metadataErrorReport } from 'lib/test/mockMetadataErrorReport';
import {
    getProductColumnDefs,
    getProjectColumnDefs,
    hasProductErrors,
    hasProjectErrors,
    MetadataErrorReportTable,
} from '../metadataErrorReport';
import JSONableProductErrorReport from '../productErrorReport';
import JSONableProjectErrorReport from '../projectErrorReport';
import { Product, Project } from '../types';

describe('<MetadataErrorReportTable />', () => {
    test('matches snapshot (Product)', () => {
        const component = renderInAppContext(
            <MetadataErrorReportTable<Product>
                loading={false}
                entities={metadataErrorReport.products}
                page={0}
                pageSize={10}
                totalEntityCount={1}
                columnDefs={getProductColumnDefs()}
                hasErrors={hasProductErrors}
                renderErrorReport={product => (
                    <JSONableProductErrorReport product={product} />
                )}
                onPageChange={() => null}
                onPageSizeChange={() => null}
            />
        );
        expect(component).toMatchSnapshot();
    });
    test('matches snapshot (Project)', () => {
        const component = renderInAppContext(
            <MetadataErrorReportTable<Project>
                loading={false}
                entities={metadataErrorReport.projects}
                page={0}
                pageSize={10}
                totalEntityCount={4}
                columnDefs={getProjectColumnDefs()}
                hasErrors={hasProjectErrors}
                renderErrorReport={project => (
                    <JSONableProjectErrorReport project={project} />
                )}
                onPageChange={() => null}
                onPageSizeChange={() => null}
            />
        );
        expect(component).toMatchSnapshot();
    });
});
