2017-08-17 22:00:37 +05:30
|
|
|
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);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual(null);
|
|
|
|
|
|
|
|
context.canBeMerged = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('readyToMerge');
|
|
|
|
|
|
|
|
context.canMerge = false;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('notAllowedToMerge');
|
|
|
|
|
|
|
|
context.mergeWhenPipelineSucceeds = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('mergeWhenPipelineSucceeds');
|
|
|
|
|
|
|
|
context.hasSHAChanged = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('shaMismatch');
|
|
|
|
|
|
|
|
context.isPipelineBlocked = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('pipelineBlocked');
|
|
|
|
|
|
|
|
context.hasMergeableDiscussionsState = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('unresolvedDiscussions');
|
|
|
|
|
|
|
|
context.onlyAllowMergeIfPipelineSucceeds = true;
|
|
|
|
context.isPipelineFailed = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('pipelineFailed');
|
|
|
|
|
|
|
|
data.work_in_progress = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('workInProgress');
|
|
|
|
|
|
|
|
data.has_conflicts = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('conflicts');
|
|
|
|
|
|
|
|
context.mergeStatus = 'unchecked';
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('checking');
|
|
|
|
|
|
|
|
data.commits_count = 0;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('nothingToMerge');
|
|
|
|
|
|
|
|
data.branch_missing = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('missingBranch');
|
|
|
|
|
|
|
|
data.project_archived = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(bound()).toEqual('archived');
|
|
|
|
});
|
|
|
|
});
|