summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/clone_dropdown_spec.js
blob: 5b8576ad761d8753022bc0966ffd4a388720b24b (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
73
74
import { shallowMount } from '@vue/test-utils';
import { GlFormInputGroup, GlDropdownSectionHeader } from '@gitlab/ui';
import CloneDropdown from '~/vue_shared/components/clone_dropdown.vue';

describe('Clone Dropdown Button', () => {
  let wrapper;
  const sshLink = 'ssh://foo.bar';
  const httpLink = 'http://foo.bar';
  const httpsLink = 'https://foo.bar';
  const defaultPropsData = {
    sshLink,
    httpLink,
  };

  const createComponent = (propsData = defaultPropsData) => {
    wrapper = shallowMount(CloneDropdown, {
      propsData,
      stubs: {
        'gl-form-input-group': GlFormInputGroup,
      },
    });
  };

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  describe('rendering', () => {
    it('matches the snapshot', () => {
      createComponent();
      expect(wrapper.element).toMatchSnapshot();
    });

    it.each`
      name      | index | value
      ${'SSH'}  | ${0}  | ${sshLink}
      ${'HTTP'} | ${1}  | ${httpLink}
    `('renders correct link and a copy-button for $name', ({ index, value }) => {
      createComponent();
      const group = wrapper.findAll(GlFormInputGroup).at(index);
      expect(group.props('value')).toBe(value);
      expect(group.find(GlFormInputGroup).exists()).toBe(true);
    });

    it.each`
      name          | value
      ${'sshLink'}  | ${sshLink}
      ${'httpLink'} | ${httpLink}
    `('does not fail if only $name is set', ({ name, value }) => {
      createComponent({ [name]: value });

      expect(wrapper.find(GlFormInputGroup).props('value')).toBe(value);
      expect(wrapper.findAll(GlDropdownSectionHeader).length).toBe(1);
    });
  });

  describe('functionality', () => {
    it.each`
      name          | value
      ${'sshLink'}  | ${null}
      ${'httpLink'} | ${null}
    `('allows null values for the props', ({ name, value }) => {
      createComponent({ ...defaultPropsData, [name]: value });

      expect(wrapper.findAll(GlDropdownSectionHeader).length).toBe(1);
    });

    it('correctly calculates httpLabel for HTTPS protocol', () => {
      createComponent({ httpLink: httpsLink });
      expect(wrapper.find(GlDropdownSectionHeader).text()).toContain('HTTPS');
    });
  });
});