Commit 9cb4384e authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '230727-yet-another-requiremnets-tab-migration' into 'master'

Migrate requirements tabs to gltab

See merge request gitlab-org/gitlab!45736
parents 0b0dcc59 2bb1c2a7
<script> <script>
import { GlLink, GlBadge, GlButton } from '@gitlab/ui'; import { GlBadge, GlButton, GlTabs, GlTab } from '@gitlab/ui';
import { FilterState } from '../constants'; import { FilterState } from '../constants';
export default { export default {
FilterState, FilterState,
components: { components: {
GlLink,
GlBadge, GlBadge,
GlButton, GlButton,
GlTabs,
GlTab,
}, },
props: { props: {
filterBy: { filterBy: {
...@@ -48,42 +49,41 @@ export default { ...@@ -48,42 +49,41 @@ export default {
</script> </script>
<template> <template>
<div class="top-area"> <div class="gl-display-flex gl-align-items-center gl-justify-content-space-between">
<ul class="nav-links mobile-separator requirements-state-filters js-requirements-state-filters"> <gl-tabs content-class="gl-p-0">
<li :class="{ active: isOpenTab }"> <gl-tab
<gl-link :title-link-attributes="{ 'data-testid': 'state-opened' }"
id="state-opened" :active="isOpenTab"
data-state="opened" @click="$emit('click-tab', { filterBy: $options.FilterState.opened })"
:title="__('Filter by requirements that are currently opened.')" >
@click="$emit('click-tab', { filterBy: $options.FilterState.opened })" <template #title>
> <span>{{ __('Open') }}</span>
{{ __('Open') }} <gl-badge size="sm" class="gl-tab-counter-badge">{{ requirementsCount.OPENED }}</gl-badge>
<gl-badge>{{ requirementsCount.OPENED }}</gl-badge> </template>
</gl-link> </gl-tab>
</li> <gl-tab
<li :class="{ active: isArchivedTab }"> :title-link-attributes="{ 'data-testid': 'state-archived' }"
<gl-link :active="isArchivedTab"
id="state-archived" @click="$emit('click-tab', { filterBy: $options.FilterState.archived })"
data-state="archived" >
:title="__('Filter by requirements that are currently archived.')" <template #title>
@click="$emit('click-tab', { filterBy: $options.FilterState.archived })" <span>{{ __('Archived') }}</span>
> <gl-badge size="sm" class="gl-tab-counter-badge">{{
{{ __('Archived') }} requirementsCount.ARCHIVED
<gl-badge>{{ requirementsCount.ARCHIVED }}</gl-badge> }}</gl-badge>
</gl-link> </template>
</li> </gl-tab>
<li :class="{ active: isAllTab }"> <gl-tab
<gl-link :title-link-attributes="{ 'data-testid': 'state-all' }"
id="state-all" :active="isAllTab"
data-state="all" @click="$emit('click-tab', { filterBy: $options.FilterState.all })"
:title="__('Show all requirements.')" >
@click="$emit('click-tab', { filterBy: $options.FilterState.all })" <template #title>
> <span>{{ __('All') }}</span>
{{ __('All') }} <gl-badge size="sm" class="gl-tab-counter-badge">{{ requirementsCount.ALL }}</gl-badge>
<gl-badge>{{ requirementsCount.ALL }}</gl-badge> </template>
</gl-link> </gl-tab>
</li> </gl-tabs>
</ul>
<div v-if="isOpenTab && canCreateRequirement" class="nav-controls"> <div v-if="isOpenTab && canCreateRequirement" class="nav-controls">
<gl-button <gl-button
v-if="showUploadCsv" v-if="showUploadCsv"
......
---
title: Migrate requirements tabs to gltab
merge_request: 45736
author:
type: changed
...@@ -44,18 +44,15 @@ RSpec.describe 'Requirements list', :js do ...@@ -44,18 +44,15 @@ RSpec.describe 'Requirements list', :js do
end end
it 'shows requirements tabs for each status type' do it 'shows requirements tabs for each status type' do
page.within('.requirements-state-filters') do page.within('.gl-tabs') do
expect(page).to have_selector('li > a#state-opened') expect(page).to have_selector('li > a[data-testid="state-opened"]')
expect(find('li > a#state-opened')[:title]).to eq('Filter by requirements that are currently opened.') expect(find('li > a[data-testid="state-opened"] .badge')).to have_content('3')
expect(find('li > a#state-opened .badge')).to have_content('3')
expect(page).to have_selector('li > a[data-testid="state-archived"]')
expect(page).to have_selector('li > a#state-archived') expect(find('li > a[data-testid="state-archived"] .badge')).to have_content('1')
expect(find('li > a#state-archived')[:title]).to eq('Filter by requirements that are currently archived.')
expect(find('li > a#state-archived .badge')).to have_content('1') expect(page).to have_selector('li > a[data-testid="state-all"]')
expect(find('li > a[data-testid="state-all"] .badge')).to have_content('4')
expect(page).to have_selector('li > a#state-all')
expect(find('li > a#state-all')[:title]).to eq('Show all requirements.')
expect(find('li > a#state-all .badge')).to have_content('4')
end end
end end
...@@ -91,16 +88,16 @@ RSpec.describe 'Requirements list', :js do ...@@ -91,16 +88,16 @@ RSpec.describe 'Requirements list', :js do
end end
it 'updates requirements count in nav sidebar and opened and all tab badges' do it 'updates requirements count in nav sidebar and opened and all tab badges' do
page.within('.requirements-state-filters') do page.within('.gl-tabs') do
expect(find('li > a#state-opened .badge')).to have_content('3') expect(find('li > a[data-testid="state-opened"] .badge')).to have_content('3')
expect(find('li > a#state-all .badge')).to have_content('4') expect(find('li > a[data-testid="state-all"] .badge')).to have_content('4')
end end
create_requirement('Foobar') create_requirement('Foobar')
page.within('.requirements-state-filters') do page.within('.gl-tabs') do
expect(find('li > a#state-opened .badge')).to have_content('4') expect(find('li > a[data-testid="state-opened"] .badge')).to have_content('4')
expect(find('li > a#state-all .badge')).to have_content('5') expect(find('li > a[data-testid="state-all"] .badge')).to have_content('5')
end end
end end
end end
...@@ -187,16 +184,16 @@ RSpec.describe 'Requirements list', :js do ...@@ -187,16 +184,16 @@ RSpec.describe 'Requirements list', :js do
end end
expect(page.find('.requirements-list-container')).to have_selector('li.requirement', count: 2) expect(page.find('.requirements-list-container')).to have_selector('li.requirement', count: 2)
page.within('.requirements-state-filters') do page.within('.gl-tabs') do
expect(find('li > a#state-opened .badge')).to have_content('2') expect(find('li > a[data-testid="state-opened"] .badge')).to have_content('2')
expect(find('li > a#state-archived .badge')).to have_content('2') expect(find('li > a[data-testid="state-archived"] .badge')).to have_content('2')
end end
end end
end end
context 'archived tab' do context 'archived tab' do
before do before do
find('li > a#state-archived').click find('li > a[data-testid="state-archived"]').click
wait_for_requests wait_for_requests
end end
...@@ -230,16 +227,16 @@ RSpec.describe 'Requirements list', :js do ...@@ -230,16 +227,16 @@ RSpec.describe 'Requirements list', :js do
end end
expect(page.find('.requirements-list-container')).to have_selector('li.requirement', count: 0) expect(page.find('.requirements-list-container')).to have_selector('li.requirement', count: 0)
page.within('.requirements-state-filters') do page.within('.gl-tabs') do
expect(find('li > a#state-opened .badge')).to have_content('4') expect(find('li > a[data-testid="state-opened"] .badge')).to have_content('4')
expect(find('li > a#state-archived .badge')).to have_content('0') expect(find('li > a[data-testid="state-archived"] .badge')).to have_content('0')
end end
end end
end end
context 'all tab' do context 'all tab' do
before do before do
find('li > a#state-all').click find('li > a[data-testid="state-all"]').click
wait_for_requests wait_for_requests
end end
......
import { GlLink, GlBadge, GlButton } from '@gitlab/ui'; import { GlTab, GlBadge, GlButton, GlTabs } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import RequirementsTabs from 'ee/requirements/components/requirements_tabs.vue'; import RequirementsTabs from 'ee/requirements/components/requirements_tabs.vue';
...@@ -21,6 +21,10 @@ const createComponent = ({ ...@@ -21,6 +21,10 @@ const createComponent = ({
canCreateRequirement, canCreateRequirement,
showUploadCsv, showUploadCsv,
}, },
stubs: {
GlTabs,
GlTab,
},
}); });
describe('RequirementsTabs', () => { describe('RequirementsTabs', () => {
...@@ -36,39 +40,30 @@ describe('RequirementsTabs', () => { ...@@ -36,39 +40,30 @@ describe('RequirementsTabs', () => {
describe('template', () => { describe('template', () => {
it('renders "Open" tab', () => { it('renders "Open" tab', () => {
const tabEl = wrapper.findAll(GlLink).at(0); const tabEl = wrapper.findAll(GlTab).at(0);
expect(tabEl.attributes('id')).toBe('state-opened');
expect(tabEl.attributes('data-state')).toBe('opened');
expect(tabEl.attributes('title')).toBe('Filter by requirements that are currently opened.');
expect(tabEl.text()).toContain('Open'); expect(tabEl.text()).toContain('Open');
expect(tabEl.find(GlBadge).text()).toBe(`${mockRequirementsCount.OPENED}`); expect(tabEl.find(GlBadge).text()).toBe(`${mockRequirementsCount.OPENED}`);
}); });
it('renders "Archived" tab', () => { it('renders "Archived" tab', () => {
const tabEl = wrapper.findAll(GlLink).at(1); const tabEl = wrapper.findAll(GlTab).at(1);
expect(tabEl.attributes('id')).toBe('state-archived');
expect(tabEl.attributes('data-state')).toBe('archived');
expect(tabEl.attributes('title')).toBe('Filter by requirements that are currently archived.');
expect(tabEl.text()).toContain('Archived'); expect(tabEl.text()).toContain('Archived');
expect(tabEl.find(GlBadge).text()).toBe(`${mockRequirementsCount.ARCHIVED}`); expect(tabEl.find(GlBadge).text()).toBe(`${mockRequirementsCount.ARCHIVED}`);
}); });
it('renders "All" tab', () => { it('renders "All" tab', () => {
const tabEl = wrapper.findAll(GlLink).at(2); const tabEl = wrapper.findAll(GlTab).at(2);
expect(tabEl.attributes('id')).toBe('state-all');
expect(tabEl.attributes('data-state')).toBe('all');
expect(tabEl.attributes('title')).toBe('Show all requirements.');
expect(tabEl.text()).toContain('All'); expect(tabEl.text()).toContain('All');
expect(tabEl.find(GlBadge).text()).toBe(`${mockRequirementsCount.ALL}`); expect(tabEl.find(GlBadge).text()).toBe(`${mockRequirementsCount.ALL}`);
}); });
it('renders class `active` on currently selected tab', () => { it('renders class `active` on currently selected tab', () => {
const tabEl = wrapper.findAll('li').at(0); const tabEl = wrapper.findAll(GlTab).at(0);
expect(tabEl.classes()).toContain('active'); expect(tabEl.attributes('active')).toBeDefined();
}); });
it('renders "New requirement" button when current tab is "Open" tab', () => { it('renders "New requirement" button when current tab is "Open" tab', () => {
......
...@@ -12224,12 +12224,6 @@ msgstr "" ...@@ -12224,12 +12224,6 @@ msgstr ""
msgid "Filter by name" msgid "Filter by name"
msgstr "" msgstr ""
msgid "Filter by requirements that are currently archived."
msgstr ""
msgid "Filter by requirements that are currently opened."
msgstr ""
msgid "Filter by status" msgid "Filter by status"
msgstr "" msgstr ""
...@@ -25450,9 +25444,6 @@ msgstr "" ...@@ -25450,9 +25444,6 @@ msgstr ""
msgid "Show all members" msgid "Show all members"
msgstr "" msgstr ""
msgid "Show all requirements."
msgstr ""
msgid "Show all test cases." msgid "Show all test cases."
msgstr "" msgstr ""
......
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