2021-03-08 18:12:59 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { GlTab } from '@gitlab/ui';
|
|
|
|
import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('navigation tabs component', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
let wrapper;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
name: 'All',
|
|
|
|
scope: 'all',
|
|
|
|
count: 1,
|
|
|
|
isActive: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Pending',
|
|
|
|
scope: 'pending',
|
|
|
|
count: 0,
|
|
|
|
isActive: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Running',
|
|
|
|
scope: 'running',
|
|
|
|
isActive: false,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = mount(NavigationTabs, {
|
|
|
|
propsData: {
|
|
|
|
tabs: data,
|
|
|
|
scope: 'pipelines',
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render tabs', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.findAll(GlTab)).toHaveLength(data.length);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render active tab', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find('.js-pipelines-tab-all').classes('active')).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render badge', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find('.js-pipelines-tab-all').text()).toContain('1');
|
|
|
|
expect(wrapper.find('.js-pipelines-tab-pending').text()).toContain('0');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render badge', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find('.js-pipelines-tab-running .badge').exists()).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should trigger onTabClick', async () => {
|
|
|
|
await wrapper.find('.js-pipelines-tab-pending').trigger('click');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.emitted('onChangeTab')).toEqual([['pending']]);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|