import React from 'react';
import { screen } from '@testing-library/react';
import { renderInAppContext } from '@theorchard/suite-testing';
import {
    ContractTable,
    ContractTablePropTypes,
} from 'src/components/contract-list/contract-table';

describe('<ContractTable>', () => {
    const render = (props: ContractTablePropTypes) =>
        renderInAppContext(<ContractTable {...props} />);

    const contracts = [
        {
            accountId: '1',
            accountName: 'Test Account 1',
            contractId: '1',
            contractName: 'Test Contract 1',
            contractType: 'Distribution',
            includedOrExcludedFromRun: 'excluded',
            contractStatus: 'ACTIVE',
            runController: 'Test Run Controller',
        },
        {
            accountId: '2',
            accountName: 'Test Account 2',
            contractId: '2',
            contractName: 'Test Contract 2',
            contractType: 'Distribution',
            includedOrExcludedFromRun: 'excluded',
            contractStatus: 'ACTIVE',
            runController: 'Test Run Controller',
        },
    ];

    const props: ContractTablePropTypes = {
        contractList: contracts,
        contractsTotalCount: 2,
        isFiltered: false,
        isLoading: false,
        hasFilterApplied: false,
        onClearFilters: jest.fn(),
        page: 0,
        setPage: jest.fn(),
        pageSize: 2,
        setPageSize: jest.fn(),
    };

    it('renders a list of contracts', () => {
        render(props);
        const gridTable = screen.getByTestId('sectionTable');
        expect(gridTable).toHaveTextContent('Test Contract 1');
        expect(gridTable).toHaveTextContent('Test Contract 2');
    });

    it('renders included/excluded from run data', () => {
        render(props);
        const gridTable = screen.getByTestId('sectionTable');
        expect(gridTable).toHaveTextContent(
            contracts[0].includedOrExcludedFromRun
        );
    });

    it('renders run controller data', () => {
        render(props);
        const gridTable = screen.getByTestId('sectionTable');
        expect(gridTable).toHaveTextContent(contracts[0].runController);
    });

    it('renders contract status data', () => {
        render(props);
        const gridTable = screen.getByTestId('sectionTable');
        expect(gridTable).toHaveTextContent(contracts[0].contractStatus);
    });
});
