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

refs_list_spec.js « components « commit « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 594f8827d5858d6b4272c3575883fdde668d101f (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
75
76
77
import { GlCollapse, GlButton, GlBadge, GlSkeletonLoader } from '@gitlab/ui';
import RefsList from '~/projects/commit_box/info/components/refs_list.vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import {
  CONTAINING_COMMIT,
  FETCH_CONTAINING_REFS_EVENT,
} from '~/projects/commit_box/info/constants';
import { refsListPropsMock, containingBranchesMock } from '../mock_data';

describe('Commit references component', () => {
  let wrapper;
  const createComponent = (props = {}) => {
    wrapper = shallowMountExtended(RefsList, {
      propsData: {
        ...refsListPropsMock,
        ...props,
      },
    });
  };

  const findTitle = () => wrapper.findByTestId('title');
  const findCollapseButton = () => wrapper.findComponent(GlButton);
  const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader);
  const findTippingRefs = () => wrapper.findAllComponents(GlBadge);
  const findContainingRefs = () => wrapper.findComponent(GlCollapse);

  beforeEach(() => {
    createComponent();
  });

  it('renders the namespace passed', () => {
    expect(findTitle().text()).toEqual(refsListPropsMock.namespace);
  });

  it('renders list of tipping branches or tags', () => {
    expect(findTippingRefs()).toHaveLength(refsListPropsMock.tippingRefs.length);
  });

  it('does not render collapse with containing branches ot tags when there is no data', () => {
    createComponent({ hasContainingRefs: false });
    expect(findCollapseButton().exists()).toBe(false);
  });

  it('renders collapse component if commit has containing branches', () => {
    expect(findCollapseButton().text()).toContain(CONTAINING_COMMIT);
  });

  it('emits event when collapse button is clicked', () => {
    findCollapseButton().vm.$emit('click');
    expect(wrapper.emitted()[FETCH_CONTAINING_REFS_EVENT]).toHaveLength(1);
  });

  it('renders the list of containing branches or tags when collapse is expanded', () => {
    createComponent({ containingRefs: containingBranchesMock });
    const containingRefsList = findContainingRefs();
    expect(containingRefsList.findAllComponents(GlBadge)).toHaveLength(
      containingBranchesMock.length,
    );
  });

  it('renders links to refs', () => {
    const index = 0;
    const refBadge = findTippingRefs().at(index);
    const refUrl = `${refsListPropsMock.urlPart}${refsListPropsMock.tippingRefs[index]}`;
    expect(refBadge.attributes('href')).toBe(refUrl);
  });

  it('does not reneder list of tipping branches or tags if there is no data', () => {
    createComponent({ tippingRefs: [] });
    expect(findTippingRefs().exists()).toBe(false);
  });

  it('renders skeleton loader when isLoading prop has true value', () => {
    createComponent({ isLoading: true, containingRefs: [] });
    expect(findSkeletonLoader().exists()).toBe(true);
  });
});