Commit ac242673 authored by Thomas Randolph's avatar Thomas Randolph Committed by Olena Horal-Koretska

Extract Merge Request Conflicts warning to component

parent 46d72293
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import { GlLoadingIcon, GlButton, GlAlert, GlPagination, GlSprintf } from '@gitlab/ui'; import { GlLoadingIcon, GlPagination, GlSprintf } from '@gitlab/ui';
import Mousetrap from 'mousetrap'; import Mousetrap from 'mousetrap';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { getParameterByName, parseBoolean } from '~/lib/utils/common_utils'; import { getParameterByName, parseBoolean } from '~/lib/utils/common_utils';
...@@ -13,9 +13,12 @@ import eventHub from '../../notes/event_hub'; ...@@ -13,9 +13,12 @@ import eventHub from '../../notes/event_hub';
import CompareVersions from './compare_versions.vue'; import CompareVersions from './compare_versions.vue';
import DiffFile from './diff_file.vue'; import DiffFile from './diff_file.vue';
import NoChanges from './no_changes.vue'; import NoChanges from './no_changes.vue';
import HiddenFilesWarning from './hidden_files_warning.vue';
import CommitWidget from './commit_widget.vue'; import CommitWidget from './commit_widget.vue';
import TreeList from './tree_list.vue'; import TreeList from './tree_list.vue';
import HiddenFilesWarning from './hidden_files_warning.vue';
import MergeConflictWarning from './merge_conflict_warning.vue';
import { import {
TREE_LIST_WIDTH_STORAGE_KEY, TREE_LIST_WIDTH_STORAGE_KEY,
INITIAL_TREE_WIDTH, INITIAL_TREE_WIDTH,
...@@ -33,13 +36,12 @@ export default { ...@@ -33,13 +36,12 @@ export default {
DiffFile, DiffFile,
NoChanges, NoChanges,
HiddenFilesWarning, HiddenFilesWarning,
MergeConflictWarning,
CommitWidget, CommitWidget,
TreeList, TreeList,
GlLoadingIcon, GlLoadingIcon,
PanelResizer, PanelResizer,
GlPagination, GlPagination,
GlButton,
GlAlert,
GlSprintf, GlSprintf,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
...@@ -422,49 +424,12 @@ export default { ...@@ -422,49 +424,12 @@ export default {
:plain-diff-path="plainDiffPath" :plain-diff-path="plainDiffPath"
:email-patch-path="emailPatchPath" :email-patch-path="emailPatchPath"
/> />
<merge-conflict-warning
<div
v-if="isDiffHead && hasConflicts" v-if="isDiffHead && hasConflicts"
:class="{ :limited="isLimitedContainer"
[CENTERED_LIMITED_CONTAINER_CLASSES]: isLimitedContainer, :resolution-path="conflictResolutionPath"
}" :mergeable="canMerge"
> />
<gl-alert
:dismissible="false"
:title="__('There are merge conflicts')"
variant="warning"
class="w-100 mb-3"
>
<p class="mb-1">
{{ __('The comparison view may be inaccurate due to merge conflicts.') }}
</p>
<p class="mb-0">
{{
__(
'Resolve these conflicts or ask someone with write access to this repository to merge it locally.',
)
}}
</p>
<template #actions>
<gl-button
v-if="conflictResolutionPath"
:href="conflictResolutionPath"
variant="info"
class="mr-3 gl-alert-action"
>
{{ __('Resolve conflicts') }}
</gl-button>
<gl-button
v-if="canMerge"
class="gl-alert-action"
data-toggle="modal"
data-target="#modal_merge_info"
>
{{ __('Merge locally') }}
</gl-button>
</template>
</gl-alert>
</div>
<div <div
:data-can-create-note="getNoteableData.current_user.can_create_note" :data-can-create-note="getNoteableData.current_user.can_create_note"
......
<script>
import { GlButton, GlAlert } from '@gitlab/ui';
import { CENTERED_LIMITED_CONTAINER_CLASSES } from '../constants';
export default {
components: {
GlAlert,
GlButton,
},
props: {
limited: {
type: Boolean,
required: true,
},
mergeable: {
type: Boolean,
required: true,
},
resolutionPath: {
type: String,
required: true,
},
},
computed: {
containerClasses() {
return {
[CENTERED_LIMITED_CONTAINER_CLASSES]: this.limited,
};
},
},
};
</script>
<template>
<div :class="containerClasses">
<gl-alert
:dismissible="false"
:title="__('There are merge conflicts')"
variant="warning"
class="gl-mb-5"
>
<p class="gl-mb-2">
{{ __('The comparison view may be inaccurate due to merge conflicts.') }}
</p>
<p class="gl-mb-0">
{{
__(
'Resolve these conflicts or ask someone with write access to this repository to merge it locally.',
)
}}
</p>
<template #actions>
<gl-button
v-if="resolutionPath"
:href="resolutionPath"
variant="info"
class="gl-mr-5 gl-alert-action"
>
{{ __('Resolve conflicts') }}
</gl-button>
<gl-button
v-if="mergeable"
class="gl-alert-action"
data-toggle="modal"
data-target="#modal_merge_info"
>
{{ __('Merge locally') }}
</gl-button>
</template>
</gl-alert>
</div>
</template>
import { shallowMount, mount } from '@vue/test-utils';
import MergeConflictWarning from '~/diffs/components/merge_conflict_warning.vue';
import { CENTERED_LIMITED_CONTAINER_CLASSES } from '~/diffs/constants';
const propsData = {
limited: true,
mergeable: true,
resolutionPath: 'a-path',
};
const limitedClasses = CENTERED_LIMITED_CONTAINER_CLASSES.split(' ');
function findResolveButton(wrapper) {
return wrapper.find('.gl-alert-actions a.gl-button:first-child');
}
function findLocalMergeButton(wrapper) {
return wrapper.find('.gl-alert-actions button.gl-button:last-child');
}
describe('MergeConflictWarning', () => {
let wrapper;
const createComponent = (props = {}, { full } = { full: false }) => {
const mounter = full ? mount : shallowMount;
wrapper = mounter(MergeConflictWarning, {
propsData: { ...propsData, ...props },
});
};
afterEach(() => {
wrapper.destroy();
});
it.each`
limited | containerClasses
${true} | ${limitedClasses}
${false} | ${[]}
`(
'has the correct container classes when limited is $limited',
({ limited, containerClasses }) => {
createComponent({ limited });
expect(wrapper.classes()).toEqual(containerClasses);
},
);
it.each`
present | resolutionPath
${false} | ${''}
${true} | ${'some-path'}
`(
'toggles the resolve conflicts button based on the provided resolutionPath "$resolutionPath"',
({ present, resolutionPath }) => {
createComponent({ resolutionPath }, { full: true });
const resolveButton = findResolveButton(wrapper);
expect(resolveButton.exists()).toBe(present);
if (present) {
expect(resolveButton.attributes('href')).toBe(resolutionPath);
}
},
);
it.each`
present | mergeable
${false} | ${false}
${true} | ${true}
`(
'toggles the local merge button based on the provided mergeable property "$mergable"',
({ present, mergeable }) => {
createComponent({ mergeable }, { full: true });
const localMerge = findLocalMergeButton(wrapper);
expect(localMerge.exists()).toBe(present);
},
);
});
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