Commit a00fea40 authored by Brandon Everett's avatar Brandon Everett

Update to GlTab in repo tabs view

Fixes https://gitlab.com/gitlab-org/gitlab/-/issues/230726
parent 266744a6
<script> <script>
import { GlIcon } from '@gitlab/ui'; import { GlIcon, GlTab } from '@gitlab/ui';
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
...@@ -13,6 +13,7 @@ export default { ...@@ -13,6 +13,7 @@ export default {
FileIcon, FileIcon,
GlIcon, GlIcon,
ChangedFileIcon, ChangedFileIcon,
GlTab,
}, },
props: { props: {
tab: { tab: {
...@@ -71,15 +72,15 @@ export default { ...@@ -71,15 +72,15 @@ export default {
</script> </script>
<template> <template>
<li <gl-tab
:class="{ :active="tab.active"
active: tab.active, :disabled="tab.pending"
disabled: tab.pending, :title="tab.name"
}"
@click="clickFile(tab)" @click="clickFile(tab)"
@mouseover="mouseOverTab" @mouseover="mouseOverTab"
@mouseout="mouseOutTab" @mouseout="mouseOutTab"
> >
<template #title>
<div :title="getUrlForPath(tab.path)" class="multi-file-tab"> <div :title="getUrlForPath(tab.path)" class="multi-file-tab">
<file-icon :file-name="tab.name" :size="16" /> <file-icon :file-name="tab.name" :size="16" />
{{ tab.name }} {{ tab.name }}
...@@ -95,5 +96,6 @@ export default { ...@@ -95,5 +96,6 @@ export default {
<gl-icon v-if="!showChangedIcon" :size="12" name="close" /> <gl-icon v-if="!showChangedIcon" :size="12" name="close" />
<changed-file-icon v-else :file="tab" /> <changed-file-icon v-else :file="tab" />
</button> </button>
</li> </template>
</gl-tab>
</template> </template>
<script> <script>
import { GlTabs } from '@gitlab/ui';
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import RepoTab from './repo_tab.vue'; import RepoTab from './repo_tab.vue';
export default { export default {
components: { components: {
RepoTab, RepoTab,
GlTabs,
}, },
props: { props: {
activeFile: { activeFile: {
...@@ -42,8 +44,8 @@ export default { ...@@ -42,8 +44,8 @@ export default {
<template> <template>
<div class="multi-file-tabs"> <div class="multi-file-tabs">
<ul ref="tabsScroller" class="list-unstyled gl-mb-0"> <gl-tabs>
<repo-tab v-for="tab in files" :key="tab.key" :tab="tab" /> <repo-tab v-for="tab in files" :key="tab.key" :tab="tab" />
</ul> </gl-tabs>
</div> </div>
</template> </template>
---
title: convert to GlTabs in app/assets/javascripts/ide/components/repo_tabs.vue
merge_request: 42162
author: Brandon Everett
type: added
import { GlTab } from '@gitlab/ui';
import { mount, createLocalVue } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { stubComponent } from 'helpers/stub_component';
import RepoTab from '~/ide/components/repo_tab.vue'; import RepoTab from '~/ide/components/repo_tab.vue';
import { createRouter } from '~/ide/ide_router'; import { createRouter } from '~/ide/ide_router';
import { createStore } from '~/ide/stores'; import { createStore } from '~/ide/stores';
...@@ -8,16 +10,25 @@ import { file } from '../helpers'; ...@@ -8,16 +10,25 @@ import { file } from '../helpers';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
const GlTabStub = stubComponent(GlTab, {
template: '<li><slot name="title" /></li>',
});
describe('RepoTab', () => { describe('RepoTab', () => {
let wrapper; let wrapper;
let store; let store;
let router; let router;
const findTab = () => wrapper.find(GlTabStub);
function createComponent(propsData) { function createComponent(propsData) {
wrapper = mount(RepoTab, { wrapper = mount(RepoTab, {
localVue, localVue,
store, store,
propsData, propsData,
stubs: {
GlTab: GlTabStub,
},
}); });
} }
...@@ -55,7 +66,7 @@ describe('RepoTab', () => { ...@@ -55,7 +66,7 @@ describe('RepoTab', () => {
jest.spyOn(wrapper.vm, 'openPendingTab').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'openPendingTab').mockImplementation(() => {});
await wrapper.trigger('click'); await findTab().vm.$emit('click');
expect(wrapper.vm.openPendingTab).not.toHaveBeenCalled(); expect(wrapper.vm.openPendingTab).not.toHaveBeenCalled();
}); });
...@@ -67,7 +78,7 @@ describe('RepoTab', () => { ...@@ -67,7 +78,7 @@ describe('RepoTab', () => {
jest.spyOn(wrapper.vm, 'clickFile').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'clickFile').mockImplementation(() => {});
wrapper.trigger('click'); findTab().vm.$emit('click');
expect(wrapper.vm.clickFile).toHaveBeenCalledWith(wrapper.vm.tab); expect(wrapper.vm.clickFile).toHaveBeenCalledWith(wrapper.vm.tab);
}); });
...@@ -91,11 +102,11 @@ describe('RepoTab', () => { ...@@ -91,11 +102,11 @@ describe('RepoTab', () => {
tab, tab,
}); });
await wrapper.trigger('mouseover'); await findTab().vm.$emit('mouseover');
expect(wrapper.find('.file-modified').exists()).toBe(false); expect(wrapper.find('.file-modified').exists()).toBe(false);
await wrapper.trigger('mouseout'); await findTab().vm.$emit('mouseout');
expect(wrapper.find('.file-modified').exists()).toBe(true); expect(wrapper.find('.file-modified').exists()).toBe(true);
}); });
......
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