summaryrefslogtreecommitdiff
path: root/spec/frontend/jobs/components/table/cells.vue/duration_cell_spec.js
blob: 763a4b0eaa2273007de1b3aeedc0da75801f7fad (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
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import DurationCell from '~/jobs/components/table/cells/duration_cell.vue';

describe('Duration Cell', () => {
  let wrapper;

  const findJobDuration = () => wrapper.findByTestId('job-duration');
  const findJobFinishedTime = () => wrapper.findByTestId('job-finished-time');
  const findDurationIcon = () => wrapper.findByTestId('duration-icon');
  const findFinishedTimeIcon = () => wrapper.findByTestId('finished-time-icon');

  const createComponent = (props) => {
    wrapper = extendedWrapper(
      shallowMount(DurationCell, {
        propsData: {
          job: {
            ...props,
          },
        },
      }),
    );
  };

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

  it('does not display duration or finished time when no properties are present', () => {
    createComponent();

    expect(findJobDuration().exists()).toBe(false);
    expect(findJobFinishedTime().exists()).toBe(false);
  });

  it('displays duration and finished time when both properties are present', () => {
    const props = {
      duration: 7,
      finishedAt: '2021-04-26T13:37:52Z',
    };

    createComponent(props);

    expect(findJobDuration().exists()).toBe(true);
    expect(findJobFinishedTime().exists()).toBe(true);
  });

  it('displays only the duration of the job when the duration property is present', () => {
    const props = {
      duration: 7,
    };

    createComponent(props);

    expect(findJobDuration().exists()).toBe(true);
    expect(findJobFinishedTime().exists()).toBe(false);
  });

  it('displays only the finished time of the job when the finshedAt property is present', () => {
    const props = {
      finishedAt: '2021-04-26T13:37:52Z',
    };

    createComponent(props);

    expect(findJobFinishedTime().exists()).toBe(true);
    expect(findJobDuration().exists()).toBe(false);
  });

  it('displays icons for finished time and duration', () => {
    const props = {
      duration: 7,
      finishedAt: '2021-04-26T13:37:52Z',
    };

    createComponent(props);

    expect(findFinishedTimeIcon().props('name')).toBe('calendar');
    expect(findDurationIcon().props('name')).toBe('timer');
  });
});