2020-06-23 00:09:42 +05:30
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { mount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import { createStore } from '~/ide/stores';
|
|
|
|
import { createRouter } from '~/ide/ide_router';
|
2018-11-08 19:23:39 +05:30
|
|
|
import Item from '~/ide/components/merge_requests/item.vue';
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
const TEST_ITEM = {
|
|
|
|
iid: 1,
|
|
|
|
projectPathWithNamespace: 'gitlab-org/gitlab-ce',
|
|
|
|
title: 'Merge request title',
|
|
|
|
};
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
describe('IDE merge request item', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
let router;
|
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = mount(Item, {
|
|
|
|
propsData: {
|
|
|
|
item: {
|
|
|
|
...TEST_ITEM,
|
|
|
|
},
|
|
|
|
currentId: `${TEST_ITEM.iid}`,
|
|
|
|
currentProjectId: TEST_ITEM.projectPathWithNamespace,
|
|
|
|
...props,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2020-06-23 00:09:42 +05:30
|
|
|
localVue,
|
|
|
|
router,
|
|
|
|
store,
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
};
|
|
|
|
const findIcon = () => wrapper.find('.ic-mobile-issue-close');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
router = createRouter(store);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
describe('default', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders merge requests data', () => {
|
|
|
|
expect(wrapper.text()).toContain('Merge request title');
|
|
|
|
expect(wrapper.text()).toContain('gitlab-org/gitlab-ce!1');
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('renders link with href', () => {
|
|
|
|
const expectedHref = router.resolve(
|
|
|
|
`/project/${TEST_ITEM.projectPathWithNamespace}/merge_requests/${TEST_ITEM.iid}`,
|
|
|
|
).href;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.element.tagName.toLowerCase()).toBe('a');
|
|
|
|
expect(wrapper.attributes('href')).toBe(expectedHref);
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('renders icon if ID matches currentId', () => {
|
|
|
|
expect(findIcon().exists()).toBe(true);
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
describe('with different currentId', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ currentId: `${TEST_ITEM.iid + 1}` });
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('does not render icon', () => {
|
|
|
|
expect(findIcon().exists()).toBe(false);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
describe('with different project ID', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ currentProjectId: 'test/test' });
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('does not render icon', () => {
|
|
|
|
expect(findIcon().exists()).toBe(false);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|