import React from 'react';
import { screen } from '@testing-library/react';
import { renderInAppContext } from '@theorchard/suite-testing';
import EntityBulkEditProcessingStatus from '../entity-bulk-edit-processing-status';

describe('<EntityBulkEditProcessingStatus>', () => {
    const makeEntry = (id: string) => ({
        id: id,
        contractTermId: id,
        contractTermName: null,
        currentAttachments: null,
        contractName: null,
        contractId: null,
        attachmentsToAppend: null,
        attachmentsToSet: null,
        calculatedAttachments: null,
    });

    const renderComponent = (
        p: React.ComponentProps<typeof EntityBulkEditProcessingStatus>
    ) => renderInAppContext(<EntityBulkEditProcessingStatus {...p} />);

    it('shows loading status when in progress', () => {
        renderComponent({
            success: [makeEntry('1')],
            failed: [],
            all: [makeEntry('1'), makeEntry('2')],
        });

        expect(
            screen.getByText(/Processing 1\/2, success: 1, failed: 0/i)
        ).toBeDefined();
    });

    it('shows success and failed alerts when complete', () => {
        renderComponent({
            success: [makeEntry('1')],
            failed: [
                {
                    entry: makeEntry('2'),
                    error: {},
                    message: 'Term not found.',
                },
            ],
            all: [makeEntry('1'), makeEntry('2')],
        });

        expect(
            screen.getByText(/Success import of 1 out of 2 entities\./i)
        ).toBeDefined();
        expect(
            screen.getByText(/Failed import of 1 out of 2 entities\./i)
        ).toBeDefined();
    });
});
