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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
2022-08-27 11:52:29 +05:30
|
|
|
const group = wrapper.findAllComponents(GlFormInputGroup).at(index);
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(group.props('value')).toBe(value);
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(group.findComponent(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 });
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlFormInputGroup).props('value')).toBe(value);
|
|
|
|
expect(wrapper.findAllComponents(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 });
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findAllComponents(GlDropdownSectionHeader).length).toBe(1);
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly calculates httpLabel for HTTPS protocol', () => {
|
|
|
|
createComponent({ httpLink: httpsLink });
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlDropdownSectionHeader).text()).toContain('HTTPS');
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|