2018-11-08 19:23:39 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { createStore } from '~/ide/stores';
|
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2020-06-23 00:09:42 +05:30
|
|
|
import {
|
2018-11-08 19:23:39 +05:30
|
|
|
getMergeRequestData,
|
|
|
|
getMergeRequestChanges,
|
|
|
|
getMergeRequestVersions,
|
2018-11-20 20:47:30 +05:30
|
|
|
openMergeRequest,
|
2018-11-08 19:23:39 +05:30
|
|
|
} from '~/ide/stores/actions/merge_request';
|
2018-05-09 12:01:36 +05:30
|
|
|
import service from '~/ide/services';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { leftSidebarViews, PERMISSION_READ_MR } from '~/ide/constants';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
const TEST_PROJECT = 'abcproject';
|
|
|
|
const TEST_PROJECT_ID = 17;
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.mock('~/flash');
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
describe('IDE store merge request actions', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
let store;
|
2018-11-08 19:23:39 +05:30
|
|
|
let mock;
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
beforeEach(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
store = createStore();
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
store.state.projects[TEST_PROJECT] = {
|
|
|
|
id: TEST_PROJECT_ID,
|
2018-05-09 12:01:36 +05:30
|
|
|
mergeRequests: {},
|
2020-03-13 15:44:24 +05:30
|
|
|
userPermissions: {
|
|
|
|
[PERMISSION_READ_MR]: true,
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
mock.restore();
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe('getMergeRequestsForBranch', () => {
|
|
|
|
describe('success', () => {
|
|
|
|
const mrData = { iid: 2, source_branch: 'bar' };
|
|
|
|
const mockData = [mrData];
|
|
|
|
|
|
|
|
describe('base case', () => {
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(service, 'getProjectMergeRequests');
|
2019-07-07 11:18:12 +05:30
|
|
|
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, mockData);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getProjectMergeRequests service method', done => {
|
|
|
|
store
|
|
|
|
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' })
|
|
|
|
.then(() => {
|
|
|
|
expect(service.getProjectMergeRequests).toHaveBeenCalledWith(TEST_PROJECT, {
|
|
|
|
source_branch: 'bar',
|
|
|
|
source_project_id: TEST_PROJECT_ID,
|
2020-07-28 23:09:34 +05:30
|
|
|
state: 'opened',
|
2019-07-07 11:18:12 +05:30
|
|
|
order_by: 'created_at',
|
|
|
|
per_page: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the "Merge Request" Object', done => {
|
|
|
|
store
|
|
|
|
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' })
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.projects.abcproject.mergeRequests).toEqual({
|
2020-06-23 00:09:42 +05:30
|
|
|
'2': expect.objectContaining(mrData),
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets "Current Merge Request" object to the most recent MR', done => {
|
|
|
|
store
|
|
|
|
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' })
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.currentMergeRequestId).toEqual('2');
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it('does nothing if user cannot read MRs', done => {
|
|
|
|
store.state.projects[TEST_PROJECT].userPermissions[PERMISSION_READ_MR] = false;
|
|
|
|
|
|
|
|
store
|
|
|
|
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' })
|
|
|
|
.then(() => {
|
|
|
|
expect(service.getProjectMergeRequests).not.toHaveBeenCalled();
|
|
|
|
expect(store.state.currentMergeRequestId).toBe('');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('no merge requests for branch available case', () => {
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(service, 'getProjectMergeRequests');
|
2019-07-07 11:18:12 +05:30
|
|
|
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, []);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not fail if there are no merge requests for current branch', done => {
|
|
|
|
store
|
|
|
|
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'foo' })
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.projects[TEST_PROJECT].mergeRequests).toEqual({});
|
|
|
|
expect(store.state.currentMergeRequestId).toEqual('');
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).networkError();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('flashes message, if error', done => {
|
|
|
|
store
|
|
|
|
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' })
|
|
|
|
.catch(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(createFlash).toHaveBeenCalled();
|
|
|
|
expect(createFlash.mock.calls[0][0]).toBe('Error fetching merge requests for bar');
|
2019-07-07 11:18:12 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
describe('getMergeRequestData', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('success', () => {
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(service, 'getProjectMergeRequestData');
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
mock
|
|
|
|
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/)
|
|
|
|
.reply(200, { title: 'mergerequest' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getProjectMergeRequestData service method', done => {
|
|
|
|
store
|
2019-07-07 11:18:12 +05:30
|
|
|
.dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 })
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(() => {
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(service.getProjectMergeRequestData).toHaveBeenCalledWith(TEST_PROJECT, 1);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the Merge Request Object', done => {
|
|
|
|
store
|
2019-07-07 11:18:12 +05:30
|
|
|
.dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 })
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(() => {
|
|
|
|
expect(store.state.currentMergeRequestId).toBe(1);
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].title).toBe(
|
|
|
|
'mergerequest',
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/).networkError();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches error action', done => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const dispatch = jest.fn();
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
getMergeRequestData(
|
|
|
|
{
|
|
|
|
commit() {},
|
|
|
|
dispatch,
|
|
|
|
state: store.state,
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
{ projectId: TEST_PROJECT, mergeRequestId: 1 },
|
2018-11-08 19:23:39 +05:30
|
|
|
)
|
|
|
|
.then(done.fail)
|
|
|
|
.catch(() => {
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
|
2020-03-13 15:44:24 +05:30
|
|
|
text: 'An error occurred while loading the merge request.',
|
2020-06-23 00:09:42 +05:30
|
|
|
action: expect.any(Function),
|
2018-11-08 19:23:39 +05:30
|
|
|
actionText: 'Please try again',
|
|
|
|
actionPayload: {
|
2019-07-07 11:18:12 +05:30
|
|
|
projectId: TEST_PROJECT,
|
2018-11-08 19:23:39 +05:30
|
|
|
mergeRequestId: 1,
|
|
|
|
force: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getMergeRequestChanges', () => {
|
|
|
|
beforeEach(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
store.state.projects[TEST_PROJECT].mergeRequests['1'] = { changes: [] };
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('success', () => {
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(service, 'getProjectMergeRequestChanges');
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
mock
|
|
|
|
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/)
|
|
|
|
.reply(200, { title: 'mergerequest' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getProjectMergeRequestChanges service method', done => {
|
|
|
|
store
|
2019-07-07 11:18:12 +05:30
|
|
|
.dispatch('getMergeRequestChanges', { projectId: TEST_PROJECT, mergeRequestId: 1 })
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith(TEST_PROJECT, 1);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the Merge Request Changes Object', done => {
|
|
|
|
store
|
2019-07-07 11:18:12 +05:30
|
|
|
.dispatch('getMergeRequestChanges', { projectId: TEST_PROJECT, mergeRequestId: 1 })
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].changes.title).toBe(
|
2018-11-08 19:23:39 +05:30
|
|
|
'mergerequest',
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/).networkError();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches error action', done => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const dispatch = jest.fn();
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
getMergeRequestChanges(
|
|
|
|
{
|
|
|
|
commit() {},
|
|
|
|
dispatch,
|
|
|
|
state: store.state,
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
{ projectId: TEST_PROJECT, mergeRequestId: 1 },
|
2018-11-08 19:23:39 +05:30
|
|
|
)
|
|
|
|
.then(done.fail)
|
|
|
|
.catch(() => {
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
|
2020-03-13 15:44:24 +05:30
|
|
|
text: 'An error occurred while loading the merge request changes.',
|
2020-06-23 00:09:42 +05:30
|
|
|
action: expect.any(Function),
|
2018-11-08 19:23:39 +05:30
|
|
|
actionText: 'Please try again',
|
|
|
|
actionPayload: {
|
2019-07-07 11:18:12 +05:30
|
|
|
projectId: TEST_PROJECT,
|
2018-11-08 19:23:39 +05:30
|
|
|
mergeRequestId: 1,
|
|
|
|
force: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getMergeRequestVersions', () => {
|
|
|
|
beforeEach(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
store.state.projects[TEST_PROJECT].mergeRequests['1'] = { versions: [] };
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('success', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock
|
|
|
|
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/)
|
|
|
|
.reply(200, [{ id: 789 }]);
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(service, 'getProjectMergeRequestVersions');
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getProjectMergeRequestVersions service method', done => {
|
|
|
|
store
|
2019-07-07 11:18:12 +05:30
|
|
|
.dispatch('getMergeRequestVersions', { projectId: TEST_PROJECT, mergeRequestId: 1 })
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith(TEST_PROJECT, 1);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the Merge Request Versions Object', done => {
|
|
|
|
store
|
2019-07-07 11:18:12 +05:30
|
|
|
.dispatch('getMergeRequestVersions', { projectId: TEST_PROJECT, mergeRequestId: 1 })
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].versions.length).toBe(1);
|
2018-11-08 19:23:39 +05:30
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/).networkError();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches error action', done => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const dispatch = jest.fn();
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
getMergeRequestVersions(
|
|
|
|
{
|
|
|
|
commit() {},
|
|
|
|
dispatch,
|
|
|
|
state: store.state,
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
{ projectId: TEST_PROJECT, mergeRequestId: 1 },
|
2018-11-08 19:23:39 +05:30
|
|
|
)
|
|
|
|
.then(done.fail)
|
|
|
|
.catch(() => {
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
|
2020-03-13 15:44:24 +05:30
|
|
|
text: 'An error occurred while loading the merge request version data.',
|
2020-06-23 00:09:42 +05:30
|
|
|
action: expect.any(Function),
|
2018-11-08 19:23:39 +05:30
|
|
|
actionText: 'Please try again',
|
|
|
|
actionPayload: {
|
2019-07-07 11:18:12 +05:30
|
|
|
projectId: TEST_PROJECT,
|
2018-11-08 19:23:39 +05:30
|
|
|
mergeRequestId: 1,
|
|
|
|
force: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
describe('openMergeRequest', () => {
|
|
|
|
const mr = {
|
2019-07-07 11:18:12 +05:30
|
|
|
projectId: TEST_PROJECT,
|
2018-11-20 20:47:30 +05:30
|
|
|
targetProjectId: 'defproject',
|
|
|
|
mergeRequestId: 2,
|
|
|
|
};
|
|
|
|
let testMergeRequest;
|
|
|
|
let testMergeRequestChanges;
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const mockGetters = { findBranch: () => ({ commit: { id: 'abcd2322' } }) };
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
testMergeRequest = {
|
|
|
|
source_branch: 'abcbranch',
|
|
|
|
};
|
|
|
|
testMergeRequestChanges = {
|
|
|
|
changes: [],
|
|
|
|
};
|
|
|
|
store.state.entries = {
|
2019-12-26 22:10:19 +05:30
|
|
|
foo: {
|
|
|
|
type: 'blob',
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
type: 'blob',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
store.state.currentProjectId = 'test/test';
|
|
|
|
store.state.currentBranchId = 'master';
|
|
|
|
|
|
|
|
store.state.projects['test/test'] = {
|
|
|
|
branches: {
|
|
|
|
master: {
|
|
|
|
commit: {
|
|
|
|
id: '7297abc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
abcbranch: {
|
|
|
|
commit: {
|
|
|
|
id: '29020fc',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-11-20 20:47:30 +05:30
|
|
|
};
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
const originalDispatch = store.dispatch;
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(store, 'dispatch').mockImplementation((type, payload) => {
|
2018-11-20 20:47:30 +05:30
|
|
|
switch (type) {
|
|
|
|
case 'getMergeRequestData':
|
|
|
|
return Promise.resolve(testMergeRequest);
|
|
|
|
case 'getMergeRequestChanges':
|
|
|
|
return Promise.resolve(testMergeRequestChanges);
|
2019-02-15 15:39:39 +05:30
|
|
|
case 'getFiles':
|
|
|
|
case 'getMergeRequestVersions':
|
|
|
|
case 'getBranchData':
|
|
|
|
case 'setFileMrChange':
|
2019-01-03 12:48:30 +05:30
|
|
|
return Promise.resolve();
|
2019-02-15 15:39:39 +05:30
|
|
|
default:
|
|
|
|
return originalDispatch(type, payload);
|
2018-11-20 20:47:30 +05:30
|
|
|
}
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(service, 'getFileData').mockImplementation(() =>
|
2019-02-15 15:39:39 +05:30
|
|
|
Promise.resolve({
|
|
|
|
headers: {},
|
|
|
|
}),
|
|
|
|
);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('dispatches actions for merge request data', done => {
|
|
|
|
openMergeRequest({ state: store.state, dispatch: store.dispatch, getters: mockGetters }, mr)
|
2018-11-20 20:47:30 +05:30
|
|
|
.then(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(store.dispatch.mock.calls).toEqual([
|
2018-11-20 20:47:30 +05:30
|
|
|
['getMergeRequestData', mr],
|
|
|
|
['setCurrentBranchId', testMergeRequest.source_branch],
|
2018-12-13 13:39:08 +05:30
|
|
|
[
|
|
|
|
'getBranchData',
|
|
|
|
{
|
|
|
|
projectId: mr.projectId,
|
|
|
|
branchId: testMergeRequest.source_branch,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'getFiles',
|
|
|
|
{
|
|
|
|
projectId: mr.projectId,
|
|
|
|
branchId: testMergeRequest.source_branch,
|
2020-03-13 15:44:24 +05:30
|
|
|
ref: 'abcd2322',
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
],
|
2018-11-20 20:47:30 +05:30
|
|
|
['getMergeRequestVersions', mr],
|
|
|
|
['getMergeRequestChanges', mr],
|
|
|
|
]);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates activity bar view and gets file data, if changes are found', done => {
|
2019-02-15 15:39:39 +05:30
|
|
|
store.state.entries.foo = {
|
2019-12-26 22:10:19 +05:30
|
|
|
type: 'blob',
|
2019-02-15 15:39:39 +05:30
|
|
|
};
|
|
|
|
store.state.entries.bar = {
|
2019-12-26 22:10:19 +05:30
|
|
|
type: 'blob',
|
2019-02-15 15:39:39 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
testMergeRequestChanges.changes = [
|
|
|
|
{ new_path: 'foo', path: 'foo' },
|
|
|
|
{ new_path: 'bar', path: 'bar' },
|
|
|
|
];
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
openMergeRequest({ state: store.state, dispatch: store.dispatch, getters: mockGetters }, mr)
|
2018-11-20 20:47:30 +05:30
|
|
|
.then(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(store.dispatch).toHaveBeenCalledWith(
|
|
|
|
'updateActivityBarView',
|
2020-03-13 15:44:24 +05:30
|
|
|
leftSidebarViews.review.name,
|
2018-12-13 13:39:08 +05:30
|
|
|
);
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
testMergeRequestChanges.changes.forEach((change, i) => {
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('setFileMrChange', {
|
|
|
|
file: store.state.entries[change.new_path],
|
|
|
|
mrChange: change,
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('getFileData', {
|
|
|
|
path: change.new_path,
|
|
|
|
makeFileActive: i === 0,
|
2019-02-15 15:39:39 +05:30
|
|
|
openFile: true,
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
expect(store.state.openFiles.length).toBe(testMergeRequestChanges.changes.length);
|
2018-11-20 20:47:30 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('flashes message, if error', done => {
|
2020-06-23 00:09:42 +05:30
|
|
|
store.dispatch.mockRejectedValue();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
openMergeRequest(store, mr)
|
|
|
|
.catch(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(createFlash).toHaveBeenCalledWith(expect.any(String));
|
2018-11-20 20:47:30 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|