2021-02-22 17:27:13 +05:30
|
|
|
import { convertToCamelCase } from '~/lib/utils/text_utility';
|
2017-08-17 22:00:37 +05:30
|
|
|
import MergeRequestStore from '~/vue_merge_request_widget/stores/mr_widget_store';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { stateKey } from '~/vue_merge_request_widget/stores/state_maps';
|
2017-08-17 22:00:37 +05:30
|
|
|
import mockData from '../mock_data';
|
|
|
|
|
|
|
|
describe('MergeRequestStore', () => {
|
2019-02-15 15:39:39 +05:30
|
|
|
let store;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
store = new MergeRequestStore(mockData);
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
it('should initialize gitpod attributes', () => {
|
|
|
|
expect(store).toMatchObject({
|
|
|
|
gitpodEnabled: mockData.gitpod_enabled,
|
|
|
|
showGitpodButton: mockData.show_gitpod_button,
|
|
|
|
gitpodUrl: mockData.gitpod_url,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('setData', () => {
|
|
|
|
it('should set isSHAMismatch when the diff SHA changes', () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
store.setData({ ...mockData, diff_head_sha: 'a-different-string' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(store.isSHAMismatch).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it('should not set isSHAMismatch when other data changes', () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
store.setData({ ...mockData, work_in_progress: !mockData.work_in_progress });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(store.isSHAMismatch).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update cached sha after rebasing', () => {
|
|
|
|
store.setData({ ...mockData, diff_head_sha: 'abc123' }, true);
|
|
|
|
|
|
|
|
expect(store.isSHAMismatch).toBe(false);
|
|
|
|
expect(store.sha).toBe('abc123');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('isPipelinePassing', () => {
|
|
|
|
it('is true when the CI status is `success`', () => {
|
|
|
|
store.setData({ ...mockData, ci_status: 'success' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.isPipelinePassing).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it('is true when the CI status is `success-with-warnings`', () => {
|
|
|
|
store.setData({ ...mockData, ci_status: 'success-with-warnings' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.isPipelinePassing).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is false when the CI status is `failed`', () => {
|
|
|
|
store.setData({ ...mockData, ci_status: 'failed' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.isPipelinePassing).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is false when the CI status is anything except `success`', () => {
|
|
|
|
store.setData({ ...mockData, ci_status: 'foobarbaz' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.isPipelinePassing).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isPipelineSkipped', () => {
|
|
|
|
it('should set isPipelineSkipped=true when the CI status is `skipped`', () => {
|
|
|
|
store.setData({ ...mockData, ci_status: 'skipped' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.isPipelineSkipped).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set isPipelineSkipped=false when the CI status is anything except `skipped`', () => {
|
|
|
|
store.setData({ ...mockData, ci_status: 'foobarbaz' });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(store.isPipelineSkipped).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('isPipelineBlocked', () => {
|
|
|
|
const pipelineWaitingForManualAction = {
|
|
|
|
details: {
|
|
|
|
status: {
|
|
|
|
group: 'manual',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should be `false` when the pipeline status is missing', () => {
|
|
|
|
store.setData({ ...mockData, pipeline: undefined });
|
|
|
|
|
|
|
|
expect(store.isPipelineBlocked).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be `false` when the pipeline is waiting for manual action', () => {
|
|
|
|
store.setData({ ...mockData, pipeline: pipelineWaitingForManualAction });
|
|
|
|
|
|
|
|
expect(store.isPipelineBlocked).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be `true` when the pipeline is waiting for manual action and the pipeline must succeed', () => {
|
|
|
|
store.setData({
|
|
|
|
...mockData,
|
|
|
|
pipeline: pipelineWaitingForManualAction,
|
|
|
|
only_allow_merge_if_pipeline_succeeds: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(store.isPipelineBlocked).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('isNothingToMergeState', () => {
|
|
|
|
it('returns true when nothingToMerge', () => {
|
|
|
|
store.state = stateKey.nothingToMerge;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.isNothingToMergeState).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when not nothingToMerge', () => {
|
|
|
|
store.state = 'state';
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.isNothingToMergeState).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe('setPaths', () => {
|
|
|
|
it('should set the add ci config path', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
store.setPaths({ ...mockData });
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.mergeRequestAddCiConfigPath).toBe('/group2/project2/new/pipeline');
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should set humanAccess=Maintainer when user has that role', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
store.setPaths({ ...mockData });
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.humanAccess).toBe('Maintainer');
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
it('should set pipelinesEmptySvgPath', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
store.setPaths({ ...mockData });
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(store.pipelinesEmptySvgPath).toBe('/path/to/svg');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set newPipelinePath', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
store.setPaths({ ...mockData });
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(store.newPipelinePath).toBe('/group2/project2/pipelines/new');
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('should set sourceProjectDefaultUrl', () => {
|
|
|
|
store.setPaths({ ...mockData });
|
|
|
|
|
|
|
|
expect(store.sourceProjectDefaultUrl).toBe('/gitlab-org/html5-boilerplate.git');
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('should set securityReportsDocsPath', () => {
|
|
|
|
store.setPaths({ ...mockData });
|
|
|
|
|
|
|
|
expect(store.securityReportsDocsPath).toBe('security-reports-docs-path');
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it.each(['sast_comparison_path', 'secret_detection_comparison_path'])(
|
2021-02-22 17:27:13 +05:30
|
|
|
'should set %s path',
|
2021-03-08 18:12:59 +05:30
|
|
|
(property) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
// Ensure something is set in the mock data
|
|
|
|
expect(property in mockData).toBe(true);
|
|
|
|
const expectedValue = mockData[property];
|
|
|
|
|
|
|
|
store.setPaths({ ...mockData });
|
|
|
|
|
|
|
|
expect(store[convertToCamelCase(property)]).toBe(expectedValue);
|
|
|
|
},
|
|
|
|
);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|