1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import { mount } from '@vue/test-utils';
import { GlModal } from '@gitlab/ui';
import SplitButton from '~/vue_shared/components/split_button.vue';
import RemoveClusterConfirmation from '~/clusters/components/remove_cluster_confirmation.vue';
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;
const findSplitButton = () => wrapper.find(SplitButton);
beforeEach(() => {
createComponent({ clusterName: 'my-test-cluster' });
jest.spyOn(findModal(), 'show').mockReturnValue();
});
it('opens modal with "cleanup" option', () => {
findSplitButton().vm.$emit('remove-cluster-and-cleanup');
return wrapper.vm.$nextTick().then(() => {
expect(findModal().show).toHaveBeenCalled();
expect(wrapper.vm.confirmCleanup).toEqual(true);
});
});
it('opens modal without "cleanup" option', () => {
findSplitButton().vm.$emit('remove-cluster');
return wrapper.vm.$nextTick().then(() => {
expect(findModal().show).toHaveBeenCalled();
expect(wrapper.vm.confirmCleanup).toEqual(false);
});
});
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);
});
});
});
});
|