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

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

describe("test for document upload", () => {
  const props = {
    allowedExtensionsRegex: (/\.(mp4)$/i),
    videoSize: 16000000,
    uploadAsset: jest.fn(),
    supportedExtensions: '',
    uploadedAssetList: {},
    updateDocumentSrc: jest.fn(),
    updateOnReUpload: jest.fn(),
    index: 0,
    className: 'cap-custom-video-upload',
    videoData: {},
    channel: 'WHATSAPP',
    onVideoUploadUpdateAssestList: jest.fn(),
  };
  it("test for cap document upload", () => {
    renderComponent(props);
    expect(
      screen.getByText(/file size: up to 16 mb/i)
    ).toBeInTheDocument();
    expect(
      screen.getByText(
        /format: mp4/i)
    ).toBeInTheDocument();
    expect(
      screen.getByText(/drag and drop video here/i)
    ).toBeInTheDocument();
    const button = screen.getByRole('button', {
      name: /drag and drop video here or select from computer/i,
    });
    userEvent.click(button);
  });
  it("test for cap document upload 1", () => {
    const props1 = {
      ...props,
      videoData: {
        uploadedAssetData0: {
          _id: "63f3126a8f9d2d85450a99d3",
          type: "VIDEO",
          isActive: true,
          name: "sample_960x540_Xs2E4anK.mp4",
          createdBy: "15000449",
          updatedBy: "15000449",
          orgId: 50074,
          metaInfo: {
            file_handle: null,
            name: "sample_960x540_Xs2E4anK.mp4",
            content_type: null,
            file_size: 1320775,
            added_on: 1676874342000,
            last_modified_on: 1676874342000,
            acl: null,
            secure_file_path: "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/69d66812-291f-4658-9da8-c6d30eef.mp4",
            public_url: "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/69d66812-291f-4658-9da8-c6d30eef.mp4",
            video_file_path_preview: "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/video_screenshot_assets__1676874342082.png/1040"
          },
          createdAt: "2023-02-20T06:25:46.637Z",
          updatedAt: "2023-02-20T06:25:46.637Z",
          __v: 0,
        },
      },
      uploadedAssetList: {
        videoSrc: "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/69d66812-291f-4658-9da8-c6d30eef.mp4",
        videoId: "",
        videoName: "sample_960x540_Xs2E4anK.mp4",
        videoHeight: 540,
        videoWidth: 960,
        previewUrl: "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/video_screenshot_assets__1676874342082.png/1040"
      },
    };
    renderComponent(props1);
    const reUploadBtn = screen.getByText(/re upload/i);
    userEvent.click(reUploadBtn);
  });
});
