debian-mirror-gitlab/spec/frontend/integrations/edit/components/override_dropdown_spec.js

104 lines
2.8 KiB
JavaScript
Raw Normal View History

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';
2021-09-04 01:27:46 +05:30
2020-11-24 15:15:51 +05:30
import OverrideDropdown from '~/integrations/edit/components/override_dropdown.vue';
2021-11-18 22:05:49 +05:30
import { integrationLevels, overrideDropdownDescriptions } from '~/integrations/constants';
2021-03-11 19:13:27 +05:30
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(() => {
2021-09-04 01:27:46 +05:30
wrapper.destroy();
2020-11-24 15:15:51 +05:30
});
2021-09-04 01:27:46 +05:30
const findGlLink = () => wrapper.findComponent(GlLink);
const findGlDropdown = () => wrapper.findComponent(GlDropdown);
2020-11-24 15:15:51 +05:30
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');
});
});
});
});