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

ci_resource_header_spec.js « details « components « catalog « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c061332ba136811487a1e03d759087da5bb810dd (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { GlAvatar, GlAvatarLink, GlBadge } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import CiResourceHeader from '~/ci/catalog/components/details/ci_resource_header.vue';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import CiResourceAbout from '~/ci/catalog/components/details/ci_resource_about.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import { catalogSharedDataMock, catalogAdditionalDetailsMock } from '../../mock';

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

  const resource = { ...catalogSharedDataMock.data.ciCatalogResource };
  const resourceAdditionalData = { ...catalogAdditionalDetailsMock.data.ciCatalogResource };

  const defaultProps = {
    openIssuesCount: resourceAdditionalData.openIssuesCount,
    openMergeRequestsCount: resourceAdditionalData.openMergeRequestsCount,
    isLoadingDetails: false,
    isLoadingSharedData: false,
    resource,
  };

  const findAboutComponent = () => wrapper.findComponent(CiResourceAbout);
  const findAvatar = () => wrapper.findComponent(GlAvatar);
  const findAvatarLink = () => wrapper.findComponent(GlAvatarLink);
  const findVersionBadge = () => wrapper.findComponent(GlBadge);
  const findPipelineStatusBadge = () => wrapper.findComponent(CiIcon);

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

  describe('when mounted', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders the project name and description', () => {
      expect(wrapper.html()).toContain(resource.name);
      expect(wrapper.html()).toContain(resource.description);
    });

    it('renders the namespace and project path', () => {
      expect(wrapper.html()).toContain(resource.rootNamespace.fullPath);
      expect(wrapper.html()).toContain(resource.rootNamespace.name);
    });

    it('renders the avatar', () => {
      const { id, name } = resource;

      expect(findAvatar().exists()).toBe(true);
      expect(findAvatarLink().exists()).toBe(true);
      expect(findAvatar().props()).toMatchObject({
        entityId: getIdFromGraphQLId(id),
        entityName: name,
      });
    });

    it('renders the catalog about section and passes props', () => {
      expect(findAboutComponent().exists()).toBe(true);
      expect(findAboutComponent().props()).toEqual({
        isLoadingDetails: false,
        isLoadingSharedData: false,
        openIssuesCount: defaultProps.openIssuesCount,
        openMergeRequestsCount: defaultProps.openMergeRequestsCount,
        latestVersion: resource.latestVersion,
        webPath: resource.webPath,
      });
    });
  });

  describe('Version badge', () => {
    describe('without a version', () => {
      beforeEach(() => {
        createComponent({ props: { resource: { ...resource, latestVersion: null } } });
      });

      it('does not render', () => {
        expect(findVersionBadge().exists()).toBe(false);
      });
    });

    describe('with a version', () => {
      beforeEach(() => {
        createComponent();
      });

      it('renders', () => {
        expect(findVersionBadge().exists()).toBe(true);
      });
    });
  });

  describe('when the project has a release', () => {
    const pipelineStatus = {
      detailsPath: 'path/to/pipeline',
      icon: 'status_success',
      text: 'passed',
      group: 'success',
    };

    describe.each`
      hasPipelineBadge | describeText | testText             | status
      ${true}          | ${'is'}      | ${'renders'}         | ${pipelineStatus}
      ${false}         | ${'is not'}  | ${'does not render'} | ${{}}
    `('and there $describeText a pipeline', ({ hasPipelineBadge, testText, status }) => {
      beforeEach(() => {
        createComponent({
          props: {
            pipelineStatus: status,
            latestVersion: { tagName: '1.0.0', tagPath: 'path/to/release' },
          },
        });
      });

      it('renders the version badge', () => {
        expect(findVersionBadge().exists()).toBe(true);
      });

      it(`${testText} the pipeline status badge`, () => {
        expect(findPipelineStatusBadge().exists()).toBe(hasPipelineBadge);
        if (hasPipelineBadge) {
          expect(findPipelineStatusBadge().props()).toEqual({
            showStatusText: true,
            status: pipelineStatus,
            showTooltip: true,
            useLink: true,
          });
        }
      });
    });
  });
});