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

delete_button_spec.js « components « explorer « registry « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a79ca77a464cb6cbacc6ae5caf747b0821405ab3 (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
import { shallowMount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import component from '~/registry/explorer/components/delete_button.vue';

describe('delete_button', () => {
  let wrapper;

  const defaultProps = {
    title: 'Foo title',
    tooltipTitle: 'Bar tooltipTitle',
  };

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

  const mountComponent = props => {
    wrapper = shallowMount(component, {
      propsData: {
        ...defaultProps,
        ...props,
      },
      directives: {
        GlTooltip: createMockDirective(),
      },
    });
  };

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

  describe('tooltip', () => {
    it('the title is controlled by tooltipTitle prop', () => {
      mountComponent();
      const tooltip = getBinding(wrapper.element, 'gl-tooltip');
      expect(tooltip).toBeDefined();
      expect(tooltip.value.title).toBe(defaultProps.tooltipTitle);
    });

    it('is disabled when tooltipTitle is disabled', () => {
      mountComponent({ tooltipDisabled: true });
      const tooltip = getBinding(wrapper.element, 'gl-tooltip');
      expect(tooltip.value.disabled).toBe(true);
    });

    describe('button', () => {
      it('exists', () => {
        mountComponent();
        expect(findButton().exists()).toBe(true);
      });

      it('has the correct props/attributes bound', () => {
        mountComponent({ disabled: true });
        expect(findButton().attributes()).toMatchObject({
          'aria-label': 'Foo title',
          icon: 'remove',
          title: 'Foo title',
          variant: 'danger',
          disabled: 'true',
        });
      });

      it('emits a delete event', () => {
        mountComponent();
        expect(wrapper.emitted('delete')).toEqual(undefined);
        findButton().vm.$emit('click');
        expect(wrapper.emitted('delete')).toEqual([[]]);
      });
    });
  });
});