2020-11-24 15:15:51 +05:30
|
|
|
import { GlDropdown, GlLink } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-11-24 15:15:51 +05:30
|
|
|
import OverrideDropdown from '~/integrations/edit/components/override_dropdown.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { integrationLevels, overrideDropdownDescriptions } from '~/integrations/edit/constants';
|
|
|
|
import { createStore } from '~/integrations/edit/store';
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
describe('OverrideDropdown', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
inheritFromId: 1,
|
|
|
|
override: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultDefaultStateProps = {
|
|
|
|
integrationLevel: 'group',
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = (props = {}, defaultStateProps = {}) => {
|
|
|
|
wrapper = shallowMount(OverrideDropdown, {
|
|
|
|
propsData: { ...defaultProps, ...props },
|
|
|
|
store: createStore({
|
|
|
|
defaultState: { ...defaultDefaultStateProps, ...defaultStateProps },
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const findGlLink = () => wrapper.find(GlLink);
|
|
|
|
const findGlDropdown = () => wrapper.find(GlDropdown);
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
describe('override prop is true', () => {
|
|
|
|
it('renders GlToggle as disabled', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findGlDropdown().props('text')).toBe('Use custom settings');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('override prop is false', () => {
|
|
|
|
it('renders GlToggle as disabled', () => {
|
|
|
|
createComponent({ override: false });
|
|
|
|
|
|
|
|
expect(findGlDropdown().props('text')).toBe('Use default settings');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('integrationLevel is "project"', () => {
|
|
|
|
it('renders copy mentioning instance (as default fallback)', () => {
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
integrationLevel: 'project',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(overrideDropdownDescriptions[integrationLevels.INSTANCE]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('integrationLevel is "group"', () => {
|
|
|
|
it('renders copy mentioning group', () => {
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
integrationLevel: 'group',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(overrideDropdownDescriptions[integrationLevels.GROUP]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('integrationLevel is "instance"', () => {
|
|
|
|
it('renders copy mentioning instance', () => {
|
|
|
|
createComponent(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
integrationLevel: 'instance',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(overrideDropdownDescriptions[integrationLevels.INSTANCE]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('learnMorePath is present', () => {
|
|
|
|
it('renders GlLink with correct link', () => {
|
|
|
|
createComponent({
|
|
|
|
learnMorePath: '/docs',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findGlLink().text()).toBe('Learn more');
|
|
|
|
expect(findGlLink().attributes('href')).toBe('/docs');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|