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
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ItemsList from '~/super_sidebar/components/items_list.vue';
import NavItem from '~/super_sidebar/components/nav_item.vue';
import { cachedFrequentProjects } from '../mock_data';
const mockItems = JSON.parse(cachedFrequentProjects);
const [firstMockedProject] = mockItems;
describe('ItemsList component', () => {
let wrapper;
const findNavItems = () => wrapper.findAllComponents(NavItem);
const createWrapper = ({ props = {}, slots = {} } = {}) => {
wrapper = shallowMountExtended(ItemsList, {
propsData: {
...props,
},
slots,
});
};
it('does not render nav items when there are no items', () => {
createWrapper();
expect(findNavItems().length).toBe(0);
});
it('renders one nav item per item', () => {
createWrapper({
props: {
items: mockItems,
},
});
expect(findNavItems().length).not.toBe(0);
expect(findNavItems().length).toBe(mockItems.length);
});
it('passes the correct props to the nav items', () => {
createWrapper({
props: {
items: mockItems,
},
});
const firstNavItem = findNavItems().at(0);
expect(firstNavItem.props('item')).toEqual(firstMockedProject);
});
it('renders the `view-all-items` slot', () => {
const testId = 'view-all-items';
createWrapper({
slots: {
'view-all-items': {
template: `<div data-testid="${testId}" />`,
},
},
});
expect(wrapper.findByTestId(testId).exists()).toBe(true);
});
});
|