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
|
import { GlButton, GlCollapse, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import MrCollapsibleSection from '~/vue_merge_request_widget/components/mr_widget_expandable_section.vue';
describe('MrWidgetExpanableSection', () => {
let wrapper;
const findButton = () => wrapper.find(GlButton);
const findCollapse = () => wrapper.find(GlCollapse);
beforeEach(() => {
wrapper = shallowMount(MrCollapsibleSection, {
slots: {
content: '<span>Collapsable Content</span>',
header: '<span>Header Content</span>',
},
});
});
it('renders Icon', () => {
expect(wrapper.find(GlIcon).exists()).toBe(true);
});
it('renders header slot', () => {
expect(wrapper.text()).toContain('Header Content');
});
it('renders content slot', () => {
expect(wrapper.text()).toContain('Collapsable Content');
});
describe('when collapse section is closed', () => {
it('renders button with expand text', () => {
expect(findButton().text()).toBe('Expand');
});
it('renders a collpased section with no visibility', () => {
const collapse = findCollapse();
expect(collapse.exists()).toBe(true);
expect(collapse.attributes('visible')).toBeUndefined();
});
});
describe('when collapse section is open', () => {
beforeEach(async () => {
findButton().vm.$emit('click');
await nextTick();
});
it('renders button with collapse text', () => {
const button = findButton();
expect(button.exists()).toBe(true);
expect(button.text()).toBe('Collapse');
});
it('renders a collpased section with visible content', () => {
const collapse = findCollapse();
expect(collapse.exists()).toBe(true);
expect(collapse.attributes('visible')).toBe('true');
});
});
});
|