import React from 'react';
import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';

import { TemplatePreview } from '../index';

describe('Test Templates container', () => {
  let renderedComponent;

  const renderFunction = (
    channel,
    content,
    whatsappAccountName,
    whatsappContentLen,
    templateData
  ) => {
    renderedComponent = shallowWithIntl(
      <TemplatePreview
        channel={channel}
        content={content}
        whatsappAccountName={whatsappAccountName}
        whatsappContentLen={whatsappContentLen}
        templateData={templateData}
      />,
    );
  };

  it('Should render correct preview component for whatsapp channel', () => {
    renderFunction(
      'whatsapp',
      {
        templateMsg: 'You have received {{1}} points',
        whatsappImageSrc: 'https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/c9edc114-923b-4ac7-82d0-d6682213.jpg',
        ctaData: [
          {
            index: 0,
            type: 'PHONE_NUMBER',
            text: 'Call',
            phone_number: '+917892303868',
          },
          {
            index: 1,
            type: 'STATIC_URL',
            text: 'Visit',
            url: 'https://www.capillarytech.com/',
          },
        ],
      },
      'test',
      30,
    );
    expect(renderedComponent).toMatchSnapshot();
    renderFunction(
      'whatsapp',
      {
        templateMsg: 'You have received {{1}} points',
        whatsappImageSrc: '',
        ctaData: [{}],
      },
      'test',
      30,
    );
    expect(renderedComponent).toMatchSnapshot();
    renderFunction('whatsapp', {}, 'test', 0);
    expect(renderedComponent).toMatchSnapshot();
  });
  it('Should render correct preview component for zalo channel', () => {
    renderFunction('zalo', {}, '', '', {
      templatePreviewUrl: 'https://account.zalo.cloud/znspreview/-CL4HT4Hwza4v5ocK3pdVQ=='
    });
    expect(renderedComponent).toMatchSnapshot();
  });
});
