Commit 98a0373d authored by Paul Slaughter's avatar Paul Slaughter

Decouple ide_router from components

- Instead we can simply use `this.$router`
parent 8bbccfad
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
/* eslint-disable @gitlab/vue-require-i18n-strings */ /* eslint-disable @gitlab/vue-require-i18n-strings */
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import Timeago from '~/vue_shared/components/time_ago_tooltip.vue'; import Timeago from '~/vue_shared/components/time_ago_tooltip.vue';
import router from '../../ide_router';
export default { export default {
components: { components: {
...@@ -26,7 +25,7 @@ export default { ...@@ -26,7 +25,7 @@ export default {
}, },
computed: { computed: {
branchHref() { branchHref() {
return router.resolve(`/project/${this.projectId}/edit/${this.item.name}`).href; return this.$router.resolve(`/project/${this.projectId}/edit/${this.item.name}`).href;
}, },
}, },
}; };
......
<script> <script>
import Icon from '../../../vue_shared/components/icon.vue'; import Icon from '../../../vue_shared/components/icon.vue';
import router from '../../ide_router';
export default { export default {
components: { components: {
...@@ -33,7 +32,7 @@ export default { ...@@ -33,7 +32,7 @@ export default {
mergeRequestHref() { mergeRequestHref() {
const path = `/project/${this.item.projectPathWithNamespace}/merge_requests/${this.item.iid}`; const path = `/project/${this.item.projectPathWithNamespace}/merge_requests/${this.item.iid}`;
return router.resolve(path).href; return this.$router.resolve(path).href;
}, },
}, },
}; };
......
<script> <script>
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import RepoTab from './repo_tab.vue'; import RepoTab from './repo_tab.vue';
import router from '../ide_router';
export default { export default {
components: { components: {
...@@ -28,7 +27,7 @@ export default { ...@@ -28,7 +27,7 @@ export default {
if (this.activeFile.pending) { if (this.activeFile.pending) {
return this.removePendingTab(this.activeFile).then(() => { return this.removePendingTab(this.activeFile).then(() => {
router.push(`/project${this.activeFile.url}`); this.$router.push(`/project${this.activeFile.url}`);
}); });
} }
......
...@@ -22,6 +22,7 @@ describe('IDE branch item', () => { ...@@ -22,6 +22,7 @@ describe('IDE branch item', () => {
isActive: false, isActive: false,
...props, ...props,
}, },
router,
}); });
} }
......
import Vue from 'vue'; import { mount } from '@vue/test-utils';
import router from '~/ide/ide_router'; import router from '~/ide/ide_router';
import Item from '~/ide/components/merge_requests/item.vue'; import Item from '~/ide/components/merge_requests/item.vue';
import mountCompontent from '../../../helpers/vue_mount_component_helper';
const TEST_ITEM = {
iid: 1,
projectPathWithNamespace: 'gitlab-org/gitlab-ce',
title: 'Merge request title',
};
describe('IDE merge request item', () => { describe('IDE merge request item', () => {
const Component = Vue.extend(Item); let wrapper;
let vm;
const createComponent = (props = {}) => {
beforeEach(() => { wrapper = mount(Item, {
vm = mountCompontent(Component, { propsData: {
item: { item: {
iid: 1, ...TEST_ITEM,
projectPathWithNamespace: 'gitlab-org/gitlab-ce', },
title: 'Merge request title', currentId: `${TEST_ITEM.iid}`,
currentProjectId: TEST_ITEM.projectPathWithNamespace,
...props,
}, },
currentId: '1', router,
currentProjectId: 'gitlab-org/gitlab-ce',
}); });
}); };
const findIcon = () => wrapper.find('.ic-mobile-issue-close');
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
wrapper = null;
}); });
it('renders merge requests data', () => { describe('default', () => {
expect(vm.$el.textContent).toContain('Merge request title'); beforeEach(() => {
expect(vm.$el.textContent).toContain('gitlab-org/gitlab-ce!1'); createComponent();
}); });
it('renders link with href', () => { it('renders merge requests data', () => {
const expectedHref = router.resolve( expect(wrapper.text()).toContain('Merge request title');
`/project/${vm.item.projectPathWithNamespace}/merge_requests/${vm.item.iid}`, expect(wrapper.text()).toContain('gitlab-org/gitlab-ce!1');
).href; });
expect(vm.$el.tagName.toLowerCase()).toBe('a'); it('renders link with href', () => {
expect(vm.$el).toHaveAttr('href', expectedHref); const expectedHref = router.resolve(
}); `/project/${TEST_ITEM.projectPathWithNamespace}/merge_requests/${TEST_ITEM.iid}`,
).href;
it('renders icon if ID matches currentId', () => { expect(wrapper.element.tagName.toLowerCase()).toBe('a');
expect(vm.$el.querySelector('.ic-mobile-issue-close')).not.toBe(null); expect(wrapper.attributes('href')).toBe(expectedHref);
}); });
it('does not render icon if ID does not match currentId', done => { it('renders icon if ID matches currentId', () => {
vm.currentId = '2'; expect(findIcon().exists()).toBe(true);
});
});
vm.$nextTick(() => { describe('with different currentId', () => {
expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null); beforeEach(() => {
createComponent({ currentId: `${TEST_ITEM.iid + 1}` });
});
done(); it('does not render icon', () => {
expect(findIcon().exists()).toBe(false);
}); });
}); });
it('does not render icon if project ID does not match', done => { describe('with different project ID', () => {
vm.currentProjectId = 'test/test'; beforeEach(() => {
createComponent({ currentProjectId: 'test/test' });
vm.$nextTick(() => { });
expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null);
done(); it('does not render icon', () => {
expect(findIcon().exists()).toBe(false);
}); });
}); });
}); });
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