debian-mirror-gitlab/spec/frontend/performance_bar/components/detailed_metric_spec.js

187 lines
5.7 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { nextTick } from 'vue';
2020-01-01 13:55:28 +05:30
import { shallowMount } from '@vue/test-utils';
2020-10-24 23:57:45 +05:30
import { trimText } from 'helpers/text_helper';
2019-12-21 20:55:43 +05:30
import DetailedMetric from '~/performance_bar/components/detailed_metric.vue';
import RequestWarning from '~/performance_bar/components/request_warning.vue';
describe('detailedMetric', () => {
2020-06-23 00:09:42 +05:30
let wrapper;
2021-03-08 18:12:59 +05:30
const createComponent = (props) => {
2020-06-23 00:09:42 +05:30
wrapper = shallowMount(DetailedMetric, {
2019-12-21 20:55:43 +05:30
propsData: {
...props,
},
});
2020-06-23 00:09:42 +05:30
};
2021-01-29 00:20:46 +05:30
const findAllTraceBlocks = () => wrapper.findAll('pre');
2021-03-08 18:12:59 +05:30
const findTraceBlockAtIndex = (index) => findAllTraceBlocks().at(index);
2021-01-29 00:20:46 +05:30
const findExpandBacktraceBtns = () => wrapper.findAll('[data-testid="backtrace-expand-btn"]');
2021-03-08 18:12:59 +05:30
const findExpandedBacktraceBtnAtIndex = (index) => findExpandBacktraceBtns().at(index);
2021-01-29 00:20:46 +05:30
2020-06-23 00:09:42 +05:30
afterEach(() => {
wrapper.destroy();
});
2019-12-21 20:55:43 +05:30
describe('when the current request has no details', () => {
2020-06-23 00:09:42 +05:30
beforeEach(() => {
createComponent({
currentRequest: {},
metric: 'gitaly',
header: 'Gitaly calls',
details: 'details',
keys: ['feature', 'request'],
});
2019-12-21 20:55:43 +05:30
});
it('does not render the element', () => {
2020-11-24 15:15:51 +05:30
expect(wrapper.html()).toBe('');
2019-12-21 20:55:43 +05:30
});
});
describe('when the current request has details', () => {
const requestDetails = [
{ duration: '100', feature: 'find_commit', request: 'abcdef', backtrace: ['hello', 'world'] },
2021-01-29 00:20:46 +05:30
{
duration: '23',
feature: 'rebase_in_progress',
request: '',
backtrace: ['other', 'example'],
},
2019-12-21 20:55:43 +05:30
];
describe('with a default metric name', () => {
2020-06-23 00:09:42 +05:30
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
duration: '123ms',
calls: '456',
details: requestDetails,
warnings: ['gitaly calls: 456 over 30'],
},
2019-12-21 20:55:43 +05:30
},
},
2020-06-23 00:09:42 +05:30
metric: 'gitaly',
header: 'Gitaly calls',
keys: ['feature', 'request'],
});
2019-12-21 20:55:43 +05:30
});
it('displays details', () => {
expect(wrapper.text().replace(/\s+/g, ' ')).toContain('123ms / 456');
});
it('adds a modal with a table of the details', () => {
wrapper
.findAll('.performance-bar-modal td:nth-child(1)')
.wrappers.forEach((duration, index) => {
expect(duration.text()).toContain(requestDetails[index].duration);
});
wrapper
.findAll('.performance-bar-modal td:nth-child(2)')
.wrappers.forEach((feature, index) => {
expect(feature.text()).toContain(requestDetails[index].feature);
});
wrapper
.findAll('.performance-bar-modal td:nth-child(2)')
.wrappers.forEach((request, index) => {
expect(request.text()).toContain(requestDetails[index].request);
});
2021-01-29 00:20:46 +05:30
expect(wrapper.find('.js-toggle-button')).not.toBeNull();
2019-12-21 20:55:43 +05:30
2021-03-08 18:12:59 +05:30
wrapper.findAll('.performance-bar-modal td:nth-child(2)').wrappers.forEach((request) => {
2019-12-21 20:55:43 +05:30
expect(request.text()).toContain('world');
});
});
it('displays the metric title', () => {
expect(wrapper.text()).toContain('gitaly');
});
it('displays request warnings', () => {
expect(wrapper.find(RequestWarning).exists()).toBe(true);
});
2021-01-29 00:20:46 +05:30
it('can open and close traces', async () => {
expect(findAllTraceBlocks()).toHaveLength(0);
// Each block click on a new trace and assert that the correct
// count is open and that the content is what we expect to ensure
// we opened or closed the right one
const secondExpandButton = findExpandedBacktraceBtnAtIndex(1);
findExpandedBacktraceBtnAtIndex(0).vm.$emit('click');
await nextTick();
expect(findAllTraceBlocks()).toHaveLength(1);
expect(findTraceBlockAtIndex(0).text()).toContain(requestDetails[0].backtrace[0]);
secondExpandButton.vm.$emit('click');
await nextTick();
expect(findAllTraceBlocks()).toHaveLength(2);
expect(findTraceBlockAtIndex(1).text()).toContain(requestDetails[1].backtrace[0]);
secondExpandButton.vm.$emit('click');
await nextTick();
expect(findAllTraceBlocks()).toHaveLength(1);
expect(findTraceBlockAtIndex(0).text()).toContain(requestDetails[0].backtrace[0]);
});
2019-12-21 20:55:43 +05:30
});
describe('when using a custom metric title', () => {
2020-06-23 00:09:42 +05:30
beforeEach(() => {
createComponent({
currentRequest: {
details: {
gitaly: {
duration: '123ms',
calls: '456',
details: requestDetails,
},
},
},
metric: 'gitaly',
title: 'custom',
header: 'Gitaly calls',
keys: ['feature', 'request'],
});
});
it('displays the custom title', () => {
expect(wrapper.text()).toContain('custom');
});
});
});
describe('when the details has no duration', () => {
beforeEach(() => {
createComponent({
2019-12-21 20:55:43 +05:30
currentRequest: {
details: {
2020-06-23 00:09:42 +05:30
bullet: {
2019-12-21 20:55:43 +05:30
calls: '456',
2020-06-23 00:09:42 +05:30
details: [{ notification: 'notification', backtrace: 'backtrace' }],
2019-12-21 20:55:43 +05:30
},
},
},
2020-06-23 00:09:42 +05:30
metric: 'bullet',
header: 'Bullet notifications',
keys: ['notification'],
2019-12-21 20:55:43 +05:30
});
2020-06-23 00:09:42 +05:30
});
2019-12-21 20:55:43 +05:30
2021-01-29 00:20:46 +05:30
it('renders only the number of calls', async () => {
expect(trimText(wrapper.text())).toEqual('456 notification bullet');
findExpandedBacktraceBtnAtIndex(0).vm.$emit('click');
await nextTick();
2020-06-23 00:09:42 +05:30
expect(trimText(wrapper.text())).toEqual('456 notification backtrace bullet');
2019-12-21 20:55:43 +05:30
});
});
});