MetaPhase-Consulting/State-TalentMAP

View on GitHub
src/Components/PositionTitleSubDescription/PositionTitleSubDescription.test.jsx

Summary

Maintainability
A
0 mins
Test Coverage
import { shallow } from 'enzyme';
import toJSON from 'enzyme-to-json';
import PositionTitleSubDescription from './PositionTitleSubDescription';

describe('PositionTitleSubDescriptionComponent', () => {
  it('is defined', () => {
    const wrapper = shallow(
      <PositionTitleSubDescription
        title="title"
        formattedContent={<span>content</span>}
        plainContent="content"
        shouldShowEditor={false}
        onSubmitText={() => {}}
        toggleEditor={() => {}}
        isAllowedToEdit
      />,
    );
    expect(wrapper).toBeDefined();
  });

  it('shows the editor button when the user has permission', () => {
    const wrapper = shallow(
      <PositionTitleSubDescription
        title="title"
        formattedContent={<span>content</span>}
        plainContent="content"
        shouldShowEditor={false}
        onSubmitText={() => {}}
        toggleEditor={() => {}}
        isAllowedToEdit
      />,
    );
    expect(wrapper.find('EditContentButton')).toHaveLength(1);
  });

  it('hides the editor button when the user does not have permission', () => {
    const wrapper = shallow(
      <PositionTitleSubDescription
        title="title"
        formattedContent={<span>content</span>}
        plainContent="content"
        shouldShowEditor={false}
        onSubmitText={() => {}}
        toggleEditor={() => {}}
        isAllowedToEdit={false}
      />,
    );
    expect(wrapper.find('EditContentButton')).toHaveLength(0);
  });

  it('matches snapshot when editor is hidden', () => {
    const wrapper = shallow(
      <PositionTitleSubDescription
        title="title"
        formattedContent={<span>content</span>}
        plainContent="content"
        shouldShowEditor={false}
        onSubmitText={() => {}}
        toggleEditor={() => {}}
        isAllowedToEdit
      />,
    );
    expect(toJSON(wrapper)).toMatchSnapshot();
  });

  it('matches snapshot when editor is shown', () => {
    const wrapper = shallow(
      <PositionTitleSubDescription
        title="title"
        formattedContent={<span>content</span>}
        plainContent="content"
        shouldShowEditor
        onSubmitText={() => {}}
        toggleEditor={() => {}}
        isAllowedToEdit
      />,
    );
    expect(toJSON(wrapper)).toMatchSnapshot();
  });
});