/**
 * @jest-environment jsdom
 */
import React from 'react';
import renderer from 'react-test-renderer';
import Rule from '../Rule';

describe('Rule Component - ', () => {
    it('Renders correctly with basic required params', () => {
        const item = renderer.create(<Rule title="EA Rule Title" link="/support/cases" description="Test Rule Render" onHide={jest.fn()}/>).toJSON();
        expect(item).toMatchSnapshot();
    });
    it('Renders markdown links in description correctly (with target blank)', () => {
        const item = renderer.create(<Rule
            title="EA Rule Title"
            link="/support/cases"
            description={`[Contact Customer Service](/support/contact) for help. Test **bold** text. \n1. OL1\n2. OL2\n- UL1\n- UL2`}
            onHide={jest.fn()}/>).toJSON();
        expect(item).toMatchSnapshot();
    });
    it(`Doesn't render <a> tag when link is not passed`, () => {
        const item = renderer.create(<Rule title="EA Rule Title" description="Test Rule Render" onHide={jest.fn()}/>).toJSON();
        expect(item).toMatchSnapshot();
    });
    it(`Doesn't render <a> tag when link is empty`, () => {
        const item = renderer.create(<Rule title="EA Rule Title" link="" description="Test Rule Render" onHide={jest.fn()}/>).toJSON();
        expect(item).toMatchSnapshot();
    });
    it(`Doesn't render <a> tag when link is null`, () => {
        const item = renderer.create(<Rule title="EA Rule Title" link={null} description="Test Rule Render" onHide={jest.fn()}/>).toJSON();
        expect(item).toMatchSnapshot();
    });
    it(`Doesn't render <a> tag when link is undefined`, () => {
        const item = renderer.create(<Rule title="EA Rule Title" link={undefined} description="Test Rule Render" onHide={jest.fn()}/>).toJSON();
        expect(item).toMatchSnapshot();
    });
});
