summaryrefslogtreecommitdiff
path: root/spec/frontend/ci/runner/components/cells/runner_status_cell_spec.js
blob: 2fb824a8fa541804b1c9efcbbbb5e58f47138ee8 (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
import { mount } from '@vue/test-utils';
import RunnerStatusCell from '~/ci/runner/components/cells/runner_status_cell.vue';

import RunnerStatusBadge from '~/ci/runner/components/runner_status_badge.vue';
import RunnerPausedBadge from '~/ci/runner/components/runner_paused_badge.vue';
import {
  I18N_PAUSED,
  I18N_STATUS_ONLINE,
  I18N_STATUS_OFFLINE,
  INSTANCE_TYPE,
  STATUS_ONLINE,
  STATUS_OFFLINE,
} from '~/ci/runner/constants';

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

  const findStatusBadge = () => wrapper.findComponent(RunnerStatusBadge);
  const findPausedBadge = () => wrapper.findComponent(RunnerPausedBadge);

  const createComponent = ({ runner = {} } = {}) => {
    wrapper = mount(RunnerStatusCell, {
      propsData: {
        runner: {
          runnerType: INSTANCE_TYPE,
          active: true,
          status: STATUS_ONLINE,
          ...runner,
        },
      },
    });
  };

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

  it('Displays online status', () => {
    createComponent();

    expect(wrapper.text()).toContain(I18N_STATUS_ONLINE);
    expect(findStatusBadge().text()).toBe(I18N_STATUS_ONLINE);
  });

  it('Displays offline status', () => {
    createComponent({
      runner: {
        status: STATUS_OFFLINE,
      },
    });

    expect(wrapper.text()).toMatchInterpolatedText(I18N_STATUS_OFFLINE);
    expect(findStatusBadge().text()).toBe(I18N_STATUS_OFFLINE);
  });

  it('Displays paused status', () => {
    createComponent({
      runner: {
        active: false,
        status: STATUS_ONLINE,
      },
    });

    expect(wrapper.text()).toMatchInterpolatedText(`${I18N_STATUS_ONLINE} ${I18N_PAUSED}`);
    expect(findPausedBadge().text()).toBe(I18N_PAUSED);
  });

  it('Is empty when data is missing', () => {
    createComponent({
      runner: {
        status: null,
      },
    });

    expect(wrapper.text()).toBe('');
  });
});