import React from 'react';
import TestUtils from 'react-dom/test-utils';
import Fieldset from './fieldset';
import Textbox from './../textbox';
import { shallow } from 'enzyme';
import { elementsTagTest, rootTagTest } from '../../utils/helpers/tags/tags-specs';

describe('Fieldset', () => {
  let instance;

  beforeEach(() => {
    instance = TestUtils.renderIntoDocument(<Fieldset><Textbox /></Fieldset>);
  });

  it('renders its children', () => {
    let child = TestUtils.findRenderedComponentWithType(instance, Textbox);
    expect(child).toBeDefined();
  });

  it('applies any props to the fieldset', () => {
    instance = TestUtils.renderIntoDocument(<Fieldset id="foo"><Textbox /></Fieldset>);
    let child = TestUtils.findRenderedDOMComponentWithTag(instance, 'fieldset');
    expect(child.id).toEqual('foo');
  });

  describe('if a legend is supplied', () => {
    it('renders its legend', () => {
      instance = TestUtils.renderIntoDocument(<Fieldset legend="foo"><Textbox /></Fieldset>);
      let child = TestUtils.findRenderedDOMComponentWithTag(instance, 'legend');
      expect(child).toBeDefined();
    });
  });

  describe("tags", () => {
    describe("on component", () => {
      let wrapper = shallow(<Fieldset data-element='bar' data-role='baz' />);

      it('include correct component, element and role data tags', () => {
        rootTagTest(wrapper, 'fieldset', 'bar', 'baz');
      });
    });

    describe("on internal elements", () => {
      let wrapper = shallow(<Fieldset legend='test' />);

      elementsTagTest(wrapper, [
        'legend'
      ]);
    });
  });
});

import React from 'react';
import { shallow } from 'enzyme';
import Fieldset from './fieldset.component';
import Textbox from '../textbox';
import { LegendStyle } from './fieldset.style';

function render(props, renderType = shallow) {
  return renderType(
    <Fieldset { ...props }>
      <Textbox />
    </Fieldset>
  );
}

describe('Fieldset', () => {
  it('renders its children', () => {
    const wrapper = render();
    expect(wrapper.find(Textbox).length).toEqual(1);
  });

  describe('Fieldset Legend', () => {
    it('is rendered if supplied', () => {
      const wrapper = render({ legend: 'Legend' });
      expect(wrapper.find(LegendStyle).length).toEqual(1);
    });
  });
});

Update Specs for New Fieldset
Update Specs for New Fieldset
