summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_mr_widget/components/states/mr_widget_missing_branch_spec.js
blob: 98674d12afb4bbc8f5f6ccafb3b37a252c210ddd (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
import Vue from 'vue';
import missingBranchComponent from '~/vue_merge_request_widget/components/states/mr_widget_missing_branch';

const createComponent = () => {
  const Component = Vue.extend(missingBranchComponent);
  const mr = {
    sourceBranchRemoved: true,
  };

  return new Component({
    el: document.createElement('div'),
    propsData: { mr },
  });
};

describe('MRWidgetMissingBranch', () => {
  describe('props', () => {
    it('should have props', () => {
      const mrProp = missingBranchComponent.props.mr;

      expect(mrProp.type instanceof Object).toBeTruthy();
      expect(mrProp.required).toBeTruthy();
    });
  });

  describe('components', () => {
    it('should have components added', () => {
      expect(missingBranchComponent.components['mr-widget-merge-help']).toBeDefined();
    });
  });

  describe('computed', () => {
    describe('missingBranchName', () => {
      it('should return proper branch name', () => {
        const vm = createComponent();
        expect(vm.missingBranchName).toEqual('source');

        vm.mr.sourceBranchRemoved = false;
        expect(vm.missingBranchName).toEqual('target');
      });
    });
  });

  describe('template', () => {
    it('should have correct elements', () => {
      const el = createComponent().$el;
      const content = el.textContent.replace(/\n(\s)+/g, ' ').trim();

      expect(el.classList.contains('mr-widget-body')).toBeTruthy();
      expect(el.querySelector('button').getAttribute('disabled')).toBeTruthy();
      expect(content).toContain('source branch does not exist.');
      expect(content).toContain('Please restore the source branch or use a different source branch.');
    });
  });
});