summaryrefslogtreecommitdiff
path: root/spec/frontend/clusters/components/remove_cluster_confirmation_spec.js
blob: 41bd492148e254b7642aa9ce6c2b9b5f6ff35aa4 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
import { GlModal, GlSprintf } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { stubComponent } from 'helpers/stub_component';
import RemoveClusterConfirmation from '~/clusters/components/remove_cluster_confirmation.vue';
import SplitButton from '~/vue_shared/components/split_button.vue';

describe('Remove cluster confirmation modal', () => {
  let wrapper;

  const createComponent = ({ props = {}, stubs = {} } = {}) => {
    wrapper = mount(RemoveClusterConfirmation, {
      propsData: {
        clusterPath: 'clusterPath',
        clusterName: 'clusterName',
        ...props,
      },
      stubs,
    });
  };

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  it('renders splitbutton with modal included', () => {
    createComponent();
    expect(wrapper.element).toMatchSnapshot();
  });

  describe('split button dropdown', () => {
    const findModal = () => wrapper.findComponent(GlModal);
    const findSplitButton = () => wrapper.findComponent(SplitButton);

    beforeEach(() => {
      createComponent({
        props: { clusterName: 'my-test-cluster' },
        stubs: { GlSprintf, GlModal: stubComponent(GlModal) },
      });
      jest.spyOn(findModal().vm, 'show').mockReturnValue();
    });

    it('opens modal with "cleanup" option', async () => {
      findSplitButton().vm.$emit('remove-cluster-and-cleanup');

      await wrapper.vm.$nextTick();

      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>',
      );
    });

    it('opens modal without "cleanup" option', async () => {
      findSplitButton().vm.$emit('remove-cluster');

      await wrapper.vm.$nextTick();

      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>',
      );
    });

    describe('with cluster management project', () => {
      beforeEach(() => {
        createComponent({ props: { hasManagementProject: true } });
      });

      it('renders regular button instead', () => {
        expect(findSplitButton().exists()).toBe(false);
        expect(wrapper.find('[data-testid="btnRemove"]').exists()).toBe(true);
      });
    });
  });
});