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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
import { shallowMount } from '@vue/test-utils';
import { GlLink } from '@gitlab/ui';
import { s__ } from '~/locale';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import RunnerOwnerCell from '~/ci/runner/components/cells/runner_owner_cell.vue';
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '~/ci/runner/constants';
describe('RunnerOwnerCell', () => {
let wrapper;
const findLink = () => wrapper.findComponent(GlLink);
const getLinkTooltip = () => getBinding(findLink().element, 'gl-tooltip').value;
const createComponent = ({ runner } = {}) => {
wrapper = shallowMount(RunnerOwnerCell, {
directives: {
GlTooltip: createMockDirective('gl-tooltip'),
},
propsData: {
runner,
},
});
};
afterEach(() => {
wrapper.destroy();
});
describe('When its an instance runner', () => {
beforeEach(() => {
createComponent({
runner: {
runnerType: INSTANCE_TYPE,
},
});
});
it('shows an administrator label', () => {
expect(findLink().exists()).toBe(false);
expect(wrapper.text()).toBe(s__('Runners|Administrator'));
});
});
describe('When its a group runner', () => {
const mockName = 'Group 2';
const mockFullName = 'Group 1 / Group 2';
const mockWebUrl = '/group-1/group-2';
beforeEach(() => {
createComponent({
runner: {
runnerType: GROUP_TYPE,
groups: {
nodes: [
{
name: mockName,
fullName: mockFullName,
webUrl: mockWebUrl,
},
],
},
},
});
});
it('Displays a group link', () => {
expect(findLink().attributes('href')).toBe(mockWebUrl);
expect(wrapper.text()).toBe(mockName);
expect(getLinkTooltip()).toBe(mockFullName);
});
});
describe('When its a project runner', () => {
const mockName = 'Project 1';
const mockNameWithNamespace = 'Group 1 / Project 1';
const mockWebUrl = '/group-1/project-1';
beforeEach(() => {
createComponent({
runner: {
runnerType: PROJECT_TYPE,
ownerProject: {
name: mockName,
nameWithNamespace: mockNameWithNamespace,
webUrl: mockWebUrl,
},
},
});
});
it('Displays a project link', () => {
expect(findLink().attributes('href')).toBe(mockWebUrl);
expect(wrapper.text()).toBe(mockName);
expect(getLinkTooltip()).toBe(mockNameWithNamespace);
});
});
describe('When its an empty runner', () => {
beforeEach(() => {
createComponent({
runner: {},
});
});
it('shows no label', () => {
expect(wrapper.text()).toBe('');
});
});
});
|