Commit 4b15c2c1 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'test-coverage/test-diff-file-metadata-preparation' into 'master'

Test all of the `diffs_metadata.json` handling through `prepareDiffData`

See merge request gitlab-org/gitlab!34335
parents 9d8d5c63 12d7d348
......@@ -13,6 +13,7 @@ export default {
blob_name: 'CHANGELOG',
blob_icon: '<i aria-hidden="true" data-hidden="true" class="fa fa-file-text-o fa-fw"></i>',
file_hash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a',
file_identifier_hash: '928f8286952bda02d674b692addcbe077084663a',
file_path: 'CHANGELOG',
new_file: false,
deleted_file: false,
......
/* eslint-disable import/prefer-default-export */
/* https://gitlab.com/gitlab-org/frontend/rfcs/-/issues/20 */
export const diffMetadata = {
real_size: '1',
size: 1,
branch_name: 'update-changelog',
source_branch_exists: true,
target_branch_name: 'master',
commit: null,
context_commits: null,
merge_request_diff: {
version_index: null,
created_at: '2019-11-07T06:48:35.202Z',
commits_count: 1,
latest: true,
short_commit_sha: 'eb227b3e',
base_version_path: '/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_id=4',
head_version_path: '/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_head=true',
version_path: '/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_id=4',
compare_path:
'/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_id=4\u0026start_sha=eb227b3e214624708c474bdab7bde7afc17cefcc',
},
start_version: null,
latest_diff: true,
latest_version_path: '/gitlab-org/gitlab-test/-/merge_requests/4/diffs',
added_lines: 2,
removed_lines: 0,
render_overflow_warning: false,
email_patch_path: '/gitlab-org/gitlab-test/-/merge_requests/4.patch',
plain_diff_path: '/gitlab-org/gitlab-test/-/merge_requests/4.diff',
merge_request_diffs: [
{
version_index: null,
created_at: '2019-11-07T06:48:35.202Z',
commits_count: 1,
latest: true,
short_commit_sha: 'eb227b3e',
base_version_path: '/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_id=4',
head_version_path: '/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_head=true',
version_path: '/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_id=4',
compare_path:
'/gitlab-org/gitlab-test/-/merge_requests/4/diffs?diff_id=4\u0026start_sha=eb227b3e214624708c474bdab7bde7afc17cefcc',
},
],
diff_files: [
{
added_lines: 2,
removed_lines: 0,
new_path: 'CHANGELOG',
old_path: 'CHANGELOG',
new_file: false,
deleted_file: false,
file_identifier_hash: '928f8286952bda02d674b692addcbe077084663a',
file_hash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a',
},
],
};
......@@ -53,6 +53,7 @@ import * as utils from '~/diffs/store/utils';
import * as commonUtils from '~/lib/utils/common_utils';
import { mergeUrlParams } from '~/lib/utils/url_utility';
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import { diffMetadata } from '../mock_data/diff_metadata';
import createFlash from '~/flash';
jest.mock('~/flash', () => jest.fn());
......@@ -259,13 +260,19 @@ describe('DiffsStoreActions', () => {
});
describe('fetchDiffFilesMeta', () => {
it('should fetch diff meta information', done => {
const endpointMetadata = '/fetch/diffs_meta?view=inline';
const mock = new MockAdapter(axios);
const data = { diff_files: [] };
const res = { data };
mock.onGet(endpointMetadata).reply(200, res);
const endpointMetadata = '/fetch/diffs_metadata.json?view=inline';
const noFilesData = { ...diffMetadata };
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
delete noFilesData.diff_files;
mock.onGet(endpointMetadata).reply(200, diffMetadata);
});
it('should fetch diff meta information', done => {
testAction(
fetchDiffFilesMeta,
{},
......@@ -273,8 +280,8 @@ describe('DiffsStoreActions', () => {
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_LOADING, payload: false },
{ type: types.SET_MERGE_REQUEST_DIFFS, payload: [] },
{ type: types.SET_DIFF_DATA, payload: { data } },
{ type: types.SET_MERGE_REQUEST_DIFFS, payload: diffMetadata.merge_request_diffs },
{ type: types.SET_DIFF_DATA, payload: noFilesData },
],
[],
() => {
......@@ -390,13 +397,18 @@ describe('DiffsStoreActions', () => {
});
describe('fetchDiffFilesMeta', () => {
it('should fetch diff meta information', done => {
const endpointMetadata = '/fetch/diffs_meta';
const mock = new MockAdapter(axios);
const data = { diff_files: [] };
const res = { data };
mock.onGet(endpointMetadata).reply(200, res);
const endpointMetadata = '/fetch/diffs_metadata.json';
const noFilesData = { ...diffMetadata };
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
delete noFilesData.diff_files;
mock.onGet(endpointMetadata).reply(200, diffMetadata);
});
it('should fetch diff meta information', done => {
testAction(
fetchDiffFilesMeta,
{},
......@@ -404,8 +416,8 @@ describe('DiffsStoreActions', () => {
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_LOADING, payload: false },
{ type: types.SET_MERGE_REQUEST_DIFFS, payload: [] },
{ type: types.SET_DIFF_DATA, payload: { data } },
{ type: types.SET_MERGE_REQUEST_DIFFS, payload: diffMetadata.merge_request_diffs },
{ type: types.SET_DIFF_DATA, payload: noFilesData },
],
[],
() => {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment