Commit f6f186f2 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch...

Merge branch '348100-deprecate-segmented-control-performance_bar-components-detailed_metric-vue' into 'master'

Replace GlSegmentedControl with GlDropdown in PerformanceBar

See merge request gitlab-org/gitlab!81113
parents 4b4a68f4 6d20f713
<script> <script>
import { GlButton, GlModal, GlModalDirective, GlSegmentedControl } from '@gitlab/ui'; import { GlButton, GlDropdown, GlDropdownItem, GlModal, GlModalDirective } from '@gitlab/ui';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import { sortOrders, sortOrderOptions } from '../constants'; import { sortOrders, sortOrderOptions } from '../constants';
...@@ -9,8 +9,9 @@ export default { ...@@ -9,8 +9,9 @@ export default {
components: { components: {
RequestWarning, RequestWarning,
GlButton, GlButton,
GlDropdown,
GlDropdownItem,
GlModal, GlModal,
GlSegmentedControl,
}, },
directives: { directives: {
'gl-modal': GlModalDirective, 'gl-modal': GlModalDirective,
...@@ -156,13 +157,19 @@ export default { ...@@ -156,13 +157,19 @@ export default {
</div> </div>
</div> </div>
</div> </div>
<gl-segmented-control <gl-dropdown
v-if="displaySortOrder" v-if="displaySortOrder"
:text="$options.sortOrderOptions[sortOrder]"
right
data-testid="performance-bar-sort-order" data-testid="performance-bar-sort-order"
:options="$options.sortOrderOptions" >
:checked="sortOrder" <gl-dropdown-item
@input="changeSortOrder" v-for="option in Object.keys($options.sortOrderOptions)"
/> :key="option"
@click="changeSortOrder(option)"
>{{ $options.sortOrderOptions[option] }}</gl-dropdown-item
>
</gl-dropdown>
</div> </div>
<hr /> <hr />
<table class="table gl-table"> <table class="table gl-table">
......
...@@ -5,13 +5,7 @@ export const sortOrders = { ...@@ -5,13 +5,7 @@ export const sortOrders = {
CHRONOLOGICAL: 'chronological', CHRONOLOGICAL: 'chronological',
}; };
export const sortOrderOptions = [ export const sortOrderOptions = {
{ [sortOrders.DURATION]: s__('PerformanceBar|Sort by duration'),
value: sortOrders.DURATION, [sortOrders.CHRONOLOGICAL]: s__('PerformanceBar|Sort chronologically'),
text: s__('PerformanceBar|Sort by duration'), };
},
{
value: sortOrders.CHRONOLOGICAL,
text: s__('PerformanceBar|Sort chronologically'),
},
];
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlDropdownItem } from '@gitlab/ui';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import DetailedMetric from '~/performance_bar/components/detailed_metric.vue'; import DetailedMetric from '~/performance_bar/components/detailed_metric.vue';
import RequestWarning from '~/performance_bar/components/request_warning.vue'; import RequestWarning from '~/performance_bar/components/request_warning.vue';
import { sortOrders } from '~/performance_bar/constants'; import { sortOrders, sortOrderOptions } from '~/performance_bar/constants';
describe('detailedMetric', () => { describe('detailedMetric', () => {
let wrapper; let wrapper;
...@@ -29,7 +30,13 @@ describe('detailedMetric', () => { ...@@ -29,7 +30,13 @@ describe('detailedMetric', () => {
const findExpandBacktraceBtns = () => wrapper.findAllByTestId('backtrace-expand-btn'); const findExpandBacktraceBtns = () => wrapper.findAllByTestId('backtrace-expand-btn');
const findExpandedBacktraceBtnAtIndex = (index) => findExpandBacktraceBtns().at(index); const findExpandedBacktraceBtnAtIndex = (index) => findExpandBacktraceBtns().at(index);
const findDetailsLabel = () => wrapper.findByTestId('performance-bar-details-label'); const findDetailsLabel = () => wrapper.findByTestId('performance-bar-details-label');
const findSortOrderSwitcher = () => wrapper.findByTestId('performance-bar-sort-order'); const findSortOrderDropdown = () => wrapper.findByTestId('performance-bar-sort-order');
const clickSortOrderDropdownItem = (sortOrder) =>
findSortOrderDropdown()
.findAllComponents(GlDropdownItem)
.filter((item) => item.text() === sortOrderOptions[sortOrder])
.at(0)
.vm.$emit('click');
const findEmptyDetailNotice = () => wrapper.findByTestId('performance-bar-empty-detail-notice'); const findEmptyDetailNotice = () => wrapper.findByTestId('performance-bar-empty-detail-notice');
const findAllDetailDurations = () => const findAllDetailDurations = () =>
wrapper.findAllByTestId('performance-item-duration').wrappers.map((w) => w.text()); wrapper.findAllByTestId('performance-item-duration').wrappers.map((w) => w.text());
...@@ -86,7 +93,7 @@ describe('detailedMetric', () => { ...@@ -86,7 +93,7 @@ describe('detailedMetric', () => {
}); });
it('does not display sort by switcher', () => { it('does not display sort by switcher', () => {
expect(findSortOrderSwitcher().exists()).toBe(false); expect(findSortOrderDropdown().exists()).toBe(false);
}); });
}); });
...@@ -216,7 +223,7 @@ describe('detailedMetric', () => { ...@@ -216,7 +223,7 @@ describe('detailedMetric', () => {
}); });
it('does not display sort by switcher', () => { it('does not display sort by switcher', () => {
expect(findSortOrderSwitcher().exists()).toBe(false); expect(findSortOrderDropdown().exists()).toBe(false);
}); });
it('adds a modal with a table of the details', () => { it('adds a modal with a table of the details', () => {
...@@ -323,14 +330,15 @@ describe('detailedMetric', () => { ...@@ -323,14 +330,15 @@ describe('detailedMetric', () => {
}); });
it('displays sort by switcher', () => { it('displays sort by switcher', () => {
expect(findSortOrderSwitcher().exists()).toBe(true); expect(findSortOrderDropdown().exists()).toBe(true);
}); });
it('allows switch sorting orders', async () => { it('changes sortOrder on select', async () => {
findSortOrderSwitcher().vm.$emit('input', sortOrders.CHRONOLOGICAL); clickSortOrderDropdownItem(sortOrders.CHRONOLOGICAL);
await nextTick(); await nextTick();
expect(findAllDetailDurations()).toEqual(['23ms', '100ms', '75ms']); expect(findAllDetailDurations()).toEqual(['23ms', '100ms', '75ms']);
findSortOrderSwitcher().vm.$emit('input', sortOrders.DURATION);
clickSortOrderDropdownItem(sortOrders.DURATION);
await nextTick(); await nextTick();
expect(findAllDetailDurations()).toEqual(['100ms', '75ms', '23ms']); expect(findAllDetailDurations()).toEqual(['100ms', '75ms', '23ms']);
}); });
......
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