import * as apollo from '@apollo/client';
import { render } from '@testing-library/react';
import { ToastProvider } from '@theorchard/suite-frontend';
import React from 'react';
import { FingerprintRestrictionsOAPanel } from '../fingerprint-restrictions-oa-panel';

describe('<FingerprintRestrictionsOAPanel>', () => {
    const useQuerySpy = jest.spyOn(apollo, 'useQuery');

    const renderWrapper = () =>
        render(
            <ToastProvider>
                <FingerprintRestrictionsOAPanel />
            </ToastProvider>
        );

    test('renders loading OA panel', () => {
        useQuerySpy.mockImplementation(
            () =>
                ({
                    loading: true,
                    data: undefined,
                }) as apollo.QueryResult<unknown, apollo.OperationVariables>
        );
        const { container } = renderWrapper();
        expect(container).toMatchSnapshot();
    });

    test('renders empty state OA panel', () => {
        useQuerySpy.mockImplementation(
            () =>
                ({
                    loading: false,
                    data: undefined,
                }) as apollo.QueryResult<unknown, apollo.OperationVariables>
        );
        const { container } = renderWrapper();
        expect(container).toMatchSnapshot();
    });

    test('renders error state OA panel', () => {
        useQuerySpy.mockImplementation(
            () =>
                ({
                    loading: false,
                    error: new Error('some error here'),
                    data: undefined,
                }) as apollo.QueryResult<unknown, apollo.OperationVariables>
        );
        const { container } = renderWrapper();
        expect(container).toMatchSnapshot();
    });
});
