2019-12-26 22:10:19 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { GlDropdownItem, GlIcon } from '@gitlab/ui';
|
2019-12-26 22:10:19 +05:30
|
|
|
import CrossplaneProviderStack from '~/clusters/components/crossplane_provider_stack.vue';
|
|
|
|
|
|
|
|
describe('CrossplaneProviderStack component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
stacks: [
|
|
|
|
{
|
|
|
|
name: 'Google Cloud Platform',
|
|
|
|
code: 'gcp',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Amazon Web Services',
|
|
|
|
code: 'aws',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
function createComponent(props = {}) {
|
|
|
|
const propsData = {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapper = shallowMount(CrossplaneProviderStack, {
|
|
|
|
propsData,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const crossplane = {
|
|
|
|
title: 'crossplane',
|
|
|
|
stack: '',
|
|
|
|
};
|
|
|
|
createComponent({ crossplane });
|
|
|
|
});
|
|
|
|
|
|
|
|
const findDropdownElements = () => wrapper.findAll(GlDropdownItem);
|
|
|
|
const findFirstDropdownElement = () => findDropdownElements().at(0);
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all of the available stacks in the dropdown', () => {
|
|
|
|
const dropdownElements = findDropdownElements();
|
|
|
|
|
|
|
|
expect(dropdownElements.length).toBe(defaultProps.stacks.length);
|
|
|
|
|
|
|
|
defaultProps.stacks.forEach((stack, index) =>
|
|
|
|
expect(dropdownElements.at(index).text()).toEqual(stack.name),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the correct label for the first dropdown item if a stack is selected', () => {
|
|
|
|
const crossplane = {
|
|
|
|
title: 'crossplane',
|
|
|
|
stack: 'gcp',
|
|
|
|
};
|
|
|
|
createComponent({ crossplane });
|
|
|
|
expect(wrapper.vm.dropdownText).toBe('Google Cloud Platform');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits the "set" event with the selected stack value', () => {
|
|
|
|
const crossplane = {
|
|
|
|
title: 'crossplane',
|
|
|
|
stack: 'gcp',
|
|
|
|
};
|
|
|
|
createComponent({ crossplane });
|
|
|
|
findFirstDropdownElement().vm.$emit('click');
|
|
|
|
expect(wrapper.emitted().set[0][0].code).toEqual('gcp');
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it('renders the correct dropdown text when no stack is selected', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.vm.dropdownText).toBe('Select Stack');
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it('renders an external link', () => {
|
|
|
|
expect(wrapper.find(GlIcon).props('name')).toBe('external-link');
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|