debian-mirror-gitlab/spec/frontend/ide/components/branches/item_spec.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2018-11-18 11:00:15 +05:30
import Item from '~/ide/components/branches/item.vue';
2021-03-11 19:13:27 +05:30
import { createRouter } from '~/ide/ide_router';
import { createStore } from '~/ide/stores';
2020-03-13 15:44:24 +05:30
import Timeago from '~/vue_shared/components/time_ago_tooltip.vue';
2018-11-18 11:00:15 +05:30
import { projectData } from '../../mock_data';
const TEST_BRANCH = {
2021-09-04 01:27:46 +05:30
name: 'main',
2018-11-18 11:00:15 +05:30
committedDate: '2018-01-05T05:50Z',
};
const TEST_PROJECT_ID = projectData.name_with_namespace;
describe('IDE branch item', () => {
2020-03-13 15:44:24 +05:30
let wrapper;
2020-06-23 00:09:42 +05:30
let store;
let router;
2020-03-13 15:44:24 +05:30
function createComponent(props = {}) {
wrapper = shallowMount(Item, {
propsData: {
item: { ...TEST_BRANCH },
projectId: TEST_PROJECT_ID,
isActive: false,
...props,
},
2020-06-23 00:09:42 +05:30
router,
2018-11-18 11:00:15 +05:30
});
2020-03-13 15:44:24 +05:30
}
2018-11-18 11:00:15 +05:30
2020-06-23 00:09:42 +05:30
beforeEach(() => {
store = createStore();
router = createRouter(store);
});
2018-11-18 11:00:15 +05:30
afterEach(() => {
2020-03-13 15:44:24 +05:30
wrapper.destroy();
2018-11-18 11:00:15 +05:30
});
2020-03-13 15:44:24 +05:30
describe('if not active', () => {
beforeEach(() => {
createComponent();
});
it('renders branch name and timeago', () => {
expect(wrapper.text()).toContain(TEST_BRANCH.name);
expect(wrapper.find(Timeago).props('time')).toBe(TEST_BRANCH.committedDate);
2020-11-24 15:15:51 +05:30
expect(wrapper.find(GlIcon).exists()).toBe(false);
2020-03-13 15:44:24 +05:30
});
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
it('renders link to branch', () => {
const expectedHref = router.resolve(`/project/${TEST_PROJECT_ID}/edit/${TEST_BRANCH.name}`)
.href;
2018-12-13 13:39:08 +05:30
2020-03-13 15:44:24 +05:30
expect(wrapper.text()).toMatch('a');
expect(wrapper.attributes('href')).toBe(expectedHref);
});
2018-11-18 11:00:15 +05:30
});
2020-03-13 15:44:24 +05:30
it('renders icon if is not active', () => {
createComponent({ isActive: true });
2018-11-18 11:00:15 +05:30
2020-11-24 15:15:51 +05:30
expect(wrapper.find(GlIcon).exists()).toBe(true);
2018-11-18 11:00:15 +05:30
});
});