2021-01-03 14:25:43 +05:30
|
|
|
import { getByText as getByTextHelper } from '@testing-library/dom';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount, createWrapper } from '@vue/test-utils';
|
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;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createComponent = (propsData) => {
|
2021-01-03 14:25:43 +05:30
|
|
|
wrapper = mount(MemberSource, {
|
|
|
|
propsData: {
|
|
|
|
memberSource: {
|
|
|
|
id: 102,
|
2021-03-08 18:12:59 +05:30
|
|
|
fullName: 'Foo bar',
|
2021-01-03 14:25:43 +05:30
|
|
|
webUrl: 'https://gitlab.com/groups/foo-bar',
|
|
|
|
},
|
|
|
|
...propsData,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: createMockDirective(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const getByText = (text, options) =>
|
|
|
|
createWrapper(getByTextHelper(wrapper.element, text, options));
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const getTooltipDirective = (elementWrapper) => getBinding(elementWrapper.element, 'gl-tooltip');
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('direct member', () => {
|
|
|
|
it('displays "Direct member"', () => {
|
|
|
|
createComponent({
|
|
|
|
isDirectMember: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(getByText('Direct member').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('inherited member', () => {
|
|
|
|
let sourceGroupLink;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
isDirectMember: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
sourceGroupLink = getByText('Foo bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays a link to source group', () => {
|
|
|
|
createComponent({
|
|
|
|
isDirectMember: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(sourceGroupLink.exists()).toBe(true);
|
|
|
|
expect(sourceGroupLink.attributes('href')).toBe('https://gitlab.com/groups/foo-bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays tooltip with "Inherited"', () => {
|
|
|
|
const tooltipDirective = getTooltipDirective(sourceGroupLink);
|
|
|
|
|
|
|
|
expect(tooltipDirective).not.toBeUndefined();
|
|
|
|
expect(sourceGroupLink.attributes('title')).toBe('Inherited');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|