BigW Consortium Gitlab

Commit a4d84192 by Phil Hughes

Merge branch 'fl-mr-widget' into 'master'

Move mr widget related links into a vue file See merge request gitlab-org/gitlab-ce!16825
parents f4b91f7a 514826f5
export default { <script>
import { s__ } from '~/locale';
export default {
name: 'MRWidgetRelatedLinks', name: 'MRWidgetRelatedLinks',
props: { props: {
relatedLinks: { type: Object, required: true }, relatedLinks: {
state: { type: String, required: false }, type: Object,
required: true,
default: () => ({}),
},
state: {
type: String,
required: false,
default: '',
}, },
computed: {
hasLinks() {
const { closing, mentioned, assignToMe } = this.relatedLinks;
return closing || mentioned || assignToMe;
}, },
computed: {
closesText() { closesText() {
if (this.state === 'merged') { if (this.state === 'merged') {
return 'Closed'; return s__('mrWidget|Closed');
} }
if (this.state === 'closed') { if (this.state === 'closed') {
return 'Did not close'; return s__('mrWidget|Did not close');
} }
return 'Closes'; return s__('mrWidget|Closes');
}, },
}, },
template: ` };
<section </script>
v-if="hasLinks" <template>
class="mr-info-list mr-links"> <section class="mr-info-list mr-links">
<p v-if="relatedLinks.closing"> <p v-if="relatedLinks.closing">
{{closesText}} <span v-html="relatedLinks.closing"></span> {{ closesText }} <span v-html="relatedLinks.closing"></span>
</p> </p>
<p v-if="relatedLinks.mentioned"> <p v-if="relatedLinks.mentioned">
Mentions <span v-html="relatedLinks.mentioned"></span> {{ s__("mrWidget|Mentions") }} <span v-html="relatedLinks.mentioned"></span>
</p> </p>
<p v-if="relatedLinks.assignToMe"> <p v-if="relatedLinks.assignToMe">
<span v-html="relatedLinks.assignToMe"></span> <span v-html="relatedLinks.assignToMe"></span>
</p> </p>
</section> </section>
`, </template>
};
...@@ -15,7 +15,7 @@ export { default as WidgetHeader } from './components/mr_widget_header'; ...@@ -15,7 +15,7 @@ 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';
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.vue';
export { default as MergedState } from './components/states/mr_widget_merged.vue'; export { default as MergedState } from './components/states/mr_widget_merged.vue';
export { default as FailedToMerge } from './components/states/mr_widget_failed_to_merge.vue'; export { default as FailedToMerge } from './components/states/mr_widget_failed_to_merge.vue';
export { default as ClosedState } from './components/states/mr_widget_closed.vue'; export { default as ClosedState } from './components/states/mr_widget_closed.vue';
......
...@@ -257,7 +257,8 @@ export default { ...@@ -257,7 +257,8 @@ export default {
<mr-widget-related-links <mr-widget-related-links
v-if="shouldRenderRelatedLinks" v-if="shouldRenderRelatedLinks"
:state="mr.state" :state="mr.state"
:related-links="mr.relatedLinks" /> :related-links="mr.relatedLinks"
/>
</div> </div>
<div <div
class="mr-widget-footer" class="mr-widget-footer"
......
import Vue from 'vue'; import Vue from 'vue';
import relatedLinksComponent from '~/vue_merge_request_widget/components/mr_widget_related_links'; import relatedLinksComponent from '~/vue_merge_request_widget/components/mr_widget_related_links.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
const createComponent = (data) => {
const Component = Vue.extend(relatedLinksComponent);
return new Component({
el: document.createElement('div'),
propsData: data,
});
};
describe('MRWidgetRelatedLinks', () => { describe('MRWidgetRelatedLinks', () => {
describe('props', () => { let vm;
it('should have props', () => {
const { relatedLinks } = relatedLinksComponent.props;
expect(relatedLinks).toBeDefined(); const createComponent = (data) => {
expect(relatedLinks.type instanceof Object).toBeTruthy(); const Component = Vue.extend(relatedLinksComponent);
expect(relatedLinks.required).toBeTruthy();
});
});
describe('computed', () => { return mountComponent(Component, data);
const data = {
relatedLinks: {
closing: '/foo',
mentioned: '/foo',
assignToMe: '/foo',
},
}; };
describe('hasLinks', () => { afterEach(() => {
it('should return correct value when we have links reference', () => { vm.$destroy();
const vm = createComponent(data);
expect(vm.hasLinks).toBeTruthy();
vm.relatedLinks.closing = null;
expect(vm.hasLinks).toBeTruthy();
vm.relatedLinks.mentioned = null;
expect(vm.hasLinks).toBeTruthy();
vm.relatedLinks.assignToMe = null;
expect(vm.hasLinks).toBeFalsy();
});
}); });
describe('computed', () => {
describe('closesText', () => { describe('closesText', () => {
it('returns correct text for open merge request', () => { it('returns Closes text for open merge request', () => {
data.state = 'open'; vm = createComponent({ state: 'open', relatedLinks: {} });
const vm = createComponent(data);
expect(vm.closesText).toEqual('Closes'); expect(vm.closesText).toEqual('Closes');
}); });
it('returns correct text for closed merge request', () => { it('returns correct text for closed merge request', () => {
data.state = 'closed'; vm = createComponent({ state: 'closed', relatedLinks: {} });
const vm = createComponent(data);
expect(vm.closesText).toEqual('Did not close'); expect(vm.closesText).toEqual('Did not close');
}); });
it('returns correct tense for merged request', () => { it('returns correct tense for merged request', () => {
data.state = 'merged'; vm = createComponent({ state: 'merged', relatedLinks: {} });
const vm = createComponent(data);
expect(vm.closesText).toEqual('Closed'); expect(vm.closesText).toEqual('Closed');
}); });
}); });
}); });
describe('template', () => {
it('should have only have closing issues text', () => { it('should have only have closing issues text', () => {
const vm = createComponent({ vm = createComponent({
relatedLinks: { relatedLinks: {
closing: '<a href="#">#23</a> and <a>#42</a>', closing: '<a href="#">#23</a> and <a>#42</a>',
}, },
...@@ -81,7 +47,7 @@ describe('MRWidgetRelatedLinks', () => { ...@@ -81,7 +47,7 @@ describe('MRWidgetRelatedLinks', () => {
}); });
it('should have only have mentioned issues text', () => { it('should have only have mentioned issues text', () => {
const vm = createComponent({ vm = createComponent({
relatedLinks: { relatedLinks: {
mentioned: '<a href="#">#7</a>', mentioned: '<a href="#">#7</a>',
}, },
...@@ -92,7 +58,7 @@ describe('MRWidgetRelatedLinks', () => { ...@@ -92,7 +58,7 @@ describe('MRWidgetRelatedLinks', () => {
}); });
it('should have closing and mentioned issues at the same time', () => { it('should have closing and mentioned issues at the same time', () => {
const vm = createComponent({ vm = createComponent({
relatedLinks: { relatedLinks: {
closing: '<a href="#">#7</a>', closing: '<a href="#">#7</a>',
mentioned: '<a href="#">#23</a> and <a>#42</a>', mentioned: '<a href="#">#23</a> and <a>#42</a>',
...@@ -105,7 +71,7 @@ describe('MRWidgetRelatedLinks', () => { ...@@ -105,7 +71,7 @@ describe('MRWidgetRelatedLinks', () => {
}); });
it('should have assing issues link', () => { it('should have assing issues link', () => {
const vm = createComponent({ vm = createComponent({
relatedLinks: { relatedLinks: {
assignToMe: '<a href="#">Assign yourself to these issues</a>', assignToMe: '<a href="#">Assign yourself to these issues</a>',
}, },
...@@ -113,5 +79,4 @@ describe('MRWidgetRelatedLinks', () => { ...@@ -113,5 +79,4 @@ describe('MRWidgetRelatedLinks', () => {
expect(vm.$el.innerText).toContain('Assign yourself to these issues'); expect(vm.$el.innerText).toContain('Assign yourself to these issues');
}); });
});
}); });
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