2017-09-10 17:25:29 +05:30
|
|
|
import Vue from 'vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
import mountComponent, { mountComponentWithSlots } from 'helpers/vue_mount_component_helper';
|
2020-01-01 13:55:28 +05:30
|
|
|
import headerCi from '~/vue_shared/components/header_ci_component.vue';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe('Header CI Component', () => {
|
|
|
|
let HeaderCi;
|
|
|
|
let vm;
|
|
|
|
let props;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
HeaderCi = Vue.extend(headerCi);
|
|
|
|
props = {
|
|
|
|
status: {
|
|
|
|
group: 'failed',
|
2018-11-18 11:00:15 +05:30
|
|
|
icon: 'status_failed',
|
2017-09-10 17:25:29 +05:30
|
|
|
label: 'failed',
|
|
|
|
text: 'failed',
|
|
|
|
details_path: 'path',
|
|
|
|
},
|
|
|
|
itemName: 'job',
|
|
|
|
itemId: 123,
|
|
|
|
time: '2017-05-08T14:57:39.781Z',
|
|
|
|
user: {
|
|
|
|
web_url: 'path',
|
|
|
|
name: 'Foo',
|
|
|
|
username: 'foobar',
|
|
|
|
email: 'foo@bar.com',
|
|
|
|
avatar_url: 'link',
|
|
|
|
},
|
|
|
|
hasSidebarButton: true,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const findActionButtons = () => vm.$el.querySelector('.header-action-buttons');
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('render', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(HeaderCi, props);
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should render status badge', () => {
|
|
|
|
expect(vm.$el.querySelector('.ci-failed')).toBeDefined();
|
|
|
|
expect(vm.$el.querySelector('.ci-status-icon-failed svg')).toBeDefined();
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.ci-failed').getAttribute('href')).toEqual(
|
|
|
|
props.status.details_path,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should render item name and id', () => {
|
|
|
|
expect(vm.$el.querySelector('strong').textContent.trim()).toEqual('job #123');
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should render timeago date', () => {
|
|
|
|
expect(vm.$el.querySelector('time')).toBeDefined();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should render user icon and name', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.$el.querySelector('.js-user-link').innerText.trim()).toContain(props.user.name);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('should render sidebar toggle button', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-sidebar-build-toggle')).not.toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('should not render header action buttons when empty', () => {
|
|
|
|
expect(findActionButtons()).toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe('slot', () => {
|
|
|
|
it('should render header action buttons', () => {
|
|
|
|
vm = mountComponentWithSlots(HeaderCi, { props, slots: { default: 'Test Actions' } });
|
|
|
|
|
|
|
|
const buttons = findActionButtons();
|
|
|
|
|
|
|
|
expect(buttons).not.toBeNull();
|
|
|
|
expect(buttons.textContent).toEqual('Test Actions');
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('shouldRenderTriggeredLabel', () => {
|
|
|
|
it('should rendered created keyword when the shouldRenderTriggeredLabel is false', () => {
|
|
|
|
vm = mountComponent(HeaderCi, { ...props, shouldRenderTriggeredLabel: false });
|
|
|
|
|
|
|
|
expect(vm.$el.textContent).toContain('created');
|
|
|
|
expect(vm.$el.textContent).not.toContain('triggered');
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|