2020-01-01 13:55:28 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2022-07-16 23:28:13 +05:30
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2018-11-18 11:00:15 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import '~/performance_bar/components/performance_bar_app.vue';
|
2018-11-18 11:00:15 +05:30
|
|
|
import performanceBar from '~/performance_bar';
|
|
|
|
import PerformanceBarService from '~/performance_bar/services/performance_bar_service';
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
jest.mock('~/performance_bar/performance_bar_log');
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
describe('performance bar wrapper', () => {
|
|
|
|
let mock;
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture('<div id="js-peek"></div>');
|
2021-03-08 18:12:59 +05:30
|
|
|
const peekWrapper = document.getElementById('js-peek');
|
2020-06-23 00:09:42 +05:30
|
|
|
performance.getEntriesByType = jest.fn().mockReturnValue([]);
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
peekWrapper.setAttribute('id', 'js-peek');
|
|
|
|
peekWrapper.setAttribute('data-env', 'development');
|
|
|
|
peekWrapper.setAttribute('data-request-id', '123');
|
|
|
|
peekWrapper.setAttribute('data-peek-url', '/-/peek/results');
|
2021-04-17 20:07:23 +05:30
|
|
|
peekWrapper.setAttribute('data-stats-url', 'https://log.gprd.gitlab.net/app/dashboards#/view/');
|
2018-11-18 11:00:15 +05:30
|
|
|
peekWrapper.setAttribute('data-profile-url', '?lineprofiler=true');
|
|
|
|
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
|
|
|
mock.onGet('/-/peek/results').reply(
|
|
|
|
200,
|
|
|
|
{
|
|
|
|
data: {
|
|
|
|
gc: {
|
|
|
|
invokes: 0,
|
|
|
|
invoke_time: '0.00',
|
|
|
|
use_size: 0,
|
|
|
|
total_size: 0,
|
|
|
|
total_object: 0,
|
|
|
|
gc_time: '0.00',
|
|
|
|
},
|
|
|
|
host: { hostname: 'web-01' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
vm = performanceBar(peekWrapper);
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
2021-03-08 18:12:59 +05:30
|
|
|
document.getElementById('js-peek').remove();
|
2018-11-18 11:00:15 +05:30
|
|
|
mock.restore();
|
2022-07-16 23:28:13 +05:30
|
|
|
resetHTMLFixture();
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
describe('addRequest', () => {
|
2018-11-18 11:00:15 +05:30
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(vm.store, 'addRequest');
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does nothing if the request cannot be tracked', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(vm.store, 'canTrackRequest').mockImplementation(() => false);
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
vm.addRequest('123', 'https://gitlab.com/');
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
expect(vm.store.addRequest).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds the request immediately', () => {
|
2022-05-07 20:08:51 +05:30
|
|
|
vm.addRequest('123', 'https://gitlab.com/');
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(vm.store.addRequest).toHaveBeenCalledWith('123', 'https://gitlab.com/');
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
2022-05-07 20:08:51 +05:30
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
describe('loadRequestDetails', () => {
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(PerformanceBarService, 'fetchRequestDetails');
|
2022-05-07 20:08:51 +05:30
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
it('makes an HTTP request for the request details', () => {
|
|
|
|
vm.addRequest('456', 'https://gitlab.com/');
|
|
|
|
vm.loadRequestDetails('456');
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
expect(PerformanceBarService.fetchRequestDetails).toHaveBeenCalledWith(
|
|
|
|
'/-/peek/results',
|
|
|
|
'456',
|
|
|
|
);
|
|
|
|
});
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
it('does not make a request if request was not added', () => {
|
|
|
|
vm.loadRequestDetails('456');
|
|
|
|
|
|
|
|
expect(PerformanceBarService.fetchRequestDetails).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('makes an HTTP request only once for the same request', async () => {
|
|
|
|
vm.addRequest('456', 'https://gitlab.com/');
|
|
|
|
await vm.loadRequestDetails('456');
|
|
|
|
|
|
|
|
vm.loadRequestDetails('456');
|
|
|
|
|
|
|
|
expect(PerformanceBarService.fetchRequestDetails).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
});
|