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',
|
2019-09-04 21:01:54 +05:30
|
|
|
autoMergeEnabled: false,
|
2017-08-17 22:00:37 +05:30
|
|
|
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');
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context.autoMergeEnabled = true;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(bound()).toEqual('autoMergeEnabled');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
context.isSHAMismatch = 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');
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
it('returns rebased state key', () => {
|
|
|
|
const context = {
|
|
|
|
mergeStatus: 'checked',
|
2019-09-04 21:01:54 +05:30
|
|
|
autoMergeEnabled: false,
|
2019-03-02 22:35:43 +05:30
|
|
|
canMerge: true,
|
|
|
|
onlyAllowMergeIfPipelineSucceeds: true,
|
|
|
|
isPipelineFailed: true,
|
|
|
|
hasMergeableDiscussionsState: false,
|
|
|
|
isPipelineBlocked: false,
|
|
|
|
canBeMerged: false,
|
|
|
|
shouldBeRebased: true,
|
|
|
|
};
|
|
|
|
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('rebase');
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|