debian-mirror-gitlab/spec/frontend/ci/runner/components/runner_header_spec.js

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

121 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-03-02 08:16:31 +05:30
import { GlSprintf } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
2023-01-13 00:05:48 +05:30
import {
I18N_STATUS_ONLINE,
I18N_GROUP_TYPE,
GROUP_TYPE,
STATUS_ONLINE,
} from '~/ci/runner/constants';
2023-04-23 21:23:45 +05:30
import { TYPENAME_CI_RUNNER } from '~/graphql_shared/constants';
2022-03-02 08:16:31 +05:30
import { convertToGraphQLId } from '~/graphql_shared/utils';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
2023-01-13 00:05:48 +05:30
import RunnerHeader from '~/ci/runner/components/runner_header.vue';
import RunnerTypeBadge from '~/ci/runner/components/runner_type_badge.vue';
import RunnerStatusBadge from '~/ci/runner/components/runner_status_badge.vue';
2022-03-02 08:16:31 +05:30
import { runnerData } from '../mock_data';
const mockRunner = runnerData.data.runner;
describe('RunnerHeader', () => {
let wrapper;
const findRunnerTypeBadge = () => wrapper.findComponent(RunnerTypeBadge);
const findRunnerStatusBadge = () => wrapper.findComponent(RunnerStatusBadge);
2022-04-04 11:22:00 +05:30
const findRunnerLockedIcon = () => wrapper.findByTestId('lock-icon');
2022-03-02 08:16:31 +05:30
const findTimeAgo = () => wrapper.findComponent(TimeAgo);
2022-04-04 11:22:00 +05:30
const createComponent = ({ runner = {}, options = {}, mountFn = shallowMountExtended } = {}) => {
2022-03-02 08:16:31 +05:30
wrapper = mountFn(RunnerHeader, {
propsData: {
runner: {
...mockRunner,
...runner,
},
},
stubs: {
GlSprintf,
TimeAgo,
},
2022-04-04 11:22:00 +05:30
...options,
2022-03-02 08:16:31 +05:30
});
};
it('displays the runner status', () => {
createComponent({
2022-04-04 11:22:00 +05:30
mountFn: mountExtended,
2022-03-02 08:16:31 +05:30
runner: {
status: STATUS_ONLINE,
},
});
2022-10-11 01:57:18 +05:30
expect(findRunnerStatusBadge().text()).toContain(I18N_STATUS_ONLINE);
2022-03-02 08:16:31 +05:30
});
it('displays the runner type', () => {
createComponent({
2022-04-04 11:22:00 +05:30
mountFn: mountExtended,
2022-03-02 08:16:31 +05:30
runner: {
runnerType: GROUP_TYPE,
},
});
2022-10-11 01:57:18 +05:30
expect(findRunnerTypeBadge().text()).toContain(I18N_GROUP_TYPE);
2022-03-02 08:16:31 +05:30
});
it('displays the runner id', () => {
createComponent({
runner: {
2023-04-23 21:23:45 +05:30
id: convertToGraphQLId(TYPENAME_CI_RUNNER, 99),
2022-03-02 08:16:31 +05:30
},
});
2022-04-04 11:22:00 +05:30
expect(wrapper.text()).toContain('Runner #99');
});
it('displays the runner locked icon', () => {
createComponent({
runner: {
locked: true,
},
mountFn: mountExtended,
});
expect(findRunnerLockedIcon().exists()).toBe(true);
2022-03-02 08:16:31 +05:30
});
it('displays the runner creation time', () => {
createComponent();
expect(wrapper.text()).toMatch(/created .+/);
expect(findTimeAgo().props('time')).toBe(mockRunner.createdAt);
});
2022-04-04 11:22:00 +05:30
it('does not display runner creation time if "createdAt" is missing', () => {
2022-03-02 08:16:31 +05:30
createComponent({
runner: {
2023-04-23 21:23:45 +05:30
id: convertToGraphQLId(TYPENAME_CI_RUNNER, 99),
2022-03-02 08:16:31 +05:30
createdAt: null,
},
});
2022-04-04 11:22:00 +05:30
expect(wrapper.text()).toContain('Runner #99');
2022-03-02 08:16:31 +05:30
expect(wrapper.text()).not.toMatch(/created .+/);
expect(findTimeAgo().exists()).toBe(false);
});
2022-04-04 11:22:00 +05:30
it('displays actions in a slot', () => {
createComponent({
options: {
slots: {
actions: '<div data-testid="actions-content">My Actions</div>',
},
mountFn: mountExtended,
},
});
expect(wrapper.findByTestId('actions-content').text()).toBe('My Actions');
});
2022-03-02 08:16:31 +05:30
});