summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_mr_widget/stores/get_state_key_spec.js
blob: 631d4647b17a9d81731c7f8cd7ca2c7d71dc9272 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import getStateKey from '~/vue_merge_request_widget/stores/get_state_key';

describe('getStateKey', () => {
  it('should return proper state name', () => {
    const context = {
      mergeStatus: 'checked',
      autoMergeEnabled: false,
      canMerge: true,
      onlyAllowMergeIfPipelineSucceeds: false,
      isPipelineFailed: false,
      hasMergeableDiscussionsState: false,
      isPipelineBlocked: false,
      canBeMerged: false,
      projectArchived: false,
      branchMissing: false,
      commitsCount: 2,
      hasConflicts: false,
      workInProgress: false,
    };
    const bound = getStateKey.bind(context);

    expect(bound()).toEqual(null);

    context.canBeMerged = true;

    expect(bound()).toEqual('readyToMerge');

    context.canMerge = false;

    expect(bound()).toEqual('notAllowedToMerge');

    context.autoMergeEnabled = true;
    context.hasMergeableDiscussionsState = true;

    expect(bound()).toEqual('autoMergeEnabled');

    context.canMerge = true;
    context.isSHAMismatch = true;

    expect(bound()).toEqual('shaMismatch');

    context.canMerge = false;
    context.isPipelineBlocked = true;

    expect(bound()).toEqual('pipelineBlocked');

    context.hasMergeableDiscussionsState = true;
    context.autoMergeEnabled = false;

    expect(bound()).toEqual('unresolvedDiscussions');

    context.workInProgress = true;

    expect(bound()).toEqual('workInProgress');

    context.onlyAllowMergeIfPipelineSucceeds = true;
    context.isPipelineFailed = true;

    expect(bound()).toEqual('pipelineFailed');

    context.shouldBeRebased = true;

    expect(bound()).toEqual('rebase');

    context.hasConflicts = true;

    expect(bound()).toEqual('conflicts');

    context.mergeStatus = 'unchecked';

    expect(bound()).toEqual('checking');

    context.commitsCount = 0;

    expect(bound()).toEqual('nothingToMerge');

    context.branchMissing = true;

    expect(bound()).toEqual('missingBranch');

    context.projectArchived = true;

    expect(bound()).toEqual('archived');
  });

  it('returns rebased state key', () => {
    const context = {
      mergeStatus: 'checked',
      autoMergeEnabled: false,
      canMerge: true,
      onlyAllowMergeIfPipelineSucceeds: true,
      isPipelineFailed: true,
      hasMergeableDiscussionsState: false,
      isPipelineBlocked: false,
      canBeMerged: false,
      shouldBeRebased: true,
      projectArchived: false,
      branchMissing: false,
      commitsCount: 2,
      hasConflicts: false,
      workInProgress: false,
    };
    const bound = getStateKey.bind(context);

    expect(bound()).toEqual('rebase');
  });

  it.each`
    canMerge | isSHAMismatch | stateKey
    ${true}  | ${true}       | ${'shaMismatch'}
    ${false} | ${true}       | ${'notAllowedToMerge'}
    ${false} | ${false}      | ${'notAllowedToMerge'}
  `(
    'returns $stateKey when canMerge is $canMerge and isSHAMismatch is $isSHAMismatch',
    ({ canMerge, isSHAMismatch, stateKey }) => {
      const bound = getStateKey.bind({
        canMerge,
        isSHAMismatch,
        commitsCount: 2,
      });

      expect(bound()).toEqual(stateKey);
    },
  );
});