Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delete_button_spec.js « components « design_management « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8f7d8e0b214caca5a718cdeecd2ff11eb0e29bdf (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
import { GlButton, GlModal, GlModalDirective } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
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 `deleteSelectedDesigns` event on modal ok click', () => {
    createComponent();
    findButton().vm.$emit('click');
    return wrapper.vm
      .$nextTick()
      .then(() => {
        findModal().vm.$emit('ok');
        return wrapper.vm.$nextTick();
      })
      .then(() => {
        expect(wrapper.emitted().deleteSelectedDesigns).toBeTruthy();
      });
  });

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

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