Commit b448f031 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'ph/235711/missingBranchStateGraphql' into 'master'

Converted missing branch component to use GraphQL

See merge request gitlab-org/gitlab!48360
parents 3b2b780b 8bc05e0b
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
import { GlIcon, GlTooltipDirective } from '@gitlab/ui'; import { GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import statusIcon from '../mr_widget_status_icon.vue'; import statusIcon from '../mr_widget_status_icon.vue';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import mergeRequestQueryVariablesMixin from '../../mixins/merge_request_query_variables';
import missingBranchQuery from '../../queries/states/missing_branch.query.graphql';
export default { export default {
name: 'MRWidgetMissingBranch', name: 'MRWidgetMissingBranch',
...@@ -12,15 +15,38 @@ export default { ...@@ -12,15 +15,38 @@ export default {
GlIcon, GlIcon,
statusIcon, statusIcon,
}, },
mixins: [glFeatureFlagMixin(), mergeRequestQueryVariablesMixin],
apollo: {
state: {
query: missingBranchQuery,
skip() {
return !this.glFeatures.mergeRequestWidgetGraphql;
},
variables() {
return this.mergeRequestQueryVariables;
},
update: data => data.project.mergeRequest,
},
},
props: { props: {
mr: { mr: {
type: Object, type: Object,
required: true, required: true,
}, },
}, },
data() {
return { state: {} };
},
computed: { computed: {
sourceBranchRemoved() {
if (this.glFeatures.mergeRequestWidgetGraphql) {
return !this.state.sourceBranchExists;
}
return this.mr.sourceBranchRemoved;
},
missingBranchName() { missingBranchName() {
return this.mr.sourceBranchRemoved ? 'source' : 'target'; return this.sourceBranchRemoved ? 'source' : 'target';
}, },
missingBranchNameMessage() { missingBranchNameMessage() {
return sprintf( return sprintf(
...@@ -49,7 +75,7 @@ export default { ...@@ -49,7 +75,7 @@ export default {
<div class="media-body space-children"> <div class="media-body space-children">
<span class="bold js-branch-text"> <span class="bold js-branch-text">
<span class="capitalize"> {{ missingBranchName }} </span> <span class="capitalize" data-testid="missingBranchName"> {{ missingBranchName }} </span>
{{ s__('mrWidget|branch does not exist.') }} {{ missingBranchNameMessage }} {{ s__('mrWidget|branch does not exist.') }} {{ missingBranchNameMessage }}
<gl-icon v-gl-tooltip :title="message" :aria-label="message" name="question-o" /> <gl-icon v-gl-tooltip :title="message" :aria-label="message" name="question-o" />
</span> </span>
......
query missingBranchQuery($projectPath: ID!, $iid: String!) {
project(fullPath: $projectPath) {
mergeRequest(iid: $iid) {
sourceBranchExists
}
}
}
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import mountComponent from 'helpers/vue_mount_component_helper'; import MissingBranchComponent from '~/vue_merge_request_widget/components/states/mr_widget_missing_branch.vue';
import missingBranchComponent from '~/vue_merge_request_widget/components/states/mr_widget_missing_branch.vue';
let wrapper;
describe('MRWidgetMissingBranch', () => {
let vm; function factory(sourceBranchRemoved, mergeRequestWidgetGraphql) {
wrapper = shallowMount(MissingBranchComponent, {
beforeEach(() => { propsData: {
const Component = Vue.extend(missingBranchComponent); mr: { sourceBranchRemoved },
vm = mountComponent(Component, { mr: { sourceBranchRemoved: true } }); },
}); provide: {
glFeatures: { mergeRequestWidgetGraphql },
afterEach(() => { },
vm.$destroy();
}); });
describe('computed', () => { if (mergeRequestWidgetGraphql) {
describe('missingBranchName', () => { wrapper.setData({ state: { sourceBranchExists: !sourceBranchRemoved } });
it('should return proper branch name', () => { }
expect(vm.missingBranchName).toEqual('source');
vm.mr.sourceBranchRemoved = false; return wrapper.vm.$nextTick();
}
expect(vm.missingBranchName).toEqual('target'); describe('MRWidgetMissingBranch', () => {
}); afterEach(() => {
}); wrapper.destroy();
}); });
describe('template', () => { [true, false].forEach(mergeRequestWidgetGraphql => {
it('should have correct elements', () => { describe(`widget GraphQL feature flag is ${
const el = vm.$el; mergeRequestWidgetGraphql ? 'enabled' : 'disabled'
const content = el.textContent.replace(/\n(\s)+/g, ' ').trim(); }`, () => {
it.each`
expect(el.classList.contains('mr-widget-body')).toBeTruthy(); sourceBranchRemoved | branchName
expect(el.querySelector('button').getAttribute('disabled')).toBeTruthy(); ${true} | ${'source'}
expect(content.replace(/\s\s+/g, ' ')).toContain('source branch does not exist.'); ${false} | ${'target'}
expect(content).toContain('Please restore it or use a different source branch'); `(
'should set missing branch name as $branchName when sourceBranchRemoved is $sourceBranchRemoved',
async ({ sourceBranchRemoved, branchName }) => {
await factory(sourceBranchRemoved, mergeRequestWidgetGraphql);
expect(wrapper.find('[data-testid="missingBranchName"]').text()).toContain(branchName);
},
);
}); });
}); });
}); });
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