import React from 'react';
import { injectIntl } from 'react-intl';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import {render, screen, fireEvent } from '../../../utils/test-utils';
import {CapFacebookPreview} from '../index';
import { facebookImgMockData, getPreviewActionCalledWith } from './mockdata';

const ComponentToRender = injectIntl(CapFacebookPreview);
const renderComponent = props => render(<ComponentToRender {...props} />);


const getPreview = jest.fn();
const clearPreview = jest.fn();


describe("CapFacebookPreview Test",()=>{
    it("It should call getPreview action with appropriate fields", ()=>{
        const facebookPreviewActions = {
            getPreview,
            clearPreview
        }

        const props = {
            ...facebookImgMockData, 
            facebookPreviewActions

        }

        renderComponent(props);

        const generatePreviewBtn = screen.getByRole('button', { name: /generate preview/i});
        expect(generatePreviewBtn).toBeEnabled();

        fireEvent.click(generatePreviewBtn);

        expect(getPreview).toHaveBeenCalledTimes(1);
        expect(getPreview).toHaveBeenCalledWith(getPreviewActionCalledWith);
    })
})