import { render } from '@testing-library/react';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import React from 'react';
import { TimeRule } from 'src/components/fingerprintRulesOAPanel/deliveryRules/delivery-rules';
import DeliverySummary from '../delivery-summary';
import type { FingerprintRule } from 'src/types';
import type { Props as DeliverySummaryProps } from '../delivery-summary';

dayjs.extend(utc);

describe('<DeliverySummary>', () => {
    const vendorRules = [
        {
            active: true,
            policy: 'Monetize',
            service: 'TikTok',
            territory: 'FR',
            startDate: dayjs
                .utc('2023-01-02T00:00:00.000Z')
                .format('D MMM YYYY'),
            endDate: '-',
            createdDate: dayjs
                .utc('2023-01-01T00:00:00.000Z')
                .format('D MMM YYYY'),
            lastModifiedDate: dayjs
                .utc('2023-01-01T00:00:00.000Z')
                .format('D MMM YYYY'),
            createdBy: {
                profileId: '123',
                profileType: 'ContentProfile',
                profileName: 'Name',
            },
            lastModifiedBy: {
                profileId: '123',
                profileType: 'ContentProfile',
                profileName: 'Name',
            },
        },
    ] as FingerprintRule[];
    const subaccountRules = [
        {
            active: true,
            policy: 'Monetize',
            service: 'TikTok',
            territory: 'US',
            startDate: dayjs
                .utc('2023-01-02T00:00:00.000Z')
                .format('D MMM YYYY'),
            endDate: '-',
            createdDate: dayjs
                .utc('2023-01-01T00:00:00.000Z')
                .format('D MMM YYYY'),
            lastModifiedDate: dayjs
                .utc('2023-01-01T00:00:00.000Z')
                .format('D MMM YYYY'),
            createdBy: {
                profileId: '123',
                profileType: 'ContentProfile',
                profileName: 'Name',
            },
            lastModifiedBy: {
                profileId: '123',
                profileType: 'ContentProfile',
                profileName: 'Name',
            },
        },
    ] as FingerprintRule[];

    const defaultProps: DeliverySummaryProps = {
        vendorRules,
        subaccountRules,
        timeRuleFilter: TimeRule.active,
    };

    const renderWrapper = (props: Partial<DeliverySummaryProps> = {}) =>
        render(<DeliverySummary {...defaultProps} {...props} />);

    test('renders active summary', () => {
        const { container } = renderWrapper();
        expect(container).toMatchSnapshot();
    });

    test('renders empty summary for expired', () => {
        const { container } = renderWrapper({
            timeRuleFilter: TimeRule.expired,
        });
        expect(container).toMatchSnapshot();
    });
});
