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

conflicts_spec.js « checks « components « vue_merge_request_widget « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57dcd2fd819a4558a9c73f58dfa074786fe4bfcf (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
import VueApollo from 'vue-apollo';
import Vue from 'vue';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import ConflictsComponent from '~/vue_merge_request_widget/components/checks/conflicts.vue';
import conflictsStateQuery from '~/vue_merge_request_widget/queries/states/conflicts.query.graphql';

Vue.use(VueApollo);

let wrapper;
let apolloProvider;

function factory({
  result = 'passed',
  canMerge = true,
  pushToSourceBranch = true,
  shouldBeRebased = false,
  sourceBranchProtected = false,
  mr = {},
} = {}) {
  apolloProvider = createMockApollo([
    [
      conflictsStateQuery,
      jest.fn().mockResolvedValue({
        data: {
          project: {
            id: 1,
            mergeRequest: {
              id: 1,
              shouldBeRebased,
              sourceBranchProtected,
              userPermissions: { canMerge, pushToSourceBranch },
            },
          },
        },
      }),
    ],
  ]);

  wrapper = mountExtended(ConflictsComponent, {
    apolloProvider,
    propsData: {
      mr,
      check: { result, failureReason: 'Conflicts message' },
    },
  });
}

describe('Merge request merge checks conflicts component', () => {
  afterEach(() => {
    apolloProvider = null;
  });

  it('renders failure reason text', () => {
    factory();

    expect(wrapper.text()).toEqual('Conflicts message');
  });

  it.each`
    conflictResolutionPath  | pushToSourceBranch | sourceBranchProtected | rendersConflictButton | rendersConflictButtonText
    ${'https://gitlab.com'} | ${true}            | ${false}              | ${true}               | ${'renders'}
    ${undefined}            | ${true}            | ${false}              | ${false}              | ${'does not render'}
    ${'https://gitlab.com'} | ${false}           | ${false}              | ${false}              | ${'does not render'}
    ${'https://gitlab.com'} | ${true}            | ${true}               | ${false}              | ${'does not render'}
    ${'https://gitlab.com'} | ${false}           | ${false}              | ${false}              | ${'does not render'}
    ${undefined}            | ${false}           | ${false}              | ${false}              | ${'does not render'}
  `(
    '$rendersConflictButtonText the conflict button for $conflictResolutionPath $pushToSourceBranch $sourceBranchProtected $rendersConflictButton',
    async ({
      conflictResolutionPath,
      pushToSourceBranch,
      sourceBranchProtected,
      rendersConflictButton,
    }) => {
      factory({ mr: { conflictResolutionPath }, pushToSourceBranch, sourceBranchProtected });

      await waitForPromises();

      expect(wrapper.findAllByTestId('extension-actions-button').length).toBe(
        rendersConflictButton ? 2 : 1,
      );

      expect(wrapper.findAllByTestId('extension-actions-button').at(-1).text()).toBe(
        rendersConflictButton ? 'Resolve conflicts' : 'Resolve locally',
      );
    },
  );
});