debian-mirror-gitlab/spec/frontend/helpers/init_vue_mr_page_helper.js

48 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import MockAdapter from 'axios-mock-adapter';
2020-07-28 23:09:34 +05:30
import initMRPage from '~/mr_notes';
2018-11-08 19:23:39 +05:30
import axios from '~/lib/utils/axios_utils';
2020-07-28 23:09:34 +05:30
import { userDataMock, notesDataMock, noteableDataMock } from '../notes/mock_data';
import diffFileMockData from '../diffs/mock_data/diff_file';
2018-11-08 19:23:39 +05:30
export default function initVueMRPage() {
const mrTestEl = document.createElement('div');
mrTestEl.className = 'js-merge-request-test';
document.body.appendChild(mrTestEl);
const diffsAppEndpoint = '/diffs/app/endpoint';
const diffsAppProjectPath = 'testproject';
const mrEl = document.createElement('div');
mrEl.className = 'merge-request fixture-mr';
mrEl.setAttribute('data-mr-action', 'diffs');
mrTestEl.appendChild(mrEl);
const mrDiscussionsEl = document.createElement('div');
mrDiscussionsEl.id = 'js-vue-mr-discussions';
mrDiscussionsEl.setAttribute('data-current-user-data', JSON.stringify(userDataMock));
mrDiscussionsEl.setAttribute('data-noteable-data', JSON.stringify(noteableDataMock));
mrDiscussionsEl.setAttribute('data-notes-data', JSON.stringify(notesDataMock));
mrDiscussionsEl.setAttribute('data-noteable-type', 'merge-request');
2020-10-24 23:57:45 +05:30
mrDiscussionsEl.setAttribute('data-is-locked', 'false');
2018-11-08 19:23:39 +05:30
mrTestEl.appendChild(mrDiscussionsEl);
const discussionCounterEl = document.createElement('div');
discussionCounterEl.id = 'js-vue-discussion-counter';
mrTestEl.appendChild(discussionCounterEl);
const diffsAppEl = document.createElement('div');
diffsAppEl.id = 'js-diffs-app';
diffsAppEl.setAttribute('data-endpoint', diffsAppEndpoint);
diffsAppEl.setAttribute('data-project-path', diffsAppProjectPath);
diffsAppEl.setAttribute('data-current-user-data', JSON.stringify(userDataMock));
mrTestEl.appendChild(diffsAppEl);
const mock = new MockAdapter(axios);
mock.onGet(diffsAppEndpoint).reply(200, {
branch_name: 'foo',
diff_files: [diffFileMockData],
});
initMRPage();
return mock;
}