Commit 1fbed6dc authored by Paul Slaughter's avatar Paul Slaughter

Add MR to Web IDE bottom status bar

- This is to prepare for removing the MR sidebar
  tab
parent ad890526
......@@ -2,6 +2,7 @@
/* eslint-disable @gitlab/vue-i18n/no-bare-strings */
import { mapActions, mapState, mapGetters } from 'vuex';
import IdeStatusList from 'ee_else_ce/ide/components/ide_status_list.vue';
import IdeStatusMr from './ide_status_mr.vue';
import icon from '~/vue_shared/components/icon.vue';
import tooltip from '~/vue_shared/directives/tooltip';
import timeAgoMixin from '~/vue_shared/mixins/timeago';
......@@ -15,6 +16,7 @@ export default {
userAvatarImage,
CiIcon,
IdeStatusList,
IdeStatusMr,
},
directives: {
tooltip,
......@@ -27,7 +29,7 @@ export default {
},
computed: {
...mapState(['currentBranchId', 'currentProjectId']),
...mapGetters(['currentProject', 'lastCommit']),
...mapGetters(['currentProject', 'lastCommit', 'currentMergeRequest']),
...mapState('pipelines', ['latestPipeline']),
},
watch: {
......@@ -121,6 +123,12 @@ export default {
>{{ lastCommitFormattedAge }}</time
>
</div>
<ide-status-mr
v-if="currentMergeRequest"
class="mx-3"
:url="currentMergeRequest.web_url"
:text="currentMergeRequest.references.short"
/>
<ide-status-list class="ml-auto" />
</footer>
</template>
<script>
import { GlIcon, GlLink } from '@gitlab/ui';
export default {
components: {
GlIcon,
GlLink,
},
props: {
text: {
type: String,
required: true,
},
url: {
type: String,
required: true,
},
},
};
</script>
<template>
<div class="d-flex-center flex-nowrap text-nowrap js-ide-status-mr">
<gl-icon name="merge-request" />
<span class="ml-1 d-none d-sm-block">{{ s__('WebIDE|Merge request') }}</span>
<gl-link class="ml-1" :href="url">{{ text }}</gl-link>
</div>
</template>
......@@ -21405,6 +21405,9 @@ msgstr ""
msgid "Web terminal"
msgstr ""
msgid "WebIDE|Merge request"
msgstr ""
msgid "Webhooks"
msgstr ""
......
import { shallowMount } from '@vue/test-utils';
import { GlIcon, GlLink } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants';
import IdeStatusMr from '~/ide/components/ide_status_mr.vue';
const TEST_TEXT = '!9001';
const TEST_URL = `${TEST_HOST}merge-requests/9001`;
describe('ide/components/ide_status_mr', () => {
let wrapper;
const createComponent = props => {
wrapper = shallowMount(IdeStatusMr, {
propsData: props,
});
};
const findIcon = () => wrapper.find(GlIcon);
const findLink = () => wrapper.find(GlLink);
afterEach(() => {
wrapper.destroy();
});
describe('when mounted', () => {
beforeEach(() => {
createComponent({
text: TEST_TEXT,
url: TEST_URL,
});
});
it('renders icon', () => {
const icon = findIcon();
expect(icon.exists()).toBe(true);
expect(icon.props()).toEqual(
expect.objectContaining({
name: 'merge-request',
}),
);
});
it('renders link', () => {
const link = findLink();
expect(link.exists()).toBe(true);
expect(link.attributes()).toEqual(
expect.objectContaining({
href: TEST_URL,
}),
);
expect(link.text()).toEqual(TEST_TEXT);
});
it('renders text', () => {
expect(wrapper.text()).toBe(`Merge request ${TEST_TEXT}`);
});
});
});
import Vue from 'vue';
import _ from 'lodash';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import store from '~/ide/stores';
import ideStatusBar from '~/ide/components/ide_status_bar.vue';
import { TEST_HOST } from 'spec/test_constants';
import { createStore } from '~/ide/stores';
import IdeStatusBar from '~/ide/components/ide_status_bar.vue';
import { rightSidebarViews } from '~/ide/constants';
import { resetStore } from '../helpers';
import { projectData } from '../mock_data';
const TEST_PROJECT_ID = 'abcproject';
const TEST_MERGE_REQUEST_ID = '9001';
const TEST_MERGE_REQUEST_URL = `${TEST_HOST}merge-requests/${TEST_MERGE_REQUEST_ID}`;
describe('ideStatusBar', () => {
let store;
let vm;
beforeEach(() => {
const Component = Vue.extend(ideStatusBar);
const createComponent = () => {
vm = createComponentWithStore(Vue.extend(IdeStatusBar), store).$mount();
};
const findMRStatus = () => vm.$el.querySelector('.js-ide-status-mr');
store.state.currentProjectId = 'abcproject';
store.state.projects.abcproject = projectData;
beforeEach(() => {
store = createStore();
store.state.currentProjectId = TEST_PROJECT_ID;
store.state.projects[TEST_PROJECT_ID] = _.clone(projectData);
store.state.currentBranchId = 'master';
vm = createComponentWithStore(Component, store).$mount();
});
afterEach(() => {
vm.$destroy();
resetStore(vm.$store);
});
it('renders the statusbar', () => {
expect(vm.$el.className).toBe('ide-status-bar');
});
describe('default', () => {
beforeEach(() => {
createComponent();
});
describe('mounted', () => {
it('triggers a setInterval', () => {
expect(vm.intervalId).not.toBe(null);
});
});
describe('commitAgeUpdate', () => {
beforeEach(function() {
jasmine.clock().install();
spyOn(vm, 'commitAgeUpdate').and.callFake(() => {});
vm.startTimer();
it('renders the statusbar', () => {
expect(vm.$el.className).toBe('ide-status-bar');
});
afterEach(function() {
jasmine.clock().uninstall();
});
describe('commitAgeUpdate', () => {
beforeEach(function() {
jasmine.clock().install();
spyOn(vm, 'commitAgeUpdate').and.callFake(() => {});
vm.startTimer();
});
it('gets called every second', () => {
expect(vm.commitAgeUpdate).not.toHaveBeenCalled();
afterEach(function() {
jasmine.clock().uninstall();
});
jasmine.clock().tick(1100);
it('gets called every second', () => {
expect(vm.commitAgeUpdate).not.toHaveBeenCalled();
expect(vm.commitAgeUpdate.calls.count()).toEqual(1);
jasmine.clock().tick(1100);
jasmine.clock().tick(1000);
expect(vm.commitAgeUpdate.calls.count()).toEqual(1);
expect(vm.commitAgeUpdate.calls.count()).toEqual(2);
jasmine.clock().tick(1000);
expect(vm.commitAgeUpdate.calls.count()).toEqual(2);
});
});
});
describe('getCommitPath', () => {
it('returns the path to the commit details', () => {
expect(vm.getCommitPath('abc123de')).toBe('/commit/abc123de');
describe('getCommitPath', () => {
it('returns the path to the commit details', () => {
expect(vm.getCommitPath('abc123de')).toBe('/commit/abc123de');
});
});
describe('pipeline status', () => {
it('opens right sidebar on clicking icon', done => {
spyOn(vm, 'openRightPane');
Vue.set(vm.$store.state.pipelines, 'latestPipeline', {
details: {
status: {
text: 'success',
details_path: 'test',
icon: 'status_success',
},
},
commit: {
author_gravatar_url: 'www',
},
});
vm.$nextTick()
.then(() => {
vm.$el.querySelector('.ide-status-pipeline button').click();
expect(vm.openRightPane).toHaveBeenCalledWith(rightSidebarViews.pipelines);
})
.then(done)
.catch(done.fail);
});
});
it('does not show merge request status', () => {
expect(findMRStatus()).toBe(null);
});
});
describe('pipeline status', () => {
it('opens right sidebar on clicking icon', done => {
spyOn(vm, 'openRightPane');
Vue.set(vm.$store.state.pipelines, 'latestPipeline', {
details: {
status: {
text: 'success',
details_path: 'test',
icon: 'status_success',
describe('with merge request in store', () => {
beforeEach(() => {
store.state.projects[TEST_PROJECT_ID].mergeRequests = {
[TEST_MERGE_REQUEST_ID]: {
web_url: TEST_MERGE_REQUEST_URL,
references: {
short: `!${TEST_MERGE_REQUEST_ID}`,
},
},
commit: {
author_gravatar_url: 'www',
},
});
};
store.state.currentMergeRequestId = TEST_MERGE_REQUEST_ID;
vm.$nextTick()
.then(() => {
vm.$el.querySelector('.ide-status-pipeline button').click();
createComponent();
});
expect(vm.openRightPane).toHaveBeenCalledWith(rightSidebarViews.pipelines);
})
.then(done)
.catch(done.fail);
it('shows merge request status', () => {
expect(findMRStatus().textContent.trim()).toEqual(`Merge request !${TEST_MERGE_REQUEST_ID}`);
expect(findMRStatus().querySelector('a').href).toEqual(TEST_MERGE_REQUEST_URL);
});
});
});
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