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

job_container_item_spec.js « job « components « jobs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05c38dd74b7ab4c18e454fefa4a9d561c2ccf1f5 (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
import { GlIcon, GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import delayedJobFixture from 'test_fixtures/jobs/delayed.json';
import JobContainerItem from '~/jobs/components/job/sidebar/job_container_item.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import job from '../../mock_data';

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

  const findCiIconComponent = () => wrapper.findComponent(CiIcon);
  const findGlIconComponent = () => wrapper.findComponent(GlIcon);

  function createComponent(jobData = {}, props = { isActive: false, retried: false }) {
    wrapper = shallowMount(JobContainerItem, {
      propsData: {
        job: {
          ...jobData,
          retried: props.retried,
        },
        isActive: props.isActive,
      },
    });
  }

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

  describe('when a job is not active and not retried', () => {
    beforeEach(() => {
      createComponent(job);
    });

    it('displays a status icon', () => {
      const ciIcon = findCiIconComponent();

      expect(ciIcon.props('status')).toBe(job.status);
    });

    it('displays the job name', () => {
      expect(wrapper.text()).toContain(job.name);
    });

    it('displays a link to the job', () => {
      const link = wrapper.findComponent(GlLink);

      expect(link.attributes('href')).toBe(job.status.details_path);
    });
  });

  describe('when a job is active', () => {
    beforeEach(() => {
      createComponent(job, { isActive: true });
    });

    it('displays an arrow sprite icon', () => {
      const icon = findGlIconComponent();

      expect(icon.props('name')).toBe('arrow-right');
    });
  });

  describe('when a job is retried', () => {
    beforeEach(() => {
      createComponent(job, { isActive: false, retried: true });
    });

    it('displays a retry icon', () => {
      const icon = findGlIconComponent();

      expect(icon.props('name')).toBe('retry');
    });
  });

  describe('for a delayed job', () => {
    beforeEach(() => {
      const remainingMilliseconds = 1337000;
      jest
        .spyOn(Date, 'now')
        .mockImplementation(
          () => new Date(delayedJobFixture.scheduled_at).getTime() - remainingMilliseconds,
        );

      createComponent(delayedJobFixture);
    });

    it('displays remaining time in tooltip', async () => {
      await nextTick();

      const link = wrapper.findComponent(GlLink);

      expect(link.attributes('title')).toMatch('delayed job - delayed manual action (00:22:17)');
    });
  });
});