summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_merge_request_widget/components/states/mr_widget_nothing_to_merge_spec.js
blob: c8fa1399dcbd80c0964955d3ec73f31c39eb87f3 (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
import { GlSprintf } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import NothingToMerge from '~/vue_merge_request_widget/components/states/nothing_to_merge.vue';

describe('NothingToMerge', () => {
  let wrapper;
  const newBlobPath = '/foo';

  const defaultProps = {
    mr: {
      newBlobPath,
    },
  };

  const createComponent = (props = defaultProps) => {
    wrapper = shallowMountExtended(NothingToMerge, {
      propsData: {
        ...props,
      },
      stubs: {
        GlSprintf,
      },
    });
  };

  const findCreateButton = () => wrapper.findByTestId('createFileButton');
  const findNothingToMergeTextBody = () => wrapper.findByTestId('nothing-to-merge-body');

  describe('With Blob link', () => {
    beforeEach(() => {
      createComponent();
    });

    it('shows the component with the correct text and highlights', () => {
      expect(wrapper.text()).toContain('This merge request contains no changes.');
      expect(findNothingToMergeTextBody().text()).toContain(
        'Use merge requests to propose changes to your project and discuss them with your team. To make changes, push a commit or edit this merge request to use a different branch.',
      );
    });

    it('shows the Create file button with the correct attributes', () => {
      const createButton = findCreateButton();

      expect(createButton.exists()).toBe(true);
      expect(createButton.attributes('href')).toBe(newBlobPath);
    });
  });

  describe('Without Blob link', () => {
    beforeEach(() => {
      createComponent({ mr: { newBlobPath: '' } });
    });

    it('does not show the Create file button', () => {
      expect(findCreateButton().exists()).toBe(false);
    });
  });
});