Welcome to mirror list, hosted at ThFree Co, Russian Federation.

link_cell_spec.js « cells « components « runner « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 61bb4432c8efbd44fbac6a40e8f825c4109a9da8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { GlLink } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import LinkCell from '~/ci/runner/components/cells/link_cell.vue';

describe('LinkCell', () => {
  let wrapper;

  const findGlLink = () => wrapper.findComponent(GlLink);
  const findSpan = () => wrapper.find('span');

  const createComponent = ({ props = {}, ...options } = {}) => {
    wrapper = shallowMountExtended(LinkCell, {
      propsData: {
        ...props,
      },
      ...options,
    });
  };

  it('when an href is provided, renders a link', () => {
    createComponent({ props: { href: '/url' } });
    expect(findGlLink().exists()).toBe(true);
  });

  it('when an href is not provided, renders no link', () => {
    createComponent();
    expect(findGlLink().exists()).toBe(false);
  });

  describe.each`
    href      | findContent
    ${null}   | ${findSpan}
    ${'/url'} | ${findGlLink}
  `('When href is $href', ({ href, findContent }) => {
    const content = 'My Text';
    const attrs = { foo: 'bar' };
    const listeners = {
      click: jest.fn(),
    };

    beforeEach(() => {
      createComponent({
        props: { href },
        slots: {
          default: content,
        },
        attrs,
        listeners,
      });
    });

    afterAll(() => {
      listeners.click.mockReset();
    });

    it('Renders content', () => {
      expect(findContent().text()).toBe(content);
    });

    it('Passes attributes', () => {
      expect(findContent().attributes()).toMatchObject(attrs);
    });

    it('Passes event listeners', () => {
      expect(listeners.click).toHaveBeenCalledTimes(0);

      findContent().vm.$emit('click');

      expect(listeners.click).toHaveBeenCalledTimes(1);
    });
  });
});