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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
import { GlFormRadio } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import RunnerPlatformsRadio from '~/ci/runner/components/runner_platforms_radio.vue';
const mockImg = 'mock.svg';
const mockValue = 'value';
const mockValue2 = 'value2';
const mockSlot = '<div>a</div>';
describe('RunnerPlatformsRadio', () => {
let wrapper;
const findDiv = () => wrapper.find('div');
const findImg = () => wrapper.find('img');
const findFormRadio = () => wrapper.findComponent(GlFormRadio);
const createComponent = ({ props = {}, mountFn = shallowMountExtended, ...options } = {}) => {
wrapper = mountFn(RunnerPlatformsRadio, {
propsData: {
image: mockImg,
value: mockValue,
...props,
},
...options,
});
};
describe('when its selectable', () => {
beforeEach(() => {
createComponent({
props: { value: mockValue },
});
});
it('shows the item is clickable', () => {
expect(wrapper.classes('gl-cursor-pointer')).toBe(true);
});
it('shows radio option', () => {
expect(findFormRadio().attributes('value')).toBe(mockValue);
});
it('emits when item is clicked', () => {
findDiv().trigger('click');
expect(wrapper.emitted('input')).toEqual([[mockValue]]);
});
it.each(['input', 'change'])('emits radio "%s" event', (event) => {
findFormRadio().vm.$emit(event, mockValue2);
expect(wrapper.emitted(event)).toEqual([[mockValue2]]);
});
it('shows image', () => {
expect(findImg().attributes()).toMatchObject({
src: mockImg,
'aria-hidden': 'true',
});
});
it('shows slot', () => {
createComponent({
slots: {
default: mockSlot,
},
});
expect(wrapper.html()).toContain(mockSlot);
});
describe('with no image', () => {
beforeEach(() => {
createComponent({
props: { value: mockValue, image: null },
});
});
it('shows no image', () => {
expect(findImg().exists()).toBe(false);
});
});
});
describe('when its not selectable', () => {
beforeEach(() => {
createComponent({
props: { value: null },
});
});
it('shows the item is clickable', () => {
expect(wrapper.classes('gl-cursor-pointer')).toBe(false);
});
it('does not emit when item is clicked', () => {
findDiv().trigger('click');
expect(wrapper.emitted('input')).toBe(undefined);
});
it('does not show a radio option', () => {
expect(findFormRadio().exists()).toBe(false);
});
it('shows image', () => {
expect(findImg().attributes()).toMatchObject({
src: mockImg,
'aria-hidden': 'true',
});
});
it('shows slot', () => {
createComponent({
slots: {
default: mockSlot,
},
});
expect(wrapper.html()).toContain(mockSlot);
});
describe('with no image', () => {
beforeEach(() => {
createComponent({
props: { value: null, image: null },
});
});
it('shows no image', () => {
expect(findImg().exists()).toBe(false);
});
});
});
describe('when selected', () => {
beforeEach(() => {
createComponent({
props: { checked: mockValue },
});
});
it('highlights the item', () => {
expect(wrapper.classes('gl-bg-blue-50')).toBe(true);
expect(wrapper.classes('gl-border-blue-500')).toBe(true);
});
it('shows radio option as selected', () => {
expect(findFormRadio().attributes('value')).toBe(mockValue);
expect(findFormRadio().props('checked')).toBe(mockValue);
});
});
});
|