summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_mr_widget/components/states/mr_widget_conflicts_spec.js
blob: a7d69fdcdb9aa6abbc2b947f03e270e1c3c4c7ed (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
import Vue from 'vue';
import conflictsComponent from '~/vue_merge_request_widget/components/states/mr_widget_conflicts.vue';
import mountComponent from '../../../helpers/vue_mount_component_helper';

describe('MRWidgetConflicts', () => {
  let Component;
  let vm;
  const path = '/conflicts';

  beforeEach(() => {
    Component = Vue.extend(conflictsComponent);
  });

  afterEach(() => {
    vm.$destroy();
  });

  describe('when allowed to merge', () => {
    beforeEach(() => {
      vm = mountComponent(Component, {
        mr: {
          canMerge: true,
          conflictResolutionPath: path,
        },
      });
    });

    it('should tell you about conflicts without bothering other people', () => {
      expect(vm.$el.textContent).toContain('There are merge conflicts');
      expect(vm.$el.textContent).not.toContain('ask someone with write access');
    });

    it('should allow you to resolve the conflicts', () => {
      const resolveButton = vm.$el.querySelector('.js-resolve-conflicts-button');

      expect(resolveButton.textContent).toContain('Resolve conflicts');
      expect(resolveButton.getAttribute('href')).toEqual(path);
    });

    it('should have merge buttons', () => {
      const mergeButton = vm.$el.querySelector('.js-disabled-merge-button');
      const mergeLocallyButton = vm.$el.querySelector('.js-merge-locally-button');

      expect(mergeButton.textContent).toContain('Merge');
      expect(mergeButton.disabled).toBeTruthy();
      expect(mergeButton.classList.contains('btn-success')).toEqual(true);
      expect(mergeLocallyButton.textContent).toContain('Merge locally');
    });
  });

  describe('when user does not have permission to merge', () => {
    beforeEach(() => {
      vm = mountComponent(Component, {
        mr: {
          canMerge: false,
        },
      });
    });

    it('should show proper message', () => {
      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toContain('ask someone with write access');
    });

    it('should not have action buttons', () => {
      expect(vm.$el.querySelector('.js-disabled-merge-button')).toBeDefined();
      expect(vm.$el.querySelector('.js-resolve-conflicts-button')).toBeNull();
      expect(vm.$el.querySelector('.js-merge-locally-button')).toBeNull();
    });
  });

  describe('when fast-forward or semi-linear merge enabled', () => {
    beforeEach(() => {
      vm = mountComponent(Component, {
        mr: {
          shouldBeRebased: true,
        },
      });
    });

    it('should tell you to rebase locally', () => {
      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toContain('Fast-forward merge is not possible.');
      expect(vm.$el.textContent.trim().replace(/\s\s+/g, ' ')).toContain('To merge this request, first rebase locally');
    });
  });
});