2023-03-17 16:20:25 +05:30
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
2021-02-22 17:27:13 +05:30
|
|
|
import MemberSource from '~/members/components/table/member_source.vue';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe('MemberSource', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
const memberSource = {
|
|
|
|
id: 102,
|
|
|
|
fullName: 'Foo bar',
|
|
|
|
webUrl: 'https://gitlab.com/groups/foo-bar',
|
|
|
|
};
|
|
|
|
|
|
|
|
const createdBy = {
|
|
|
|
name: 'Administrator',
|
|
|
|
webUrl: 'https://gitlab.com/root',
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createComponent = (propsData) => {
|
2023-03-17 16:20:25 +05:30
|
|
|
wrapper = mountExtended(MemberSource, {
|
2021-01-03 14:25:43 +05:30
|
|
|
propsData: {
|
2023-03-17 16:20:25 +05:30
|
|
|
memberSource,
|
2021-01-03 14:25:43 +05:30
|
|
|
...propsData,
|
|
|
|
},
|
|
|
|
directives: {
|
2023-05-27 22:25:52 +05:30
|
|
|
GlTooltip: createMockDirective('gl-tooltip'),
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const getTooltipDirective = (elementWrapper) => getBinding(elementWrapper.element, 'gl-tooltip');
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe('direct member', () => {
|
2023-03-17 16:20:25 +05:30
|
|
|
describe('when created by is available', () => {
|
|
|
|
it('displays "Direct member by <user name>"', () => {
|
|
|
|
createComponent({
|
|
|
|
isDirectMember: true,
|
|
|
|
createdBy,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe('Direct member by Administrator');
|
|
|
|
expect(wrapper.findByRole('link', { name: createdBy.name }).attributes('href')).toBe(
|
|
|
|
createdBy.webUrl,
|
|
|
|
);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
2023-03-17 16:20:25 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
describe('when created by is not available', () => {
|
|
|
|
it('displays "Direct member"', () => {
|
|
|
|
createComponent({
|
|
|
|
isDirectMember: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe('Direct member');
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('inherited member', () => {
|
2023-03-17 16:20:25 +05:30
|
|
|
describe('when created by is available', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
isDirectMember: false,
|
|
|
|
createdBy,
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
it('displays "<group name> by <user name>"', () => {
|
|
|
|
expect(wrapper.text()).toBe('Foo bar by Administrator');
|
|
|
|
expect(wrapper.findByRole('link', { name: memberSource.fullName }).attributes('href')).toBe(
|
|
|
|
memberSource.webUrl,
|
|
|
|
);
|
|
|
|
expect(wrapper.findByRole('link', { name: createdBy.name }).attributes('href')).toBe(
|
|
|
|
createdBy.webUrl,
|
|
|
|
);
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
describe('when created by is not available', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
isDirectMember: false,
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
it('displays a link to source group', () => {
|
|
|
|
expect(wrapper.text()).toBe(memberSource.fullName);
|
|
|
|
expect(wrapper.attributes('href')).toBe(memberSource.webUrl);
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
it('displays tooltip with "Inherited"', () => {
|
|
|
|
const tooltipDirective = getTooltipDirective(wrapper);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
expect(tooltipDirective).not.toBeUndefined();
|
|
|
|
expect(tooltipDirective.value).toBe('Inherited');
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|