debian-mirror-gitlab/spec/frontend/runner/components/stat/runner_stats_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-03-02 08:16:31 +05:30
import { shallowMount, mount } from '@vue/test-utils';
2022-08-13 15:12:31 +05:30
import { s__ } from '~/locale';
2022-03-02 08:16:31 +05:30
import RunnerStats from '~/runner/components/stat/runner_stats.vue';
2022-08-27 11:52:29 +05:30
import RunnerSingleStat from '~/runner/components/stat/runner_single_stat.vue';
2022-08-13 15:12:31 +05:30
import { INSTANCE_TYPE, STATUS_ONLINE, STATUS_OFFLINE, STATUS_STALE } from '~/runner/constants';
2022-03-02 08:16:31 +05:30
describe('RunnerStats', () => {
let wrapper;
2022-08-27 11:52:29 +05:30
const findSingleStats = () => wrapper.findAllComponents(RunnerSingleStat).wrappers;
2022-03-02 08:16:31 +05:30
2022-08-13 15:12:31 +05:30
const createComponent = ({ props = {}, mountFn = shallowMount, ...options } = {}) => {
2022-03-02 08:16:31 +05:30
wrapper = mountFn(RunnerStats, {
propsData: {
2022-08-13 15:12:31 +05:30
scope: INSTANCE_TYPE,
variables: {},
2022-03-02 08:16:31 +05:30
...props,
},
2022-08-13 15:12:31 +05:30
...options,
2022-03-02 08:16:31 +05:30
});
};
afterEach(() => {
wrapper.destroy();
});
it('Displays all the stats', () => {
2022-08-13 15:12:31 +05:30
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`);
});
2022-03-02 08:16:31 +05:30
2022-08-27 11:52:29 +05:30
it('Displays all counts for filtered searches', () => {
const mockVariables = { paused: true };
createComponent({ props: { variables: mockVariables } });
2022-03-02 08:16:31 +05:30
2022-08-27 11:52:29 +05:30
findSingleStats().forEach((stat) => {
expect(stat.props('variables')).toMatchObject(mockVariables);
});
2022-03-02 08:16:31 +05:30
});
});