summaryrefslogtreecommitdiff
path: root/spec/frontend/runner/components/cells/runner_status_cell_spec.js
blob: 20a1cdf7236e3a8d1d2f206ef66f0e452e0da91e (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
import { GlBadge } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import RunnerStatusCell from '~/runner/components/cells/runner_status_cell.vue';
import { INSTANCE_TYPE, STATUS_ONLINE, STATUS_OFFLINE } from '~/runner/constants';

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

  const findBadgeAt = (i) => wrapper.findAllComponents(GlBadge).at(i);

  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()).toMatchInterpolatedText('online');
    expect(findBadgeAt(0).text()).toBe('online');
  });

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

    expect(wrapper.text()).toMatchInterpolatedText('offline');
    expect(findBadgeAt(0).text()).toBe('offline');
  });

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

    expect(wrapper.text()).toMatchInterpolatedText('online paused');

    expect(findBadgeAt(0).text()).toBe('online');
    expect(findBadgeAt(1).text()).toBe('paused');
  });

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

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