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
|
import { mount } from '@vue/test-utils';
import { GlTab, GlBadge } from '@gitlab/ui';
import IssuableTabs from '~/issuable_list/components/issuable_tabs.vue';
import { mockIssuableListProps } from '../mock_data';
const createComponent = ({
tabs = mockIssuableListProps.tabs,
tabCounts = mockIssuableListProps.tabCounts,
currentTab = mockIssuableListProps.currentTab,
} = {}) =>
mount(IssuableTabs, {
propsData: {
tabs,
tabCounts,
currentTab,
},
slots: {
'nav-actions': `
<button class="js-new-issuable">New issuable</button>
`,
},
});
describe('IssuableTabs', () => {
let wrapper;
beforeEach(() => {
wrapper = createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('methods', () => {
describe('isTabActive', () => {
it.each`
tabName | currentTab | returnValue
${'opened'} | ${'opened'} | ${true}
${'opened'} | ${'closed'} | ${false}
`(
'returns $returnValue when tab name is "$tabName" is current tab is "$currentTab"',
async ({ tabName, currentTab, returnValue }) => {
wrapper.setProps({
currentTab,
});
await wrapper.vm.$nextTick();
expect(wrapper.vm.isTabActive(tabName)).toBe(returnValue);
},
);
});
});
describe('template', () => {
it('renders gl-tab for each tab within `tabs` array', () => {
const tabsEl = wrapper.findAll(GlTab);
expect(tabsEl.exists()).toBe(true);
expect(tabsEl).toHaveLength(mockIssuableListProps.tabs.length);
});
it('renders gl-badge component within a tab', () => {
const badgeEl = wrapper.findAll(GlBadge).at(0);
expect(badgeEl.exists()).toBe(true);
expect(badgeEl.text()).toBe(`${mockIssuableListProps.tabCounts.opened}`);
});
it('renders contents for slot "nav-actions"', () => {
const buttonEl = wrapper.find('button.js-new-issuable');
expect(buttonEl.exists()).toBe(true);
expect(buttonEl.text()).toBe('New issuable');
});
});
describe('events', () => {
it('gl-tab component emits `click` event on `click` event', () => {
const tabEl = wrapper.findAll(GlTab).at(0);
tabEl.vm.$emit('click', 'opened');
expect(wrapper.emitted('click')).toBeTruthy();
expect(wrapper.emitted('click')[0]).toEqual(['opened']);
});
});
});
|