summaryrefslogtreecommitdiff
path: root/spec/frontend/design_management/components/delete_button_spec.js
blob: e3907fdbe15a65b14085396c1ee4c54e19fedb68 (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
import { GlButton, GlModal, GlModalDirective } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import BatchDeleteButton from '~/design_management/components/delete_button.vue';

describe('Batch delete button component', () => {
  let wrapper;

  const findButton = () => wrapper.find(GlButton);
  const findModal = () => wrapper.find(GlModal);

  function createComponent({ isDeleting = false } = {}, { slots = {} } = {}) {
    wrapper = shallowMount(BatchDeleteButton, {
      propsData: {
        isDeleting,
      },
      directives: {
        GlModalDirective,
      },
      slots,
    });
  }

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

  it('renders non-disabled button by default', () => {
    createComponent();

    expect(findButton().exists()).toBe(true);
    expect(findButton().attributes('disabled')).toBeFalsy();
  });

  it('renders disabled button when design is deleting', () => {
    createComponent({ isDeleting: true });
    expect(findButton().attributes('disabled')).toBeTruthy();
  });

  it('emits `delete-selected-designs` event on modal ok click', async () => {
    createComponent();
    findButton().vm.$emit('click');

    await nextTick();
    findModal().vm.$emit('ok');

    await nextTick();
    expect(wrapper.emitted('delete-selected-designs')).toBeTruthy();
  });

  it('renders slot content', () => {
    const testText = 'Archive selected';
    createComponent(
      {},
      {
        slots: {
          default: testText,
        },
      },
    );

    expect(findButton().text()).toBe(testText);
  });
});