Welcome to mirror list, hosted at ThFree Co, Russian Federation.

runner_stats_spec.js « stat « components « runner « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f1ba6403dfb9e5cd3d9593f1d60bff3e792b9650 (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
82
83
import { shallowMount, mount } from '@vue/test-utils';
import { s__ } from '~/locale';
import RunnerStats from '~/runner/components/stat/runner_stats.vue';
import RunnerCount from '~/runner/components/stat/runner_count.vue';
import RunnerStatusStat from '~/runner/components/stat/runner_status_stat.vue';
import { INSTANCE_TYPE, STATUS_ONLINE, STATUS_OFFLINE, STATUS_STALE } from '~/runner/constants';

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

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

  const createComponent = ({ props = {}, mountFn = shallowMount, ...options } = {}) => {
    wrapper = mountFn(RunnerStats, {
      propsData: {
        scope: INSTANCE_TYPE,
        variables: {},
        ...props,
      },
      ...options,
    });
  };

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

  it('Displays all the stats', () => {
    const mockCounts = {
      [STATUS_ONLINE]: 3,
      [STATUS_OFFLINE]: 2,
      [STATUS_STALE]: 1,
    };

    createComponent({
      mountFn: mount,
      stubs: {
        RunnerCount: {
          props: ['variables'],
          render() {
            return this.$scopedSlots.default({
              count: mockCounts[this.variables.status],
            });
          },
        },
      },
    });

    const text = wrapper.text();
    expect(text).toMatch(`${s__('Runners|Online runners')} 3`);
    expect(text).toMatch(`${s__('Runners|Offline runners')} 2`);
    expect(text).toMatch(`${s__('Runners|Stale runners')} 1`);
  });

  it('Displays counts for filtered searches', () => {
    createComponent({ props: { variables: { paused: true } } });

    expect(findRunnerCountAt(0).props('variables').paused).toBe(true);
    expect(findRunnerCountAt(1).props('variables').paused).toBe(true);
    expect(findRunnerCountAt(2).props('variables').paused).toBe(true);
  });

  it('Skips overlapping statuses', () => {
    createComponent({ props: { variables: { status: STATUS_ONLINE } } });

    expect(findRunnerCountAt(0).props('skip')).toBe(false);
    expect(findRunnerCountAt(1).props('skip')).toBe(true);
    expect(findRunnerCountAt(2).props('skip')).toBe(true);
  });

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

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