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

delete_branch_button_spec.js « components « branches « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b029f34c3d7123efdc2344eae00e9291750ea134 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import DeleteBranchButton from '~/branches/components/delete_branch_button.vue';
import eventHub from '~/branches/event_hub';

let wrapper;
let findDeleteButton;

const createComponent = (props = {}) => {
  wrapper = shallowMount(DeleteBranchButton, {
    propsData: {
      branchName: 'test',
      deletePath: '/path/to/branch',
      defaultBranchName: 'main',
      ...props,
    },
  });
};

describe('Delete branch button', () => {
  let eventHubSpy;

  beforeEach(() => {
    findDeleteButton = () => wrapper.findComponent(GlButton);
    eventHubSpy = jest.spyOn(eventHub, '$emit');
  });

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

  it('renders the button with default tooltip, style, and icon', () => {
    createComponent();

    expect(findDeleteButton().attributes()).toMatchObject({
      title: 'Delete branch',
      variant: 'default',
      icon: 'remove',
    });
  });

  it('renders a different tooltip for a protected branch', () => {
    createComponent({ isProtectedBranch: true });

    expect(findDeleteButton().attributes()).toMatchObject({
      title: 'Delete protected branch',
      variant: 'default',
      icon: 'remove',
    });
  });

  it('renders a different protected tooltip when it is both protected and disabled', () => {
    createComponent({ isProtectedBranch: true, disabled: true });

    expect(findDeleteButton().attributes()).toMatchObject({
      title: 'Only a project maintainer or owner can delete a protected branch',
      variant: 'default',
    });
  });

  it('emits the data to eventHub when button is clicked', () => {
    createComponent({ merged: true });

    findDeleteButton().vm.$emit('click');

    expect(eventHubSpy).toHaveBeenCalledWith('openModal', {
      branchName: 'test',
      defaultBranchName: 'main',
      deletePath: '/path/to/branch',
      isProtectedBranch: false,
      merged: true,
    });
  });

  describe('#disabled', () => {
    it('does not disable the button by default when mounted', () => {
      createComponent();

      expect(findDeleteButton().attributes()).toMatchObject({
        title: 'Delete branch',
        variant: 'default',
      });
    });

    // Used for unallowed users and for the default branch.
    it('disables the button when mounted for a disabled modal', () => {
      createComponent({ disabled: true, tooltip: 'The default branch cannot be deleted' });

      expect(findDeleteButton().attributes()).toMatchObject({
        title: 'The default branch cannot be deleted',
        disabled: 'true',
        variant: 'default',
      });
    });
  });
});