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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
import { GlTab } from '@gitlab/ui';
import { nextTick } from 'vue';
import AxiosMockAdapter from 'axios-mock-adapter';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import OverviewTabs from '~/groups/components/overview_tabs.vue';
import GroupsApp from '~/groups/components/app.vue';
import GroupsStore from '~/groups/store/groups_store';
import GroupsService from '~/groups/service/groups_service';
import { createRouter } from '~/groups/init_overview_tabs';
import {
ACTIVE_TAB_SUBGROUPS_AND_PROJECTS,
ACTIVE_TAB_SHARED,
ACTIVE_TAB_ARCHIVED,
} from '~/groups/constants';
import axios from '~/lib/utils/axios_utils';
const router = createRouter();
describe('OverviewTabs', () => {
let wrapper;
const endpoints = {
subgroups_and_projects: '/groups/foobar/-/children.json',
shared: '/groups/foobar/-/shared_projects.json',
archived: '/groups/foobar/-/children.json?archived=only',
};
const routerMock = {
push: jest.fn(),
};
const createComponent = async ({
route = { name: ACTIVE_TAB_SUBGROUPS_AND_PROJECTS, params: { group: 'foo/bar/baz' } },
} = {}) => {
wrapper = mountExtended(OverviewTabs, {
router,
provide: {
endpoints,
},
mocks: { $route: route, $router: routerMock },
});
await nextTick();
};
const findTabPanels = () => wrapper.findAllComponents(GlTab);
const findTab = (name) => wrapper.findByRole('tab', { name });
const findSelectedTab = () => wrapper.findByRole('tab', { selected: true });
afterEach(() => {
wrapper.destroy();
});
beforeEach(async () => {
// eslint-disable-next-line no-new
new AxiosMockAdapter(axios);
});
it('renders `Subgroups and projects` tab with `GroupsApp` component', async () => {
await createComponent();
const tabPanel = findTabPanels().at(0);
expect(tabPanel.vm.$attrs).toMatchObject({
title: OverviewTabs.i18n[ACTIVE_TAB_SUBGROUPS_AND_PROJECTS],
lazy: false,
});
expect(tabPanel.findComponent(GroupsApp).props()).toMatchObject({
action: ACTIVE_TAB_SUBGROUPS_AND_PROJECTS,
store: new GroupsStore({ showSchemaMarkup: true }),
service: new GroupsService(endpoints[ACTIVE_TAB_SUBGROUPS_AND_PROJECTS]),
hideProjects: false,
renderEmptyState: true,
});
});
it('renders `Shared projects` tab and renders `GroupsApp` component after clicking tab', async () => {
await createComponent();
const tabPanel = findTabPanels().at(1);
expect(tabPanel.vm.$attrs).toMatchObject({
title: OverviewTabs.i18n[ACTIVE_TAB_SHARED],
lazy: true,
});
await findTab(OverviewTabs.i18n[ACTIVE_TAB_SHARED]).trigger('click');
expect(tabPanel.findComponent(GroupsApp).props()).toMatchObject({
action: ACTIVE_TAB_SHARED,
store: new GroupsStore(),
service: new GroupsService(endpoints[ACTIVE_TAB_SHARED]),
hideProjects: false,
renderEmptyState: false,
});
expect(tabPanel.vm.$attrs.lazy).toBe(false);
});
it('renders `Archived projects` tab and renders `GroupsApp` component after clicking tab', async () => {
await createComponent();
const tabPanel = findTabPanels().at(2);
expect(tabPanel.vm.$attrs).toMatchObject({
title: OverviewTabs.i18n[ACTIVE_TAB_ARCHIVED],
lazy: true,
});
await findTab(OverviewTabs.i18n[ACTIVE_TAB_ARCHIVED]).trigger('click');
expect(tabPanel.findComponent(GroupsApp).props()).toMatchObject({
action: ACTIVE_TAB_ARCHIVED,
store: new GroupsStore(),
service: new GroupsService(endpoints[ACTIVE_TAB_ARCHIVED]),
hideProjects: false,
renderEmptyState: false,
});
expect(tabPanel.vm.$attrs.lazy).toBe(false);
});
describe.each([
[
{ name: ACTIVE_TAB_SUBGROUPS_AND_PROJECTS, params: { group: 'foo/bar/baz' } },
OverviewTabs.i18n[ACTIVE_TAB_SHARED],
{
name: ACTIVE_TAB_SHARED,
params: { group: ['foo', 'bar', 'baz'] },
},
],
[
{ name: ACTIVE_TAB_SUBGROUPS_AND_PROJECTS, params: { group: ['foo', 'bar', 'baz'] } },
OverviewTabs.i18n[ACTIVE_TAB_SHARED],
{
name: ACTIVE_TAB_SHARED,
params: { group: ['foo', 'bar', 'baz'] },
},
],
[
{ name: ACTIVE_TAB_SUBGROUPS_AND_PROJECTS, params: { group: 'foo' } },
OverviewTabs.i18n[ACTIVE_TAB_SHARED],
{
name: ACTIVE_TAB_SHARED,
params: { group: ['foo'] },
},
],
[
{ name: ACTIVE_TAB_SHARED, params: { group: 'foo/bar' } },
OverviewTabs.i18n[ACTIVE_TAB_ARCHIVED],
{
name: ACTIVE_TAB_ARCHIVED,
params: { group: ['foo', 'bar'] },
},
],
[
{ name: ACTIVE_TAB_SHARED, params: { group: 'foo/bar' } },
OverviewTabs.i18n[ACTIVE_TAB_SUBGROUPS_AND_PROJECTS],
{
name: ACTIVE_TAB_SUBGROUPS_AND_PROJECTS,
params: { group: ['foo', 'bar'] },
},
],
[
{ name: ACTIVE_TAB_ARCHIVED, params: { group: ['foo'] } },
OverviewTabs.i18n[ACTIVE_TAB_SHARED],
{
name: ACTIVE_TAB_SHARED,
params: { group: ['foo'] },
},
],
])('when current route is %j', (currentRoute, tabToClick, expectedRoute) => {
beforeEach(async () => {
await createComponent({ route: currentRoute });
});
it(`sets ${OverviewTabs.i18n[currentRoute.name]} as active tab`, () => {
expect(findSelectedTab().text()).toBe(OverviewTabs.i18n[currentRoute.name]);
});
it(`pushes expected route when ${tabToClick} tab is clicked`, async () => {
await findTab(tabToClick).trigger('click');
expect(routerMock.push).toHaveBeenCalledWith(expectedRoute);
});
});
});
|