summaryrefslogtreecommitdiff
path: root/spec/frontend/environments/environment_details/components/deployment_job_spec.js
blob: 9bb61abb2935fd02cad029d589c61ff7c759ddd6 (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
import { GlTruncate, GlLink, GlBadge } from '@gitlab/ui';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import DeploymentJob from '~/environments/environment_details/components/deployment_job.vue';

describe('app/assets/javascripts/environments/environment_details/components/deployment_job.vue', () => {
  const jobData = {
    webPath: 'http://example.com',
    label: 'example job',
  };
  let wrapper;

  const createWrapper = ({ job }) => {
    return mountExtended(DeploymentJob, {
      propsData: {
        job,
      },
    });
  };

  describe('when the job data exists', () => {
    beforeEach(() => {
      wrapper = createWrapper({ job: jobData });
    });

    it('should render a link with a correct href', () => {
      const jobLink = wrapper.findComponent(GlLink);
      expect(jobLink.exists()).toBe(true);
      expect(jobLink.attributes().href).toBe(jobData.webPath);
    });
    it('should render a truncated label', () => {
      const truncatedLabel = wrapper.findComponent(GlTruncate);
      expect(truncatedLabel.exists()).toBe(true);
      expect(truncatedLabel.props().text).toBe(jobData.label);
    });
  });

  describe('when the job data does not exist', () => {
    beforeEach(() => {
      wrapper = createWrapper({ job: null });
    });

    it('should render a badge with the text "API"', () => {
      const badge = wrapper.findComponent(GlBadge);
      expect(badge.exists()).toBe(true);
      expect(badge.props().variant).toBe('info');
      expect(badge.text()).toBe('API');
    });
  });
});