Commit f4a1eaba authored by Tomas Vik's avatar Tomas Vik Committed by Andrew Fontaine

Update ShaMismatch component to match design

parent e7762cd5
...@@ -188,13 +188,6 @@ export default { ...@@ -188,13 +188,6 @@ export default {
return this.mr.preferredAutoMergeStrategy; return this.mr.preferredAutoMergeStrategy;
}, },
isSHAMismatch() {
if (this.glFeatures.mergeRequestWidgetGraphql) {
return this.mr.sha !== this.state.diffHeadSha;
}
return this.mr.isSHAMismatch;
},
squashIsSelected() { squashIsSelected() {
if (this.glFeatures.mergeRequestWidgetGraphql) { if (this.glFeatures.mergeRequestWidgetGraphql) {
return this.isSquashReadOnly ? this.state.squashOnMerge : this.state.squash; return this.isSquashReadOnly ? this.state.squashOnMerge : this.state.squash;
...@@ -573,21 +566,6 @@ export default { ...@@ -573,21 +566,6 @@ export default {
</div> </div>
</template> </template>
</div> </div>
<div v-if="isSHAMismatch" class="d-flex align-items-center mt-2 js-sha-mismatch">
<gl-icon name="warning-solid" class="text-warning mr-1" />
<span class="text-warning">
<gl-sprintf
:message="
__('New changes were added. %{linkStart}Reload the page to review them%{linkEnd}')
"
>
<template #link="{ content }">
<gl-link :href="mr.mergeRequestDiffsPath">{{ content }}</gl-link>
</template>
</gl-sprintf>
</span>
</div>
<div <div
v-if="showDangerMessageForMergeTrain" v-if="showDangerMessageForMergeTrain"
class="gl-mt-5 gl-text-gray-500" class="gl-mt-5 gl-text-gray-500"
......
<script> <script>
import { GlButton } from '@gitlab/ui';
import { I18N_SHA_MISMATCH } from '../../i18n';
import statusIcon from '../mr_widget_status_icon.vue'; import statusIcon from '../mr_widget_status_icon.vue';
export default { export default {
name: 'ShaMismatch', name: 'ShaMismatch',
components: { components: {
statusIcon, statusIcon,
GlButton,
},
i18n: {
I18N_SHA_MISMATCH,
},
props: {
mr: {
type: Object,
required: true,
},
}, },
}; };
</script> </script>
<template> <template>
<div class="mr-widget-body media"> <div class="mr-widget-body media">
<status-icon :show-disabled-button="true" status="warning" /> <status-icon :show-disabled-button="false" status="warning" />
<div class="media-body space-children"> <div class="media-body">
<span class="bold" data-qa-selector="head_mismatch_content"> <span class="gl-font-weight-bold" data-qa-selector="head_mismatch_content">
{{ {{ $options.i18n.I18N_SHA_MISMATCH.warningMessage }}
s__(`mrWidget|The source branch HEAD has recently changed.
Please reload the page and review the changes before merging`)
}}
</span> </span>
<gl-button
class="gl-ml-3"
data-testid="action-button"
size="small"
category="primary"
variant="confirm"
:href="mr.mergeRequestDiffsPath"
>{{ $options.i18n.I18N_SHA_MISMATCH.actionButtonLabel }}</gl-button
>
</div> </div>
</div> </div>
</template> </template>
...@@ -5,3 +5,8 @@ export const SQUASH_BEFORE_MERGE = { ...@@ -5,3 +5,8 @@ export const SQUASH_BEFORE_MERGE = {
checkboxLabel: __('Squash commits'), checkboxLabel: __('Squash commits'),
helpLabel: __('What is squashing?'), helpLabel: __('What is squashing?'),
}; };
export const I18N_SHA_MISMATCH = {
warningMessage: __('Merge blocked: new changes were just added.'),
actionButtonLabel: __('Review changes'),
};
...@@ -38,6 +38,7 @@ import RebaseState from './components/states/mr_widget_rebase.vue'; ...@@ -38,6 +38,7 @@ import RebaseState from './components/states/mr_widget_rebase.vue';
import NothingToMergeState from './components/states/nothing_to_merge.vue'; import NothingToMergeState from './components/states/nothing_to_merge.vue';
import PipelineFailedState from './components/states/pipeline_failed.vue'; import PipelineFailedState from './components/states/pipeline_failed.vue';
import ReadyToMergeState from './components/states/ready_to_merge.vue'; import ReadyToMergeState from './components/states/ready_to_merge.vue';
import ShaMismatch from './components/states/sha_mismatch.vue';
import UnresolvedDiscussionsState from './components/states/unresolved_discussions.vue'; import UnresolvedDiscussionsState from './components/states/unresolved_discussions.vue';
import WorkInProgressState from './components/states/work_in_progress.vue'; import WorkInProgressState from './components/states/work_in_progress.vue';
// import ExtensionsContainer from './components/extensions/container'; // import ExtensionsContainer from './components/extensions/container';
...@@ -72,7 +73,7 @@ export default { ...@@ -72,7 +73,7 @@ export default {
'mr-widget-not-allowed': NotAllowedState, 'mr-widget-not-allowed': NotAllowedState,
'mr-widget-missing-branch': MissingBranchState, 'mr-widget-missing-branch': MissingBranchState,
'mr-widget-ready-to-merge': ReadyToMergeState, 'mr-widget-ready-to-merge': ReadyToMergeState,
'sha-mismatch': ReadyToMergeState, 'sha-mismatch': ShaMismatch,
'mr-widget-checking': CheckingState, 'mr-widget-checking': CheckingState,
'mr-widget-unresolved-discussions': UnresolvedDiscussionsState, 'mr-widget-unresolved-discussions': UnresolvedDiscussionsState,
'mr-widget-pipeline-blocked': PipelineBlockedState, 'mr-widget-pipeline-blocked': PipelineBlockedState,
......
...@@ -20916,6 +20916,9 @@ msgstr "" ...@@ -20916,6 +20916,9 @@ msgstr ""
msgid "Merge automatically (%{strategy})" msgid "Merge automatically (%{strategy})"
msgstr "" msgstr ""
msgid "Merge blocked: new changes were just added."
msgstr ""
msgid "Merge blocked: the source branch must be rebased onto the target branch." msgid "Merge blocked: the source branch must be rebased onto the target branch."
msgstr "" msgstr ""
...@@ -22334,9 +22337,6 @@ msgstr "" ...@@ -22334,9 +22337,6 @@ msgstr ""
msgid "New branch unavailable" msgid "New branch unavailable"
msgstr "" msgstr ""
msgid "New changes were added. %{linkStart}Reload the page to review them%{linkEnd}"
msgstr ""
msgid "New confidential epic title " msgid "New confidential epic title "
msgstr "" msgstr ""
...@@ -28560,6 +28560,9 @@ msgstr "" ...@@ -28560,6 +28560,9 @@ msgstr ""
msgid "Review App|View latest app" msgid "Review App|View latest app"
msgstr "" msgstr ""
msgid "Review changes"
msgstr ""
msgid "Review requested from %{name}" msgid "Review requested from %{name}"
msgstr "" msgstr ""
...@@ -39854,9 +39857,6 @@ msgstr "" ...@@ -39854,9 +39857,6 @@ msgstr ""
msgid "mrWidget|The pipeline for this merge request did not complete. Push a new commit to fix the failure, or check the %{linkStart}troubleshooting documentation%{linkEnd} to see other possible actions." msgid "mrWidget|The pipeline for this merge request did not complete. Push a new commit to fix the failure, or check the %{linkStart}troubleshooting documentation%{linkEnd} to see other possible actions."
msgstr "" msgstr ""
msgid "mrWidget|The source branch HEAD has recently changed. Please reload the page and review the changes before merging"
msgstr ""
msgid "mrWidget|The source branch has been deleted" msgid "mrWidget|The source branch has been deleted"
msgstr "" msgstr ""
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ReadyToMerge with a mismatched SHA warns the user to refresh to review 1`] = `"<gl-sprintf-stub message=\\"New changes were added. %{linkStart}Reload the page to review them%{linkEnd}\\"></gl-sprintf-stub>"`;
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue'; import Vue from 'vue';
import simplePoll from '~/lib/utils/simple_poll'; import simplePoll from '~/lib/utils/simple_poll';
...@@ -782,26 +781,4 @@ describe('ReadyToMerge', () => { ...@@ -782,26 +781,4 @@ describe('ReadyToMerge', () => {
}); });
}); });
}); });
describe('with a mismatched SHA', () => {
const findMismatchShaBlock = () => wrapper.find('.js-sha-mismatch');
const findMismatchShaTextBlock = () => findMismatchShaBlock().find(GlSprintf);
beforeEach(() => {
createComponent({
mr: {
isSHAMismatch: true,
mergeRequestDiffsPath: '/merge_requests/1/diffs',
},
});
});
it('displays a warning message', () => {
expect(findMismatchShaBlock().exists()).toBe(true);
});
it('warns the user to refresh to review', () => {
expect(findMismatchShaTextBlock().element.outerHTML).toMatchSnapshot();
});
});
}); });
import Vue from 'vue'; import { mount } from '@vue/test-utils';
import { removeBreakLine } from 'helpers/text_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import ShaMismatch from '~/vue_merge_request_widget/components/states/sha_mismatch.vue'; import ShaMismatch from '~/vue_merge_request_widget/components/states/sha_mismatch.vue';
import { I18N_SHA_MISMATCH } from '~/vue_merge_request_widget/i18n';
function createComponent({ path = '' } = {}) {
return mount(ShaMismatch, {
propsData: {
mr: {
mergeRequestDiffsPath: path,
},
},
});
}
describe('ShaMismatch', () => { describe('ShaMismatch', () => {
let vm; let wrapper;
const findActionButton = () => wrapper.find('[data-testid="action-button"]');
beforeEach(() => { beforeEach(() => {
const Component = Vue.extend(ShaMismatch); wrapper = createComponent();
vm = mountComponent(Component);
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
});
it('should render warning message', () => {
expect(wrapper.element.innerText).toContain(I18N_SHA_MISMATCH.warningMessage);
}); });
it('should render information message', () => { it('action button should have correct label', () => {
expect(vm.$el.querySelector('button').disabled).toEqual(true); expect(findActionButton().text()).toBe(I18N_SHA_MISMATCH.actionButtonLabel);
});
it('action button should link to the diff path', () => {
const DIFF_PATH = '/gitlab-org/gitlab-test/-/merge_requests/6/diffs';
wrapper = createComponent({ path: DIFF_PATH });
expect(removeBreakLine(vm.$el.textContent).trim()).toContain( expect(findActionButton().attributes('href')).toBe(DIFF_PATH);
'The source branch HEAD has recently changed. Please reload the page and review the changes before merging',
);
}); });
}); });
...@@ -80,14 +80,15 @@ describe('MrWidgetOptions', () => { ...@@ -80,14 +80,15 @@ describe('MrWidgetOptions', () => {
describe('computed', () => { describe('computed', () => {
describe('componentName', () => { describe('componentName', () => {
it('should return merged component', () => { it.each`
expect(wrapper.vm.componentName).toEqual('mr-widget-merged'); state | componentName
}); ${'merged'} | ${'mr-widget-merged'}
${'conflicts'} | ${'mr-widget-conflicts'}
it('should return conflicts component', () => { ${'shaMismatch'} | ${'sha-mismatch'}
wrapper.vm.mr.state = 'conflicts'; `('should translate $state into $componentName', ({ state, componentName }) => {
wrapper.vm.mr.state = state;
expect(wrapper.vm.componentName).toEqual('mr-widget-conflicts');
expect(wrapper.vm.componentName).toEqual(componentName);
}); });
}); });
......
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