summaryrefslogtreecommitdiff
path: root/spec/frontend/cycle_analytics/value_stream_metrics_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/cycle_analytics/value_stream_metrics_spec.js')
-rw-r--r--spec/frontend/cycle_analytics/value_stream_metrics_spec.js58
1 files changed, 44 insertions, 14 deletions
diff --git a/spec/frontend/cycle_analytics/value_stream_metrics_spec.js b/spec/frontend/cycle_analytics/value_stream_metrics_spec.js
index ffdb49a828c..c97e4845bc2 100644
--- a/spec/frontend/cycle_analytics/value_stream_metrics_spec.js
+++ b/spec/frontend/cycle_analytics/value_stream_metrics_spec.js
@@ -1,13 +1,16 @@
import { GlDeprecatedSkeletonLoading as GlSkeletonLoading } from '@gitlab/ui';
import { GlSingleStat } from '@gitlab/ui/dist/charts';
import { shallowMount } from '@vue/test-utils';
+import metricsData from 'test_fixtures/projects/analytics/value_stream_analytics/summary.json';
import waitForPromises from 'helpers/wait_for_promises';
import { METRIC_TYPE_SUMMARY } from '~/api/analytics_api';
import ValueStreamMetrics from '~/cycle_analytics/components/value_stream_metrics.vue';
import createFlash from '~/flash';
-import { group, metricsData } from './mock_data';
+import { redirectTo } from '~/lib/utils/url_utility';
+import { group } from './mock_data';
jest.mock('~/flash');
+jest.mock('~/lib/utils/url_utility');
describe('ValueStreamMetrics', () => {
let wrapper;
@@ -43,7 +46,6 @@ describe('ValueStreamMetrics', () => {
afterEach(() => {
wrapper.destroy();
- wrapper = null;
});
describe('with successful requests', () => {
@@ -55,7 +57,23 @@ describe('ValueStreamMetrics', () => {
it('will display a loader with pending requests', async () => {
await wrapper.vm.$nextTick();
- expect(wrapper.find(GlSkeletonLoading).exists()).toBe(true);
+ expect(wrapper.findComponent(GlSkeletonLoading).exists()).toBe(true);
+ });
+
+ it('renders hidden GlSingleStat components for each metric', async () => {
+ await waitForPromises();
+
+ wrapper.setData({ isLoading: true });
+
+ await wrapper.vm.$nextTick();
+
+ const components = findMetrics();
+
+ expect(components).toHaveLength(metricsData.length);
+
+ metricsData.forEach((metric, index) => {
+ expect(components.at(index).isVisible()).toBe(false);
+ });
});
describe('with data loaded', () => {
@@ -67,19 +85,31 @@ describe('ValueStreamMetrics', () => {
expectToHaveRequest({ params: {} });
});
- it.each`
- index | value | title | unit
- ${0} | ${metricsData[0].value} | ${metricsData[0].title} | ${metricsData[0].unit}
- ${1} | ${metricsData[1].value} | ${metricsData[1].title} | ${metricsData[1].unit}
- ${2} | ${metricsData[2].value} | ${metricsData[2].title} | ${metricsData[2].unit}
- ${3} | ${metricsData[3].value} | ${metricsData[3].title} | ${metricsData[3].unit}
- `(
- 'renders a single stat component for the $title with value and unit',
- ({ index, value, title, unit }) => {
+ describe.each`
+ index | value | title | unit | clickable
+ ${0} | ${metricsData[0].value} | ${metricsData[0].title} | ${metricsData[0].unit} | ${false}
+ ${1} | ${metricsData[1].value} | ${metricsData[1].title} | ${metricsData[1].unit} | ${false}
+ ${2} | ${metricsData[2].value} | ${metricsData[2].title} | ${metricsData[2].unit} | ${false}
+ ${3} | ${metricsData[3].value} | ${metricsData[3].title} | ${metricsData[3].unit} | ${true}
+ `('metric tiles', ({ index, value, title, unit, clickable }) => {
+ it(`renders a single stat component for "${title}" with value and unit`, () => {
const metric = findMetrics().at(index);
expect(metric.props()).toMatchObject({ value, title, unit: unit ?? '' });
- },
- );
+ expect(metric.isVisible()).toBe(true);
+ });
+
+ it(`${
+ clickable ? 'redirects' : "doesn't redirect"
+ } when the user clicks the "${title}" metric`, () => {
+ const metric = findMetrics().at(index);
+ metric.vm.$emit('click');
+ if (clickable) {
+ expect(redirectTo).toHaveBeenCalledWith(metricsData[index].links[0].url);
+ } else {
+ expect(redirectTo).not.toHaveBeenCalled();
+ }
+ });
+ });
it('will not display a loading icon', () => {
expect(wrapper.find(GlSkeletonLoading).exists()).toBe(false);