import React from 'react';
import { screen } from '@testing-library/react';
import { renderInAppContext } from '@theorchard/suite-testing';
import { WORKSHEET_PAYMENT_ACTTION_STATUS_MAP } from 'src/apollo/type-constants/advance';
import { paymentStatus } from '../payment-status';
import type { WorksheetPaymentContractAdvancesQuery } from 'src/apollo/queries/payment-group-payment/__generated__/worksheet-payment-contract-advances';

type ActionStates =
    WorksheetPaymentContractAdvancesQuery['worksheetPaymentContractAdvances']['items'][0]['actionStates'][0];

describe('paymentStatus', () => {
    it.each([
        ['init', 'neutral'],
        ['running', 'warning'],
        ['error', 'error'],
        ['rejected', 'error'],
        ['complete', 'success'],
    ])('renders status', (status, className) => {
        const statusText = String(WORKSHEET_PAYMENT_ACTTION_STATUS_MAP[status]);
        const actionStates = [
            {
                actionName: 'send_payments',
                actionStatus: status,
                lastModified: '2024-04-10',
                lastModifiedByIdentity: {
                    name: 'lastModifiedByIdentity Name',
                },
                message: `${status} message`,
                __typename: 'AbacusState',
            },
        ] as ActionStates[];
        const result = renderInAppContext(
            <div>{paymentStatus(actionStates)}</div>
        );
        expect(screen.getByText(statusText)).toBeDefined();
        expect(result.getByTestId('Status')).toHaveClass(
            `variant-${className}`
        );
    });
});
