Commit 1533cf10 authored by Filipa Lacerda's avatar Filipa Lacerda

Moves merge help into a vue component

parent bebb9c0c
export default {
name: 'MRWidgetMergeHelp',
props: {
missingBranch: { type: String, required: false, default: '' },
},
template: `
<section class="mr-widget-help">
<template
v-if="missingBranch">
If the {{missingBranch}} branch exists in your local repository, you
</template>
<template v-else>
You
</template>
can merge this merge request manually using the
<a
data-toggle="modal"
href="#modal_merge_info">
command line
</a>
</section>
`,
};
<script>
import { sprintf, s__ } from '~/locale';
export default {
name: 'MRWidgetMergeHelp',
props: {
missingBranch: {
type: String,
required: false,
default: ''
},
},
computed: {
missingBranchInfo() {
return sprintf(
s__('mrWidget|If the %{branch} branch exists in your local repository, you can merge this merge request manually using the'),
{ branch: this.missingBranch }
);
},
},
};
</script>
<template>
<section class="mr-widget-help">
<template v-if="missingBranch">
{{ missingBranchInfo }}
</template>
<template v-else>
{{ s__("mrWidget|You can merge this merge request manually using the") }}
</template>
<a
role="button"
data-toggle="modal"
href="#modal_merge_info">
{{ s__("mrWidget|command line") }}
</a>
</section>
</template>
import statusIcon from '../mr_widget_status_icon.vue'; import statusIcon from '../mr_widget_status_icon.vue';
import tooltip from '../../../vue_shared/directives/tooltip'; import tooltip from '../../../vue_shared/directives/tooltip';
import mrWidgetMergeHelp from '../../components/mr_widget_merge_help'; import mrWidgetMergeHelp from '../../components/mr_widget_merge_help.vue';
export default { export default {
name: 'MRWidgetMissingBranch', name: 'MRWidgetMissingBranch',
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
export { default as Vue } from 'vue'; export { default as Vue } from 'vue';
export { default as SmartInterval } from '~/smart_interval'; export { default as SmartInterval } from '~/smart_interval';
export { default as WidgetHeader } from './components/mr_widget_header'; export { default as WidgetHeader } from './components/mr_widget_header';
export { default as WidgetMergeHelp } from './components/mr_widget_merge_help'; export { default as WidgetMergeHelp } from './components/mr_widget_merge_help.vue';
export { default as WidgetPipeline } from './components/mr_widget_pipeline.vue'; export { default as WidgetPipeline } from './components/mr_widget_pipeline.vue';
export { default as WidgetDeployment } from './components/mr_widget_deployment'; export { default as WidgetDeployment } from './components/mr_widget_deployment';
export { default as WidgetRelatedLinks } from './components/mr_widget_related_links'; export { default as WidgetRelatedLinks } from './components/mr_widget_related_links';
......
import Vue from 'vue'; import Vue from 'vue';
import mergeHelpComponent from '~/vue_merge_request_widget/components/mr_widget_merge_help'; import mergeHelpComponent from '~/vue_merge_request_widget/components/mr_widget_merge_help.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
const props = {
missingBranch: 'this-is-not-the-branch-you-are-looking-for',
};
const text = `If the ${props.missingBranch} branch exists in your local repository`;
const createComponent = () => { const text = `If the ${props.missingBranch} branch exists in your local repository`;
const Component = Vue.extend(mergeHelpComponent);
return new Component({
el: document.createElement('div'),
propsData: props,
});
};
describe('MRWidgetMergeHelp', () => { describe('MRWidgetMergeHelp', () => {
describe('props', () => { let vm;
it('should have props', () => { let Component;
const { missingBranch } = mergeHelpComponent.props;
const MissingBranchTypeClass = missingBranch.type; beforeEach(() => {
Component = Vue.extend(mergeHelpComponent);
expect(new MissingBranchTypeClass() instanceof String).toBeTruthy();
expect(missingBranch.required).toBeFalsy();
expect(missingBranch.default).toEqual('');
});
}); });
describe('template', () => { afterEach(() => {
let vm; vm.$destroy();
let el; });
fdescribe('with missing branch', () => {
beforeEach(() => { beforeEach(() => {
vm = createComponent(); vm = mountComponent(Component, {
el = vm.$el; missingBranch: 'this-is-not-the-branch-you-are-looking-for',
});
}); });
it('should have the correct elements', () => { it('renders missing branch information', () => {
expect(el.classList.contains('mr-widget-help')).toBeTruthy(); console.log('', vm.$el);
expect(el.textContent).toContain(text);
}); });
});
it('should not show missing branch name if missingBranch props is not provided', (done) => { describe('without missing branch', () => {
vm.missingBranch = null; beforeEach(() => {
Vue.nextTick(() => { vm = mountComponent(Component);
expect(el.textContent).not.toContain(text);
done();
});
}); });
}); });
}); });
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