{"size": 2197, "ext": "js", "max_stars_repo_path": "src/components/link/__tests__/CdrLink.spec.js", "max_stars_repo_name": "jtimberlake/rei-cedar", "max_stars_repo_stars_event_min_datetime": "2016-02-03T23:08:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T06:24:51.000Z", "max_issues_repo_path": "src/components/link/__tests__/CdrLink.spec.js", "max_issues_repo_name": "rei/rei-cedar", "max_issues_repo_issues_event_min_datetime": "2016-02-05T00:33:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T20:46:49.000Z", "max_forks_repo_path": "src/components/link/__tests__/CdrLink.spec.js", "max_forks_repo_name": "jtimberlake/rei-cedar", "max_forks_repo_forks_event_min_datetime": "2016-02-03T23:51:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T02:57:12.000Z"}
{"max_stars_count": 117, "max_issues_count": 482, "max_forks_count": 23, "avg_line_length": 24.6853932584, "max_line_length": 74, "alphanum_fraction": 0.5716886664}
import { shallowMount, mount } from '@vue/test-utils';
import sinon from 'sinon';
import CdrLink from 'componentdir/link/CdrLink';

describe('CdrLink', () => {
  test('renders correctly', () => {
    const wrapper = mount(CdrLink);
    expect(wrapper.element).toMatchSnapshot();
  });

  it('sets target attr correctly', () => {
    const wrapper = shallowMount(CdrLink, {
      propsData: {
        target: '_self',
      },
    });
    expect(wrapper.attributes().target).toBe('_self');
  });

  it('sets a default href', () => {
    const wrapper = shallowMount(CdrLink, {
      propsData: {
        href: 'www.rei.com'
      }
    });
    expect(wrapper.attributes().href).toBe('www.rei.com');
  });

  it('sets a default link text', () => {
    const wrapper = shallowMount(CdrLink);
    expect(wrapper.text()).toBe('#');
  });

  it('sets rel attr correctly', () => {
    const wrapper = shallowMount(CdrLink, {
      propsData: {
        rel: 'nofollow',
      },
    });
    expect(wrapper.attributes().rel).toBe('nofollow');
  });

  it('computes target="_blank" rel attr correctly', () => {
    const wrapper = shallowMount(CdrLink, {
      propsData: {
        target: '_blank',
      },
    });
    expect(wrapper.attributes().rel).toBe('noopener noreferrer');
  });

  it('computes the base class correctly', () => {
    const wrapper = shallowMount(CdrLink);
    expect(wrapper.classes()).toContain('cdr-link');
  });

  it('computes classes correctly for standalone modifier', () => {
    const wrapper = shallowMount(CdrLink, {
      propsData: {
        modifier: 'standalone',
      },
    });
    expect(wrapper.classes()).toContain('cdr-link--standalone');
  });

  it('renders a link with a button element and no href attribute', () => {
    const wrapper = mount(CdrLink, {
      propsData: {
        tag: 'button',
      },
    });
    expect(wrapper.element).toMatchSnapshot();
  });

  it('emits a click', () => {
    const spy = sinon.spy();
    const wrapper = shallowMount(CdrLink, {
      propsData: {
        tag: 'button',
      },
      listeners: {
        'click': spy
      },
    });
    wrapper.trigger('click');
    expect(spy.called).toBeTruthy();
  });
});
