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
|
import { mount } from '@vue/test-utils';
import Button from '~/ide/components/new_dropdown/button.vue';
describe('IDE new entry dropdown button component', () => {
let wrapper;
const createComponent = (props = {}) => {
wrapper = mount(Button, {
propsData: {
label: 'Testing',
icon: 'doc-new',
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
});
it('renders button with label', () => {
createComponent();
expect(wrapper.text()).toContain('Testing');
});
it('renders icon', () => {
createComponent();
expect(wrapper.find('[data-testid="doc-new-icon"]').exists()).toBe(true);
});
it('emits click event', async () => {
createComponent();
await wrapper.trigger('click');
expect(wrapper.emitted('click')).toHaveLength(1);
});
it('hides label if showLabel is false', () => {
createComponent({ showLabel: false });
expect(wrapper.text()).not.toContain('Testing');
});
describe('tooltip title', () => {
it('returns empty string when showLabel is true', () => {
createComponent({ showLabel: true });
expect(wrapper.attributes('title')).toBe('');
});
it('returns label', () => {
createComponent({ showLabel: false });
expect(wrapper.attributes('title')).toBe('Testing');
});
});
});
|