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

pipelines_artifacts_spec.js « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2d876841e06ba3060f28303f5c6eb7db06ba00db (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
import { GlDropdown, GlDropdownItem, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import PipelineArtifacts from '~/pipelines/components/pipelines_list/pipelines_artifacts.vue';

describe('Pipelines Artifacts dropdown', () => {
  let wrapper;

  const artifacts = [
    {
      name: 'job my-artifact',
      path: '/download/path',
    },
    {
      name: 'job-2 my-artifact-2',
      path: '/download/path-two',
    },
  ];
  const pipelineId = 108;

  const createComponent = ({ mockArtifacts = artifacts } = {}) => {
    wrapper = shallowMount(PipelineArtifacts, {
      propsData: {
        pipelineId,
        artifacts: mockArtifacts,
      },
      stubs: {
        GlSprintf,
      },
    });
  };

  const findDropdown = () => wrapper.findComponent(GlDropdown);
  const findFirstGlDropdownItem = () => wrapper.find(GlDropdownItem);
  const findAllGlDropdownItems = () => wrapper.find(GlDropdown).findAll(GlDropdownItem);

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

  it('should render a dropdown with all the provided artifacts', () => {
    createComponent();

    expect(findAllGlDropdownItems()).toHaveLength(artifacts.length);
  });

  it('should render a link with the provided path', () => {
    createComponent();

    expect(findFirstGlDropdownItem().attributes('href')).toBe(artifacts[0].path);
    expect(findFirstGlDropdownItem().text()).toBe(artifacts[0].name);
  });

  describe('with no artifacts', () => {
    it('should not render the dropdown', () => {
      createComponent({ mockArtifacts: [] });

      expect(findDropdown().exists()).toBe(false);
    });
  });
});