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

runner_job_count_spec.js « components « runner « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01b5ca5332ee4ff3547b378740d51bb04b95ff5d (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
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import runnerJobCountQuery from '~/ci/runner/graphql/list/runner_job_count.query.graphql';

import RunnerJobCount from '~/ci/runner/components/runner_job_count.vue';

import { runnerJobCountData } from '../mock_data';

const mockRunner = runnerJobCountData.data.runner;

Vue.use(VueApollo);

describe('RunnerJobCount', () => {
  let wrapper;
  let runnerJobCountHandler;

  const createComponent = ({ props = {}, ...options } = {}, mountFn = shallowMountExtended) => {
    wrapper = mountFn(RunnerJobCount, {
      apolloProvider: createMockApollo([[runnerJobCountQuery, runnerJobCountHandler]]),
      propsData: {
        runner: mockRunner,
        ...props,
      },
      ...options,
    });
  };

  beforeEach(() => {
    runnerJobCountHandler = jest.fn().mockReturnValue(new Promise(() => {}));
  });

  it('Loads data while it displays empty content', () => {
    createComponent();

    expect(runnerJobCountHandler).toHaveBeenCalledWith({ id: mockRunner.id });
    expect(wrapper.text()).toBe('-');
  });

  it('Sets a batch key for the "jobCount" query', () => {
    createComponent();

    expect(wrapper.vm.$apollo.queries.jobCount.options.context.batchKey).toBe('RunnerJobCount');
  });

  it('Displays job count', async () => {
    runnerJobCountHandler.mockResolvedValue(runnerJobCountData);

    createComponent();

    await waitForPromises();

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

  it('Displays formatted job count', async () => {
    runnerJobCountHandler.mockResolvedValue({
      data: {
        runner: {
          ...mockRunner,
          jobCount: 1001,
        },
      },
    });

    createComponent();

    await waitForPromises();

    expect(wrapper.text()).toBe('1,000+');
  });
});