Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compare_app_spec.js « components « merge_requests « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 887f79f9fadc0cfb21a135fddceb625d4b574763 (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
86
87
88
89
90
91
92
93
94
import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import axios from '~/lib/utils/axios_utils';
import CompareApp from '~/merge_requests/components/compare_app.vue';

let wrapper;
let mock;

function factory(provideData = {}) {
  wrapper = shallowMountExtended(CompareApp, {
    provide: {
      inputs: {
        project: {
          id: 'project',
          name: 'project',
        },
        branch: {
          id: 'branch',
          name: 'branch',
        },
      },
      branchCommitPath: '/commit',
      toggleClass: {
        project: 'project',
        branch: 'branch',
      },
      i18n: {
        projectHeaderText: 'Project',
        branchHeaderText: 'Branch',
      },
      ...provideData,
    },
  });
}

const findCommitBox = () => wrapper.findByTestId('commit-box');

describe('Merge requests compare app component', () => {
  beforeEach(() => {
    mock = new MockAdapter(axios);
    mock.onGet('/commit').reply(200, 'commit content');
  });

  afterEach(() => {
    mock.restore();
  });

  it('shows commit box when selected branch is empty', () => {
    factory({
      currentBranch: {
        text: '',
        value: '',
      },
    });

    const commitBox = findCommitBox();

    expect(commitBox.exists()).toBe(true);
    expect(commitBox.text()).toBe('Select a branch to compare');
  });

  it('emits select-branch on selected event', () => {
    factory({
      currentBranch: {
        text: '',
        value: '',
      },
    });

    wrapper.findByTestId('compare-dropdown').vm.$emit('selected', { value: 'main' });

    expect(wrapper.emitted('select-branch')).toEqual([['main']]);
  });

  describe('currentBranch watcher', () => {
    it('changes selected value', async () => {
      factory({
        currentBranch: {
          text: '',
          value: '',
        },
      });

      expect(findCommitBox().text()).toBe('Select a branch to compare');

      wrapper.setProps({ currentBranch: { text: 'main', value: 'main ' } });

      await waitForPromises();

      expect(findCommitBox().text()).toBe('commit content');
    });
  });
});