summaryrefslogtreecommitdiff
path: root/spec/frontend/packages/shared/components/publish_method_spec.js
blob: 6014774990cf1fa9822098b020651b32a8065d32 (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
import { shallowMount } from '@vue/test-utils';
import PublishMethod from '~/packages/shared/components/publish_method.vue';
import { packageList } from '../../mock_data';

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

  const [packageWithoutPipeline, packageWithPipeline] = packageList;

  const findPipelineRef = () => wrapper.find('[data-testid="pipeline-ref"]');
  const findPipelineSha = () => wrapper.find('[data-testid="pipeline-sha"]');
  const findManualPublish = () => wrapper.find('[data-testid="manually-published"]');

  const mountComponent = (packageEntity = {}, isGroup = false) => {
    wrapper = shallowMount(PublishMethod, {
      propsData: {
        packageEntity,
        isGroup,
      },
    });
  };

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

  it('renders', () => {
    mountComponent(packageWithPipeline);
    expect(wrapper.element).toMatchSnapshot();
  });

  describe('pipeline information', () => {
    it('displays branch and commit when pipeline info exists', () => {
      mountComponent(packageWithPipeline);

      expect(findPipelineRef().exists()).toBe(true);
      expect(findPipelineSha().exists()).toBe(true);
    });

    it('does not show any pipeline details when no information exists', () => {
      mountComponent(packageWithoutPipeline);

      expect(findPipelineRef().exists()).toBe(false);
      expect(findPipelineSha().exists()).toBe(false);
      expect(findManualPublish().exists()).toBe(true);
      expect(findManualPublish().text()).toBe('Manually Published');
    });
  });
});