2022-05-30 11:08:03 -04:00
|
|
|
import { GlSkeletonLoader } from '@gitlab/ui';
|
2022-01-25 10:12:32 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-10-22 05:09:20 -04:00
|
|
|
import metricsData from 'test_fixtures/projects/analytics/value_stream_analytics/summary.json';
|
2022-05-04 08:07:48 -04:00
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-08-16 08:09:17 -04:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2022-02-04 07:17:40 -05:00
|
|
|
import ValueStreamMetrics from '~/analytics/shared/components/value_stream_metrics.vue';
|
2021-08-16 08:09:17 -04:00
|
|
|
import { METRIC_TYPE_SUMMARY } from '~/api/analytics_api';
|
2022-05-04 08:07:48 -04:00
|
|
|
import { VSA_METRICS_GROUPS, METRICS_POPOVER_CONTENT } from '~/analytics/shared/constants';
|
2022-02-04 07:17:40 -05:00
|
|
|
import { prepareTimeMetricsData } from '~/analytics/shared/utils';
|
|
|
|
import MetricTile from '~/analytics/shared/components/metric_tile.vue';
|
2021-08-16 08:09:17 -04:00
|
|
|
import createFlash from '~/flash';
|
2021-10-22 05:09:20 -04:00
|
|
|
import { group } from './mock_data';
|
2021-08-16 08:09:17 -04:00
|
|
|
|
|
|
|
jest.mock('~/flash');
|
|
|
|
|
|
|
|
describe('ValueStreamMetrics', () => {
|
|
|
|
let wrapper;
|
|
|
|
let mockGetValueStreamSummaryMetrics;
|
2022-02-02 10:17:50 -05:00
|
|
|
let mockFilterFn;
|
2021-08-16 08:09:17 -04:00
|
|
|
|
|
|
|
const { full_path: requestPath } = group;
|
|
|
|
const fakeReqName = 'Mock metrics';
|
|
|
|
const metricsRequestFactory = () => ({
|
|
|
|
request: mockGetValueStreamSummaryMetrics,
|
|
|
|
endpoint: METRIC_TYPE_SUMMARY,
|
|
|
|
name: fakeReqName,
|
|
|
|
});
|
|
|
|
|
2022-02-02 10:17:50 -05:00
|
|
|
const createComponent = (props = {}) => {
|
2022-05-04 08:07:48 -04:00
|
|
|
return shallowMountExtended(ValueStreamMetrics, {
|
2021-08-16 08:09:17 -04:00
|
|
|
propsData: {
|
|
|
|
requestPath,
|
2022-02-02 10:17:50 -05:00
|
|
|
requestParams: {},
|
2021-08-16 08:09:17 -04:00
|
|
|
requests: [metricsRequestFactory()],
|
2022-02-02 10:17:50 -05:00
|
|
|
...props,
|
2021-08-16 08:09:17 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-01-26 10:12:36 -05:00
|
|
|
const findMetrics = () => wrapper.findAllComponents(MetricTile);
|
2022-05-04 08:07:48 -04:00
|
|
|
const findMetricsGroups = () => wrapper.findAllByTestId('vsa-metrics-group');
|
2021-08-16 08:09:17 -04:00
|
|
|
|
|
|
|
const expectToHaveRequest = (fields) => {
|
|
|
|
expect(mockGetValueStreamSummaryMetrics).toHaveBeenCalledWith({
|
|
|
|
endpoint: METRIC_TYPE_SUMMARY,
|
|
|
|
requestPath,
|
|
|
|
...fields,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with successful requests', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockGetValueStreamSummaryMetrics = jest.fn().mockResolvedValue({ data: metricsData });
|
|
|
|
wrapper = createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will display a loader with pending requests', async () => {
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-08-16 08:09:17 -04:00
|
|
|
|
2022-05-30 11:08:03 -04:00
|
|
|
expect(wrapper.findComponent(GlSkeletonLoader).exists()).toBe(true);
|
2021-11-01 05:13:14 -04:00
|
|
|
});
|
|
|
|
|
2021-08-16 08:09:17 -04:00
|
|
|
describe('with data loaded', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fetches data from the value stream analytics endpoint', () => {
|
|
|
|
expectToHaveRequest({ params: {} });
|
|
|
|
});
|
|
|
|
|
2021-10-29 08:14:45 -04:00
|
|
|
describe.each`
|
2022-01-26 10:12:36 -05:00
|
|
|
index | identifier | value | label
|
|
|
|
${0} | ${metricsData[0].identifier} | ${metricsData[0].value} | ${metricsData[0].title}
|
|
|
|
${1} | ${metricsData[1].identifier} | ${metricsData[1].value} | ${metricsData[1].title}
|
|
|
|
${2} | ${metricsData[2].identifier} | ${metricsData[2].value} | ${metricsData[2].title}
|
|
|
|
${3} | ${metricsData[3].identifier} | ${metricsData[3].value} | ${metricsData[3].title}
|
|
|
|
`('metric tiles', ({ identifier, index, value, label }) => {
|
|
|
|
it(`renders a metric tile component for "${label}"`, () => {
|
2021-08-16 08:09:17 -04:00
|
|
|
const metric = findMetrics().at(index);
|
2022-01-26 10:12:36 -05:00
|
|
|
expect(metric.props('metric')).toMatchObject({ identifier, value, label });
|
2021-11-01 05:13:14 -04:00
|
|
|
expect(metric.isVisible()).toBe(true);
|
2021-10-29 08:14:45 -04:00
|
|
|
});
|
|
|
|
});
|
2021-08-16 08:09:17 -04:00
|
|
|
|
|
|
|
it('will not display a loading icon', () => {
|
2022-05-30 11:08:03 -04:00
|
|
|
expect(wrapper.findComponent(GlSkeletonLoader).exists()).toBe(false);
|
2021-08-16 08:09:17 -04:00
|
|
|
});
|
|
|
|
|
2022-02-02 10:17:50 -05:00
|
|
|
describe('filterFn', () => {
|
2022-02-28 07:15:45 -05:00
|
|
|
const transferredMetricsData = prepareTimeMetricsData(metricsData, METRICS_POPOVER_CONTENT);
|
2022-02-02 10:17:50 -05:00
|
|
|
|
|
|
|
it('with a filter function, will call the function with the metrics data', async () => {
|
|
|
|
const filteredData = [
|
|
|
|
{ identifier: 'issues', value: '3', title: 'New Issues', description: 'foo' },
|
|
|
|
];
|
|
|
|
mockFilterFn = jest.fn(() => filteredData);
|
|
|
|
|
|
|
|
wrapper = createComponent({
|
|
|
|
filterFn: mockFilterFn,
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
2022-02-28 07:15:45 -05:00
|
|
|
expect(mockFilterFn).toHaveBeenCalledWith(transferredMetricsData);
|
2022-02-02 10:17:50 -05:00
|
|
|
expect(wrapper.vm.metrics).toEqual(filteredData);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('without a filter function, it will only update the metrics', async () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(mockFilterFn).not.toHaveBeenCalled();
|
2022-02-28 07:15:45 -05:00
|
|
|
expect(wrapper.vm.metrics).toEqual(transferredMetricsData);
|
2022-02-02 10:17:50 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-08-16 08:09:17 -04:00
|
|
|
describe('with additional params', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
requestParams: {
|
|
|
|
'project_ids[]': [1],
|
|
|
|
created_after: '2020-01-01',
|
|
|
|
created_before: '2020-02-01',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fetches data for the `getValueStreamSummaryMetrics` request', () => {
|
|
|
|
expectToHaveRequest({
|
|
|
|
params: {
|
|
|
|
'project_ids[]': [1],
|
|
|
|
created_after: '2020-01-01',
|
|
|
|
created_before: '2020-02-01',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-05-04 08:07:48 -04:00
|
|
|
|
|
|
|
describe('groupBy', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
mockGetValueStreamSummaryMetrics = jest.fn().mockResolvedValue({ data: metricsData });
|
|
|
|
wrapper = createComponent({ groupBy: VSA_METRICS_GROUPS });
|
|
|
|
await waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the metrics as separate groups', () => {
|
|
|
|
const groups = findMetricsGroups();
|
|
|
|
expect(groups).toHaveLength(VSA_METRICS_GROUPS.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders titles for each group', () => {
|
|
|
|
const groups = findMetricsGroups();
|
|
|
|
groups.wrappers.forEach((g, index) => {
|
|
|
|
const { title } = VSA_METRICS_GROUPS[index];
|
|
|
|
expect(g.html()).toContain(title);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-08-16 08:09:17 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a request failing', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
mockGetValueStreamSummaryMetrics = jest.fn().mockRejectedValue();
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('it should render an error message', () => {
|
|
|
|
expect(createFlash).toHaveBeenCalledWith({
|
|
|
|
message: `There was an error while fetching value stream analytics ${fakeReqName} data.`,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|