2020-11-24 15:15:51 +05:30
|
|
|
import { GlFormInputGroup, GlDropdownSectionHeader } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import CloneDropdown from '~/vue_shared/components/clone_dropdown.vue';
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
describe('Clone Dropdown Button', () => {
|
|
|
|
let wrapper;
|
|
|
|
const sshLink = 'ssh://foo.bar';
|
|
|
|
const httpLink = 'http://foo.bar';
|
|
|
|
const httpsLink = 'https://foo.bar';
|
|
|
|
const defaultPropsData = {
|
|
|
|
sshLink,
|
|
|
|
httpLink,
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = (propsData = defaultPropsData) => {
|
|
|
|
wrapper = shallowMount(CloneDropdown, {
|
|
|
|
propsData,
|
|
|
|
stubs: {
|
|
|
|
'gl-form-input-group': GlFormInputGroup,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('rendering', () => {
|
|
|
|
it('matches the snapshot', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
name | index | value
|
|
|
|
${'SSH'} | ${0} | ${sshLink}
|
|
|
|
${'HTTP'} | ${1} | ${httpLink}
|
|
|
|
`('renders correct link and a copy-button for $name', ({ index, value }) => {
|
|
|
|
createComponent();
|
|
|
|
const group = wrapper.findAll(GlFormInputGroup).at(index);
|
|
|
|
expect(group.props('value')).toBe(value);
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(group.find(GlFormInputGroup).exists()).toBe(true);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
name | value
|
|
|
|
${'sshLink'} | ${sshLink}
|
|
|
|
${'httpLink'} | ${httpLink}
|
|
|
|
`('does not fail if only $name is set', ({ name, value }) => {
|
|
|
|
createComponent({ [name]: value });
|
|
|
|
|
|
|
|
expect(wrapper.find(GlFormInputGroup).props('value')).toBe(value);
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.findAll(GlDropdownSectionHeader).length).toBe(1);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('functionality', () => {
|
|
|
|
it.each`
|
|
|
|
name | value
|
|
|
|
${'sshLink'} | ${null}
|
|
|
|
${'httpLink'} | ${null}
|
|
|
|
`('allows null values for the props', ({ name, value }) => {
|
|
|
|
createComponent({ ...defaultPropsData, [name]: value });
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.findAll(GlDropdownSectionHeader).length).toBe(1);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly calculates httpLabel for HTTPS protocol', () => {
|
|
|
|
createComponent({ httpLink: httpsLink });
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlDropdownSectionHeader).text()).toContain('HTTPS');
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|