import React from 'react';
import { screen } from '@testing-library/react';
import { renderInAppContext } from '@theorchard/suite-testing';
import {
    ClosePeriodAction,
    type ClosePeriodActionPropTypes,
} from 'src/components/accounting-period/close-period-action';
import { ABACUS_ACTION_STATUSES } from '@theorchard/accounting-apps-shared';
import { ACCOUNTING_PERIOD_STATUSES } from 'src/constants';

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

    describe('Close Period Actions State', () => {
        it('displays the running icon when action is in a state of "running"', () => {
            const props = {
                accountingPeriodStatus: ACCOUNTING_PERIOD_STATUSES.LOCKED,
                periodClosed: ABACUS_ACTION_STATUSES.RUNNING,
            };

            render(props);
            expect(screen.queryByTestId('ActionStatusIcon-running')).toBeNull();
        });

        it('displays period closed text when action is in a state of "complete"', () => {
            const props = {
                accountingPeriodStatus: ACCOUNTING_PERIOD_STATUSES.CLOSED,
                periodClosed: ABACUS_ACTION_STATUSES.COMPLETE,
            };
            render(props);

            expect(screen.getByText('Period Closed')).toBeDefined();
        });
    });
});
