summaryrefslogtreecommitdiff
path: root/spec/frontend/runner/components/stat/runner_stats_spec.js
blob: 68db8621ef0b5f70e37f214f660416be24f86a3d (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
import { shallowMount, mount } from '@vue/test-utils';
import RunnerStats from '~/runner/components/stat/runner_stats.vue';
import RunnerStatusStat from '~/runner/components/stat/runner_status_stat.vue';
import { STATUS_ONLINE, STATUS_OFFLINE, STATUS_STALE } from '~/runner/constants';

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

  const findRunnerStatusStatAt = (i) => wrapper.findAllComponents(RunnerStatusStat).at(i);

  const createComponent = ({ props = {}, mountFn = shallowMount } = {}) => {
    wrapper = mountFn(RunnerStats, {
      propsData: {
        onlineRunnersCount: 3,
        offlineRunnersCount: 2,
        staleRunnersCount: 1,
        ...props,
      },
    });
  };

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

  it('Displays all the stats', () => {
    createComponent({ mountFn: mount });

    const stats = wrapper.text();

    expect(stats).toMatch('Online runners 3');
    expect(stats).toMatch('Offline runners 2');
    expect(stats).toMatch('Stale runners 1');
  });

  it.each`
    i    | status
    ${0} | ${STATUS_ONLINE}
    ${1} | ${STATUS_OFFLINE}
    ${2} | ${STATUS_STALE}
  `('Displays status types at index $i', ({ i, status }) => {
    createComponent();

    expect(findRunnerStatusStatAt(i).props('status')).toBe(status);
  });
});