summaryrefslogtreecommitdiff
path: root/spec/frontend/runner/components/stat/runner_status_stat_spec.js
blob: 3218272eac7bed5322dee00161572fe79657c485 (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
import { GlSingleStat } from '@gitlab/ui/dist/charts';
import { shallowMount, mount } from '@vue/test-utils';
import RunnerStatusStat from '~/runner/components/stat/runner_status_stat.vue';
import { STATUS_ONLINE, STATUS_OFFLINE, STATUS_STALE } from '~/runner/constants';

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

  const findSingleStat = () => wrapper.findComponent(GlSingleStat);

  const createComponent = ({ props = {} } = {}, mountFn = shallowMount) => {
    wrapper = mountFn(RunnerStatusStat, {
      propsData: {
        status: STATUS_ONLINE,
        value: 99,
        ...props,
      },
    });
  };

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

  describe.each`
    status            | variant      | title                | badge
    ${STATUS_ONLINE}  | ${'success'} | ${'Online runners'}  | ${'online'}
    ${STATUS_OFFLINE} | ${'muted'}   | ${'Offline runners'} | ${'offline'}
    ${STATUS_STALE}   | ${'warning'} | ${'Stale runners'}   | ${'stale'}
  `('Renders a stat for status "$status"', ({ status, variant, title, badge }) => {
    beforeEach(() => {
      createComponent({ props: { status } }, mount);
    });

    it('Renders text', () => {
      expect(wrapper.text()).toMatch(new RegExp(`${title} 99\\s+${badge}`));
    });

    it(`Uses variant ${variant}`, () => {
      expect(findSingleStat().props('variant')).toBe(variant);
    });
  });

  it('Formats stat number', () => {
    createComponent({ props: { value: 1000 } }, mount);

    expect(wrapper.text()).toMatch('Online runners 1,000');
  });

  it('Shows a null result', () => {
    createComponent({ props: { value: null } }, mount);

    expect(wrapper.text()).toMatch('Online runners -');
  });

  it('Shows an undefined result', () => {
    createComponent({ props: { value: undefined } }, mount);

    expect(wrapper.text()).toMatch('Online runners -');
  });

  it('Shows result for an unknown status', () => {
    createComponent({ props: { status: 'UNKNOWN' } }, mount);

    expect(wrapper.text()).toMatch('Runners 99');
  });
});