2017-08-29 08:20:58 -04:00
|
|
|
import Vue from 'vue';
|
2020-05-11 05:09:45 -04:00
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2019-12-06 04:06:39 -05:00
|
|
|
import navigationTabs from '~/vue_shared/components/navigation_tabs.vue';
|
2017-08-29 08:20:58 -04:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
describe('navigation tabs component', () => {
|
2017-08-29 08:20:58 -04:00
|
|
|
let vm;
|
|
|
|
let Component;
|
|
|
|
let data;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-11-14 10:35:29 -05:00
|
|
|
data = [
|
|
|
|
{
|
|
|
|
name: 'All',
|
|
|
|
scope: 'all',
|
|
|
|
count: 1,
|
|
|
|
isActive: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Pending',
|
|
|
|
scope: 'pending',
|
|
|
|
count: 0,
|
|
|
|
isActive: false,
|
2017-08-29 08:20:58 -04:00
|
|
|
},
|
2017-11-14 10:35:29 -05:00
|
|
|
{
|
|
|
|
name: 'Running',
|
|
|
|
scope: 'running',
|
|
|
|
isActive: false,
|
2017-08-29 08:20:58 -04:00
|
|
|
},
|
2017-11-14 10:35:29 -05:00
|
|
|
];
|
2017-08-29 08:20:58 -04:00
|
|
|
|
|
|
|
Component = Vue.extend(navigationTabs);
|
2017-11-23 07:04:03 -05:00
|
|
|
vm = mountComponent(Component, { tabs: data, scope: 'pipelines' });
|
2017-08-29 08:20:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
2017-11-14 10:35:29 -05:00
|
|
|
it('should render tabs', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('li').length).toEqual(data.length);
|
2017-08-29 08:20:58 -04:00
|
|
|
});
|
|
|
|
|
2017-11-14 10:35:29 -05:00
|
|
|
it('should render active tab', () => {
|
|
|
|
expect(vm.$el.querySelector('.active .js-pipelines-tab-all')).toBeDefined();
|
2017-08-29 08:20:58 -04:00
|
|
|
});
|
|
|
|
|
2017-11-14 10:35:29 -05:00
|
|
|
it('should render badge', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-all .badge').textContent.trim()).toEqual('1');
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-pending .badge').textContent.trim()).toEqual(
|
|
|
|
'0',
|
|
|
|
);
|
2017-11-14 10:35:29 -05:00
|
|
|
});
|
2017-08-29 08:20:58 -04:00
|
|
|
|
2017-11-14 10:35:29 -05:00
|
|
|
it('should not render badge', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-pipelines-tab-running .badge')).toEqual(null);
|
2017-08-29 08:20:58 -04:00
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
|
|
|
|
it('should trigger onTabClick', () => {
|
2020-05-11 05:09:45 -04:00
|
|
|
jest.spyOn(vm, '$emit').mockImplementation(() => {});
|
2017-11-23 07:04:03 -05:00
|
|
|
vm.$el.querySelector('.js-pipelines-tab-pending').click();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
expect(vm.$emit).toHaveBeenCalledWith('onChangeTab', 'pending');
|
|
|
|
});
|
2017-08-29 08:20:58 -04:00
|
|
|
});
|