2021-10-27 15:23:28 +05:30
|
|
|
import { GlTabs, GlButton } from '@gitlab/ui';
|
2021-06-08 01:23:25 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
2021-10-27 15:23:28 +05:30
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
|
|
|
import MembersApp from '~/members/components/app.vue';
|
|
|
|
import MembersTabs from '~/members/components/members_tabs.vue';
|
2021-09-30 23:02:18 +05:30
|
|
|
import {
|
|
|
|
MEMBER_TYPES,
|
|
|
|
TAB_QUERY_PARAM_VALUES,
|
|
|
|
ACTIVE_TAB_QUERY_PARAM_NAME,
|
2022-07-23 23:45:48 +05:30
|
|
|
FILTERED_SEARCH_TOKEN_GROUPS_WITH_INHERITED_PERMISSIONS,
|
2021-09-30 23:02:18 +05:30
|
|
|
} from '~/members/constants';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { pagination } from '../mock_data';
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
describe('MembersTabs', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
Vue.use(Vuex);
|
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
const createComponent = ({ totalItems = 10, provide = {} } = {}) => {
|
2021-06-08 01:23:25 +05:30
|
|
|
const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
[MEMBER_TYPES.user]: {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
pagination: {
|
|
|
|
...pagination,
|
|
|
|
totalItems,
|
|
|
|
},
|
|
|
|
filteredSearchBar: {
|
|
|
|
searchParam: 'search',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[MEMBER_TYPES.group]: {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
pagination: {
|
|
|
|
...pagination,
|
|
|
|
totalItems,
|
|
|
|
paramName: 'groups_page',
|
|
|
|
},
|
|
|
|
filteredSearchBar: {
|
|
|
|
searchParam: 'search_groups',
|
2022-07-23 23:45:48 +05:30
|
|
|
tokens: [FILTERED_SEARCH_TOKEN_GROUPS_WITH_INHERITED_PERMISSIONS.type],
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[MEMBER_TYPES.invite]: {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
pagination: {
|
|
|
|
...pagination,
|
|
|
|
totalItems,
|
|
|
|
paramName: 'invited_page',
|
|
|
|
},
|
|
|
|
filteredSearchBar: {
|
|
|
|
searchParam: 'search_invited',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[MEMBER_TYPES.accessRequest]: {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
pagination: {
|
|
|
|
...pagination,
|
|
|
|
totalItems,
|
|
|
|
paramName: 'access_requests_page',
|
|
|
|
},
|
|
|
|
filteredSearchBar: {
|
|
|
|
searchParam: 'search_access_requests',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = mountExtended(MembersTabs, {
|
|
|
|
store,
|
|
|
|
stubs: ['members-app'],
|
|
|
|
provide: {
|
|
|
|
canManageMembers: true,
|
2021-10-27 15:23:28 +05:30
|
|
|
canExportMembers: true,
|
|
|
|
exportCsvPath: '',
|
|
|
|
...provide,
|
2021-06-08 01:23:25 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return nextTick();
|
|
|
|
};
|
|
|
|
|
|
|
|
const findTabs = () => wrapper.findAllByRole('tab').wrappers;
|
|
|
|
const findTabByText = (text) => findTabs().find((tab) => tab.text().includes(text));
|
|
|
|
const findActiveTab = () => wrapper.findByRole('tab', { selected: true });
|
2021-10-27 15:23:28 +05:30
|
|
|
const findExportButton = () => wrapper.findComponent(GlButton);
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-10-27 15:23:28 +05:30
|
|
|
setWindowLocation('https://localhost');
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('renders `GlTabs` with `syncActiveTabWithQueryParams` and `queryParamName` props set', async () => {
|
|
|
|
await createComponent();
|
|
|
|
|
|
|
|
const glTabsComponent = wrapper.findComponent(GlTabs);
|
|
|
|
|
|
|
|
expect(glTabsComponent.exists()).toBe(true);
|
|
|
|
expect(glTabsComponent.props()).toMatchObject({
|
|
|
|
syncActiveTabWithQueryParams: true,
|
|
|
|
queryParamName: ACTIVE_TAB_QUERY_PARAM_NAME,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
describe('when tabs have a count', () => {
|
|
|
|
it('renders tabs with count', async () => {
|
|
|
|
await createComponent();
|
|
|
|
|
|
|
|
const tabs = findTabs();
|
|
|
|
|
|
|
|
expect(tabs[0].text()).toBe('Members 10');
|
|
|
|
expect(tabs[1].text()).toBe('Groups 10');
|
|
|
|
expect(tabs[2].text()).toBe('Invited 10');
|
|
|
|
expect(tabs[3].text()).toBe('Access requests 10');
|
|
|
|
expect(findActiveTab().text()).toContain('Members');
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('renders `MembersApp` and passes `namespace` and `tabQueryParamValue` props', async () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
await createComponent();
|
|
|
|
|
|
|
|
const membersApps = wrapper.findAllComponents(MembersApp).wrappers;
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(membersApps[0].props('namespace')).toBe(MEMBER_TYPES.user);
|
|
|
|
expect(membersApps[1].props('namespace')).toBe(MEMBER_TYPES.group);
|
|
|
|
expect(membersApps[2].props('namespace')).toBe(MEMBER_TYPES.invite);
|
|
|
|
expect(membersApps[3].props('namespace')).toBe(MEMBER_TYPES.accessRequest);
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
expect(membersApps[1].props('tabQueryParamValue')).toBe(TAB_QUERY_PARAM_VALUES.group);
|
|
|
|
expect(membersApps[2].props('tabQueryParamValue')).toBe(TAB_QUERY_PARAM_VALUES.invite);
|
|
|
|
expect(membersApps[3].props('tabQueryParamValue')).toBe(TAB_QUERY_PARAM_VALUES.accessRequest);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when tabs do not have a count', () => {
|
|
|
|
it('only renders `Members` tab', async () => {
|
|
|
|
await createComponent({ totalItems: 0 });
|
|
|
|
|
|
|
|
expect(findTabByText('Members')).not.toBeUndefined();
|
|
|
|
expect(findTabByText('Groups')).toBeUndefined();
|
|
|
|
expect(findTabByText('Invited')).toBeUndefined();
|
|
|
|
expect(findTabByText('Access requests')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('when url param matches `filteredSearchBar.searchParam`', () => {
|
|
|
|
beforeEach(() => {
|
2021-10-27 15:23:28 +05:30
|
|
|
setWindowLocation('?search_groups=foo+bar');
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('shows tab that corresponds to search param', async () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
await createComponent({ totalItems: 0 });
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(findTabByText('Groups')).not.toBeUndefined();
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
});
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
describe('when url param matches `filteredSearchBar.tokens`', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setWindowLocation('?groups_with_inherited_permissions=exclude');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows tab that corresponds to filtered search token', async () => {
|
|
|
|
await createComponent({ totalItems: 0 });
|
|
|
|
|
|
|
|
expect(findTabByText('Groups')).not.toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when `canManageMembers` is `false`', () => {
|
|
|
|
it('shows all tabs except `Invited` and `Access requests`', async () => {
|
2021-10-27 15:23:28 +05:30
|
|
|
await createComponent({ provide: { canManageMembers: false } });
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
expect(findTabByText('Members')).not.toBeUndefined();
|
|
|
|
expect(findTabByText('Groups')).not.toBeUndefined();
|
|
|
|
expect(findTabByText('Invited')).toBeUndefined();
|
|
|
|
expect(findTabByText('Access requests')).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
describe('when `canExportMembers` is true', () => {
|
|
|
|
it('shows the CSV export button with export path', async () => {
|
|
|
|
await createComponent({ provide: { canExportMembers: true, exportCsvPath: 'foo' } });
|
|
|
|
|
|
|
|
expect(findExportButton().attributes('href')).toBe('foo');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when `canExportMembers` is false', () => {
|
|
|
|
it('does not show the CSV export button', async () => {
|
|
|
|
await createComponent({ provide: { canExportMembers: false } });
|
|
|
|
|
|
|
|
expect(findExportButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|