2020-01-01 13:55:28 +05:30
|
|
|
import { GlModal } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import RemoveClusterConfirmation from '~/clusters/components/remove_cluster_confirmation.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import SplitButton from '~/vue_shared/components/split_button.vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe('Remove cluster confirmation modal', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = mount(RemoveClusterConfirmation, {
|
|
|
|
propsData: {
|
|
|
|
clusterPath: 'clusterPath',
|
|
|
|
clusterName: 'clusterName',
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders splitbutton with modal included', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('split button dropdown', () => {
|
|
|
|
const findModal = () => wrapper.find(GlModal).vm;
|
2020-07-28 23:09:34 +05:30
|
|
|
const findSplitButton = () => wrapper.find(SplitButton);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ clusterName: 'my-test-cluster' });
|
|
|
|
jest.spyOn(findModal(), 'show').mockReturnValue();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens modal with "cleanup" option', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
findSplitButton().vm.$emit('remove-cluster-and-cleanup');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(findModal().show).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.confirmCleanup).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens modal without "cleanup" option', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
findSplitButton().vm.$emit('remove-cluster');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(findModal().show).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.confirmCleanup).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe('with cluster management project', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ hasManagementProject: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders regular button instead', () => {
|
|
|
|
expect(findSplitButton().exists()).toBe(false);
|
|
|
|
expect(wrapper.find('[data-testid="btnRemove"]').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|