import React from 'react';
import { screen } from '@testing-library/react';
import { renderInAppContext } from '@theorchard/suite-testing';
import { AbacusContractMechDeductionAdminType } from 'src/apollo/definitions/globalTypes';
import {
    ContractMechanicalDeductionAdminTypes,
    ContractMechanicalDeductionAdminTypesPropTypes,
} from 'src/components/contract-mechanical-deduction-shared/contract-mechanical-deduction-admin-types';

describe('<ContractMechanicalDeductionAdminTypes />', () => {
    const defaultProps: ContractMechanicalDeductionAdminTypesPropTypes = {
        adminType: AbacusContractMechDeductionAdminType.BUSINESS,
        handleFormChange: jest.fn(),
    };

    const render = (
        props: ContractMechanicalDeductionAdminTypesPropTypes = defaultProps
    ) =>
        renderInAppContext(
            <ContractMechanicalDeductionAdminTypes {...props} />
        );

    it('renders Admin Types', () => {
        render();
        expect(
            screen.getByText('Who Pays For The Deductions?')
        ).toBeInTheDocument();

        expect(screen.getByText('Customer')).toBeInTheDocument();
        expect(screen.getByText('Business')).toBeInTheDocument();
        expect(screen.getByText('Both')).toBeInTheDocument();
    });

    it('renders "Business" admin type selected', () => {
        render();
        const adminTypes = screen.getAllByTestId('AdminTypesOptions');
        expect(adminTypes[0]).not.toBeChecked();
        expect(adminTypes[1]).toBeChecked();
        expect(adminTypes[2]).not.toBeChecked();
    });
});
