Commit 5c3a7184 authored by Pedro Moreira da Silva's avatar Pedro Moreira da Silva Committed by Martin Wortschack

Migrate MR rebase button to GitLab UI

parent 4b56e4cf
<script> <script>
/* eslint-disable vue/no-v-html */ /* eslint-disable vue/no-v-html */
import { GlLoadingIcon } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { escape } from 'lodash'; import { escape } from 'lodash';
import simplePoll from '../../../lib/utils/simple_poll'; import simplePoll from '../../../lib/utils/simple_poll';
import eventHub from '../../event_hub'; import eventHub from '../../event_hub';
...@@ -12,7 +12,7 @@ export default { ...@@ -12,7 +12,7 @@ export default {
name: 'MRWidgetRebase', name: 'MRWidgetRebase',
components: { components: {
statusIcon, statusIcon,
GlLoadingIcon, GlButton,
}, },
props: { props: {
mr: { mr: {
...@@ -109,29 +109,29 @@ export default { ...@@ -109,29 +109,29 @@ export default {
<div class="rebase-state-find-class-convention media media-body space-children"> <div class="rebase-state-find-class-convention media media-body space-children">
<template v-if="mr.rebaseInProgress || isMakingRequest"> <template v-if="mr.rebaseInProgress || isMakingRequest">
<span class="bold">{{ __('Rebase in progress') }}</span> <span class="bold" data-testid="rebase-message">{{ __('Rebase in progress') }}</span>
</template> </template>
<template v-if="!mr.rebaseInProgress && !mr.canPushToSourceBranch"> <template v-if="!mr.rebaseInProgress && !mr.canPushToSourceBranch">
<span class="bold" v-html="fastForwardMergeText"></span> <span class="bold" data-testid="rebase-message" v-html="fastForwardMergeText"></span>
</template> </template>
<template v-if="!mr.rebaseInProgress && mr.canPushToSourceBranch && !isMakingRequest"> <template v-if="!mr.rebaseInProgress && mr.canPushToSourceBranch && !isMakingRequest">
<div <div
class="accept-merge-holder clearfix js-toggle-container accept-action media space-children" class="accept-merge-holder clearfix js-toggle-container accept-action media space-children"
> >
<button <gl-button
:disabled="isMakingRequest" :loading="isMakingRequest"
type="button" variant="success"
class="btn btn-sm btn-reopen btn-success qa-mr-rebase-button" class="qa-mr-rebase-button"
@click="rebase" @click="rebase"
> >
<gl-loading-icon v-if="isMakingRequest" />{{ __('Rebase') }} {{ __('Rebase') }}
</button> </gl-button>
<span v-if="!rebasingError" class="bold">{{ <span v-if="!rebasingError" class="bold" data-testid="rebase-message">{{
__( __(
'Fast-forward merge is not possible. Rebase the source branch onto the target branch.', 'Fast-forward merge is not possible. Rebase the source branch onto the target branch.',
) )
}}</span> }}</span>
<span v-else class="bold danger">{{ rebasingError }}</span> <span v-else class="bold danger" data-testid="rebase-message">{{ rebasingError }}</span>
</div> </div>
</template> </template>
</div> </div>
......
...@@ -6,6 +6,10 @@ import component from '~/vue_merge_request_widget/components/states/mr_widget_re ...@@ -6,6 +6,10 @@ import component from '~/vue_merge_request_widget/components/states/mr_widget_re
describe('Merge request widget rebase component', () => { describe('Merge request widget rebase component', () => {
let Component; let Component;
let vm; let vm;
const findRebaseMessageEl = () => vm.$el.querySelector('[data-testid="rebase-message"]');
const findRebaseMessageElText = () => findRebaseMessageEl().textContent.trim();
beforeEach(() => { beforeEach(() => {
Component = Vue.extend(component); Component = Vue.extend(component);
}); });
...@@ -21,9 +25,7 @@ describe('Merge request widget rebase component', () => { ...@@ -21,9 +25,7 @@ describe('Merge request widget rebase component', () => {
service: {}, service: {},
}); });
expect( expect(findRebaseMessageElText()).toContain('Rebase in progress');
vm.$el.querySelector('.rebase-state-find-class-convention span').textContent.trim(),
).toContain('Rebase in progress');
}); });
}); });
...@@ -39,9 +41,7 @@ describe('Merge request widget rebase component', () => { ...@@ -39,9 +41,7 @@ describe('Merge request widget rebase component', () => {
}); });
it('it should render rebase button and warning message', () => { it('it should render rebase button and warning message', () => {
const text = vm.$el const text = findRebaseMessageElText();
.querySelector('.rebase-state-find-class-convention span')
.textContent.trim();
expect(text).toContain('Fast-forward merge is not possible.'); expect(text).toContain('Fast-forward merge is not possible.');
expect(text.replace(/\s\s+/g, ' ')).toContain( expect(text.replace(/\s\s+/g, ' ')).toContain(
...@@ -53,9 +53,7 @@ describe('Merge request widget rebase component', () => { ...@@ -53,9 +53,7 @@ describe('Merge request widget rebase component', () => {
vm.rebasingError = 'Something went wrong!'; vm.rebasingError = 'Something went wrong!';
Vue.nextTick(() => { Vue.nextTick(() => {
expect( expect(findRebaseMessageElText()).toContain('Something went wrong!');
vm.$el.querySelector('.rebase-state-find-class-convention span').textContent.trim(),
).toContain('Something went wrong!');
done(); done();
}); });
}); });
...@@ -72,9 +70,7 @@ describe('Merge request widget rebase component', () => { ...@@ -72,9 +70,7 @@ describe('Merge request widget rebase component', () => {
service: {}, service: {},
}); });
const text = vm.$el const text = findRebaseMessageElText();
.querySelector('.rebase-state-find-class-convention span')
.textContent.trim();
expect(text).toContain('Fast-forward merge is not possible.'); expect(text).toContain('Fast-forward merge is not possible.');
expect(text).toContain('Rebase the source branch onto'); expect(text).toContain('Rebase the source branch onto');
...@@ -93,7 +89,7 @@ describe('Merge request widget rebase component', () => { ...@@ -93,7 +89,7 @@ describe('Merge request widget rebase component', () => {
service: {}, service: {},
}); });
const elem = vm.$el.querySelector('.rebase-state-find-class-convention span'); const elem = findRebaseMessageEl();
expect(elem.innerHTML).toContain( expect(elem.innerHTML).toContain(
`Fast-forward merge is not possible. Rebase the source branch onto <span class="label-branch">${targetBranch}</span> to allow this merge request to be merged.`, `Fast-forward merge is not possible. Rebase the source branch onto <span class="label-branch">${targetBranch}</span> to allow this merge request to be merged.`,
......
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