Commit 1cc51c95 authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '230728-nav-tabs-migration' into 'master'

Convert tabs in navigation_tabs.vue to gl-tabs

See merge request gitlab-org/gitlab!47841
parents 0d75b670 1ed01697
...@@ -279,7 +279,7 @@ export default { ...@@ -279,7 +279,7 @@ export default {
<div class="pipelines-container"> <div class="pipelines-container">
<div <div
v-if="shouldRenderTabs || shouldRenderButtons" v-if="shouldRenderTabs || shouldRenderButtons"
class="top-area scrolling-tabs-container inner-page-scroll-tabs" class="top-area scrolling-tabs-container inner-page-scroll-tabs gl-border-none"
> >
<div class="fade-left"><gl-icon name="chevron-lg-left" :size="12" /></div> <div class="fade-left"><gl-icon name="chevron-lg-left" :size="12" /></div>
<div class="fade-right"><gl-icon name="chevron-lg-right" :size="12" /></div> <div class="fade-right"><gl-icon name="chevron-lg-right" :size="12" /></div>
......
<script> <script>
import $ from 'jquery'; import $ from 'jquery';
import { GlBadge, GlTabs, GlTab } from '@gitlab/ui';
/** /**
* Given an array of tabs, renders non linked bootstrap tabs. * Given an array of tabs, renders non linked bootstrap tabs.
...@@ -23,6 +24,11 @@ import $ from 'jquery'; ...@@ -23,6 +24,11 @@ import $ from 'jquery';
*/ */
export default { export default {
name: 'NavigationTabs', name: 'NavigationTabs',
components: {
GlBadge,
GlTabs,
GlTab,
},
props: { props: {
tabs: { tabs: {
type: Array, type: Array,
...@@ -50,24 +56,21 @@ export default { ...@@ -50,24 +56,21 @@ export default {
}; };
</script> </script>
<template> <template>
<ul class="nav-links scrolling-tabs separator"> <gl-tabs class="gl-display-flex gl-w-full" nav-class="gl-border-0!">
<li <gl-tab
v-for="(tab, i) in tabs" v-for="(tab, i) in tabs"
:key="i" :key="i"
:class="{ :title-link-class="`js-${scope}-tab-${tab.scope} gl-display-inline-flex`"
active: tab.isActive, :title-link-attributes="{ 'data-testid': `${scope}-tab-${tab.scope}` }"
}" :active="tab.isActive"
@click="onTabClick(tab)"
> >
<a <template #title>
:class="`js-${scope}-tab-${tab.scope}`" <span class="gl-mr-2"> {{ tab.name }} </span>
:data-testid="`${scope}-tab-${tab.scope}`" <gl-badge v-if="shouldRenderBadge(tab.count)" size="sm" class="gl-tab-counter-badge">{{
role="button" tab.count
@click="onTabClick(tab)" }}</gl-badge>
> </template>
{{ tab.name }} </gl-tab>
</gl-tabs>
<span v-if="shouldRenderBadge(tab.count)" class="badge badge-pill"> {{ tab.count }} </span>
</a>
</li>
</ul>
</template> </template>
---
title: Convert navigation_tabs.vue to gl-tabs
merge_request: 47841
author:
type: other
...@@ -35,7 +35,7 @@ describe('Deploy keys app component', () => { ...@@ -35,7 +35,7 @@ describe('Deploy keys app component', () => {
}); });
const findLoadingIcon = () => wrapper.find('.gl-spinner'); const findLoadingIcon = () => wrapper.find('.gl-spinner');
const findKeyPanels = () => wrapper.findAll('.deploy-keys .nav-links li'); const findKeyPanels = () => wrapper.findAll('.deploy-keys .gl-tabs-nav li');
it('renders loading icon while waiting for request', () => { it('renders loading icon while waiting for request', () => {
mock.onGet(TEST_ENDPOINT).reply(() => new Promise()); mock.onGet(TEST_ENDPOINT).reply(() => new Promise());
...@@ -54,17 +54,14 @@ describe('Deploy keys app component', () => { ...@@ -54,17 +54,14 @@ describe('Deploy keys app component', () => {
}); });
it.each` it.each`
selector | label | count selector
${'.js-deployKeys-tab-enabled_keys'} | ${'Enabled deploy keys'} | ${1} ${'.js-deployKeys-tab-enabled_keys'}
${'.js-deployKeys-tab-available_project_keys'} | ${'Privately accessible deploy keys'} | ${0} ${'.js-deployKeys-tab-available_project_keys'}
${'.js-deployKeys-tab-public_keys'} | ${'Publicly accessible deploy keys'} | ${1} ${'.js-deployKeys-tab-public_keys'}
`('$selector title is $label with keys count equal to $count', ({ selector, label, count }) => { `('$selector title exists', ({ selector }) => {
return mountComponent().then(() => { return mountComponent().then(() => {
const element = wrapper.find(selector); const element = wrapper.find(selector);
expect(element.exists()).toBe(true); expect(element.exists()).toBe(true);
expect(element.text().trim()).toContain(label);
expect(element.find('.badge').text().trim()).toBe(count.toString());
}); });
}); });
......
import Vue from 'vue'; import { mount } from '@vue/test-utils';
import mountComponent from 'helpers/vue_mount_component_helper'; import { GlTab } from '@gitlab/ui';
import navigationTabs from '~/vue_shared/components/navigation_tabs.vue'; import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue';
describe('navigation tabs component', () => { describe('navigation tabs component', () => {
let vm; let wrapper;
let Component;
let data;
beforeEach(() => { const data = [
data = [ {
{ name: 'All',
name: 'All', scope: 'all',
scope: 'all', count: 1,
count: 1, isActive: true,
isActive: true, },
}, {
{ name: 'Pending',
name: 'Pending', scope: 'pending',
scope: 'pending', count: 0,
count: 0, isActive: false,
isActive: false, },
}, {
{ name: 'Running',
name: 'Running', scope: 'running',
scope: 'running', isActive: false,
isActive: false, },
];
const createComponent = () => {
wrapper = mount(NavigationTabs, {
propsData: {
tabs: data,
scope: 'pipelines',
}, },
]; });
};
Component = Vue.extend(navigationTabs); beforeEach(() => {
vm = mountComponent(Component, { tabs: data, scope: 'pipelines' }); createComponent();
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
wrapper = null;
}); });
it('should render tabs', () => { it('should render tabs', () => {
expect(vm.$el.querySelectorAll('li').length).toEqual(data.length); expect(wrapper.findAll(GlTab)).toHaveLength(data.length);
}); });
it('should render active tab', () => { it('should render active tab', () => {
expect(vm.$el.querySelector('.active .js-pipelines-tab-all')).toBeDefined(); expect(wrapper.find('.js-pipelines-tab-all').classes('active')).toBe(true);
}); });
it('should render badge', () => { it('should render badge', () => {
expect(vm.$el.querySelector('.js-pipelines-tab-all .badge').textContent.trim()).toEqual('1'); expect(wrapper.find('.js-pipelines-tab-all').text()).toContain('1');
expect(vm.$el.querySelector('.js-pipelines-tab-pending .badge').textContent.trim()).toEqual( expect(wrapper.find('.js-pipelines-tab-pending').text()).toContain('0');
'0',
);
}); });
it('should not render badge', () => { it('should not render badge', () => {
expect(vm.$el.querySelector('.js-pipelines-tab-running .badge')).toEqual(null); expect(wrapper.find('.js-pipelines-tab-running .badge').exists()).toBe(false);
}); });
it('should trigger onTabClick', () => { it('should trigger onTabClick', async () => {
jest.spyOn(vm, '$emit').mockImplementation(() => {}); await wrapper.find('.js-pipelines-tab-pending').trigger('click');
vm.$el.querySelector('.js-pipelines-tab-pending').click();
expect(vm.$emit).toHaveBeenCalledWith('onChangeTab', 'pending'); expect(wrapper.emitted('onChangeTab')).toEqual([['pending']]);
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment