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
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
import BranchMoreDropdown from '~/branches/components/branch_more_actions.vue';
import eventHub from '~/branches/event_hub';
describe('Delete branch button', () => {
let wrapper;
let eventHubSpy;
const findCompareButton = () => wrapper.findByTestId('compare-branch-button');
const findDeleteButton = () => wrapper.findByTestId('delete-branch-button');
const createComponent = (props = {}) => {
wrapper = mountExtended(BranchMoreDropdown, {
propsData: {
branchName: 'test',
defaultBranchName: 'main',
canDeleteBranch: true,
isProtectedBranch: false,
merged: false,
comparePath: '/path/to/branch',
deletePath: '/path/to/branch',
...props,
},
});
};
beforeEach(() => {
eventHubSpy = jest.spyOn(eventHub, '$emit');
});
it('renders the compare action', () => {
createComponent();
expect(findCompareButton().exists()).toBe(true);
expect(findCompareButton().text()).toBe('Compare');
});
it('renders the delete action', () => {
createComponent();
expect(findDeleteButton().exists()).toBe(true);
expect(findDeleteButton().text()).toBe('Delete branch');
});
it('renders a different text for a protected branch', () => {
createComponent({ isProtectedBranch: true });
expect(findDeleteButton().text()).toBe('Delete protected branch');
});
it('emits the data to eventHub when button is clicked', async () => {
createComponent({ merged: true });
await findDeleteButton().trigger('click');
expect(eventHubSpy).toHaveBeenCalledWith('openModal', {
branchName: 'test',
defaultBranchName: 'main',
deletePath: '/path/to/branch',
isProtectedBranch: false,
merged: true,
});
});
it('doesn`t render the delete action when user cannot delete branch', () => {
createComponent({ canDeleteBranch: false });
expect(findDeleteButton().exists()).toBe(false);
});
});
|