summaryrefslogtreecommitdiff
path: root/spec/frontend/diffs/components/edit_button_spec.js
blob: 71512c1c4af07cd2812165f082ea2e8b84c4aee3 (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
import { shallowMount } from '@vue/test-utils';
import { GlDeprecatedButton } from '@gitlab/ui';
import EditButton from '~/diffs/components/edit_button.vue';

const editPath = 'test-path';

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

  const createComponent = (props = {}) => {
    wrapper = shallowMount(EditButton, {
      propsData: { ...props },
    });
  };

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

  it('has correct href attribute', () => {
    createComponent({
      editPath,
      canCurrentUserFork: false,
    });

    expect(wrapper.find(GlDeprecatedButton).attributes('href')).toBe(editPath);
  });

  it('emits a show fork message event if current user can fork', () => {
    createComponent({
      editPath,
      canCurrentUserFork: true,
    });
    wrapper.find(GlDeprecatedButton).trigger('click');

    return wrapper.vm.$nextTick().then(() => {
      expect(wrapper.emitted('showForkMessage')).toBeTruthy();
    });
  });

  it('doesnt emit a show fork message event if current user cannot fork', () => {
    createComponent({
      editPath,
      canCurrentUserFork: false,
    });
    wrapper.find(GlDeprecatedButton).trigger('click');

    return wrapper.vm.$nextTick().then(() => {
      expect(wrapper.emitted('showForkMessage')).toBeFalsy();
    });
  });

  it('doesnt emit a show fork message event if current user can modify blob', () => {
    createComponent({
      editPath,
      canCurrentUserFork: true,
      canModifyBlob: true,
    });
    wrapper.find(GlDeprecatedButton).trigger('click');

    return wrapper.vm.$nextTick().then(() => {
      expect(wrapper.emitted('showForkMessage')).toBeFalsy();
    });
  });

  it('disables button if editPath is empty', () => {
    createComponent({
      editPath: '',
      canCurrentUserFork: true,
      canModifyBlob: true,
    });

    expect(wrapper.find(GlDeprecatedButton).attributes('disabled')).toBe('true');
  });
});