2021-12-11 22:18:48 +05:30
|
|
|
import { GlModal, GlSprintf } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
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;
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const createComponent = ({ props = {}, stubs = {} } = {}) => {
|
2020-01-01 13:55:28 +05:30
|
|
|
wrapper = mount(RemoveClusterConfirmation, {
|
|
|
|
propsData: {
|
|
|
|
clusterPath: 'clusterPath',
|
|
|
|
clusterName: 'clusterName',
|
|
|
|
...props,
|
|
|
|
},
|
2021-12-11 22:18:48 +05:30
|
|
|
stubs,
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders splitbutton with modal included', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('split button dropdown', () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
const findModal = () => wrapper.findComponent(GlModal);
|
|
|
|
const findSplitButton = () => wrapper.findComponent(SplitButton);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-12-11 22:18:48 +05:30
|
|
|
createComponent({
|
|
|
|
props: { clusterName: 'my-test-cluster' },
|
|
|
|
stubs: { GlSprintf, GlModal: stubComponent(GlModal) },
|
|
|
|
});
|
|
|
|
jest.spyOn(findModal().vm, 'show').mockReturnValue();
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('opens modal with "cleanup" option', async () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
findSplitButton().vm.$emit('remove-cluster-and-cleanup');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
expect(findModal().vm.show).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.confirmCleanup).toEqual(true);
|
|
|
|
expect(findModal().html()).toContain(
|
|
|
|
'<strong>To remove your integration and resources, type <code>my-test-cluster</code> to confirm:</strong>',
|
|
|
|
);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it('opens modal without "cleanup" option', async () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
findSplitButton().vm.$emit('remove-cluster');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
expect(findModal().vm.show).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.confirmCleanup).toEqual(false);
|
|
|
|
expect(findModal().html()).toContain(
|
|
|
|
'<strong>To remove your integration, type <code>my-test-cluster</code> to confirm:</strong>',
|
|
|
|
);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe('with cluster management project', () => {
|
|
|
|
beforeEach(() => {
|
2021-12-11 22:18:48 +05:30
|
|
|
createComponent({ props: { hasManagementProject: true } });
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|