get_state_key_spec.js 1.8 KB
Newer Older
F
Fatih Acet 已提交
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
import getStateKey from '~/vue_merge_request_widget/stores/get_state_key';

describe('getStateKey', () => {
  it('should return proper state name', () => {
    const context = {
      mergeStatus: 'checked',
      mergeWhenPipelineSucceeds: false,
      canMerge: true,
      onlyAllowMergeIfPipelineSucceeds: false,
      isPipelineFailed: false,
      hasMergeableDiscussionsState: false,
      isPipelineBlocked: false,
      canBeMerged: false,
    };
    const data = {
      project_archived: false,
      branch_missing: false,
      commits_count: 2,
      has_conflicts: false,
      work_in_progress: false,
    };
    const bound = getStateKey.bind(context, data);
    expect(bound()).toEqual(null);

    context.canBeMerged = true;
    expect(bound()).toEqual('readyToMerge');

28 29 30 31 32 33
    context.canMerge = false;
    expect(bound()).toEqual('notAllowedToMerge');

    context.mergeWhenPipelineSucceeds = true;
    expect(bound()).toEqual('mergeWhenPipelineSucceeds');

34 35 36
    context.hasSHAChanged = true;
    expect(bound()).toEqual('shaMismatch');

F
Fatih Acet 已提交
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
    context.isPipelineBlocked = true;
    expect(bound()).toEqual('pipelineBlocked');

    context.hasMergeableDiscussionsState = true;
    expect(bound()).toEqual('unresolvedDiscussions');

    context.onlyAllowMergeIfPipelineSucceeds = true;
    context.isPipelineFailed = true;
    expect(bound()).toEqual('pipelineFailed');

    data.work_in_progress = true;
    expect(bound()).toEqual('workInProgress');

    data.has_conflicts = true;
    expect(bound()).toEqual('conflicts');

    context.mergeStatus = 'unchecked';
    expect(bound()).toEqual('checking');

    data.commits_count = 0;
    expect(bound()).toEqual('nothingToMerge');

    data.branch_missing = true;
    expect(bound()).toEqual('missingBranch');

    data.project_archived = true;
    expect(bound()).toEqual('archived');
  });
});