doraMetricsRequest: mockDoraMetricsResponse()

in ee/spec/frontend/analytics/dashboards/ai_impact/components/metric_table_spec.js [290:429]


            doraMetricsRequest: mockDoraMetricsResponse(mockTableZeroValues),
          }),
        });
      });

      it('renders n/a instead of a percentage', () => {
        expect(findMetricNoChangeLabel(deploymentFrequencyTestId).text()).toBe('0.0%');
      });

      it('renders a tooltip on the change cell', () => {
        expect(findMetricNoChangeTooltip(deploymentFrequencyTestId).value).toBe('No change');
      });
    });

    describe('when there is a change', () => {
      beforeEach(() => {
        return createWrapper();
      });

      it('does not invert the trend indicator for ascending metrics', () => {
        expect(findTrendIndicator(deploymentFrequencyTestId).props().change).toBe(1);
        expect(findTrendIndicator(deploymentFrequencyTestId).props().invertColor).toBe(false);
      });

      it('inverts the trend indicator for declining metrics', () => {
        expect(findTrendIndicator(changeFailureRateTestId).props().change).toBe(1);
        expect(findTrendIndicator(changeFailureRateTestId).props().invertColor).toBe(true);
      });
    });
  });

  describe('metric tooltips', () => {
    const hoverClasses = ['gl-cursor-pointer', 'hover:gl-underline'];

    beforeEach(() => {
      return createWrapper();
    });

    it('adds hover class and tooltip to code suggestions metric', () => {
      const metricCell = findValueTableCells(codeSuggestionsUsageRateTestId).at(0);
      const metricValue = metricCell.find('[data-testid="formatted-metric-value"]');

      expect(metricCell.findComponent(GlTooltip).exists()).toBe(true);
      expect(metricValue.classes().some((c) => hoverClasses.includes(c))).toBe(true);
    });

    it('does not add hover class and tooltip to other metrics', () => {
      const metricCell = findValueTableCells(leadTimeTestId).at(0);
      const metricValue = metricCell.find('[data-testid="formatted-metric-value"]');

      expect(metricCell.findComponent(GlTooltip).exists()).toBe(false);
      expect(metricValue.classes().some((c) => hoverClasses.includes(c))).toBe(false);
    });
  });

  describe('restricted metrics', () => {
    beforeEach(() => {
      return createWrapper({
        glAbilities: { readDora4Analytics: false },
      });
    });

    it.each([deploymentFrequencyTestId, changeFailureRateTestId])(
      'does not render the `%s` metric',
      (testId) => {
        expect(findTableRow(testId).exists()).toBe(false);
      },
    );

    it('emits `set-alerts` warning with the restricted metrics', () => {
      expect(wrapper.emitted('set-alerts').length).toBe(1);
      expect(wrapper.emitted('set-alerts')[0][0]).toEqual({
        canRetry: false,
        warnings: [],
        alerts: expect.arrayContaining([
          'You have insufficient permissions to view: Deployment frequency, Change failure rate',
        ]),
      });
    });
  });

  describe('excludeMetrics set', () => {
    const flowMetricsRequest = jest.fn().mockImplementation(() => Promise.resolve());
    const doraMetricsRequest = jest.fn().mockImplementation(() => Promise.resolve());
    const vulnerabilityMetricsRequest = jest.fn().mockImplementation(() => Promise.resolve());
    const aiMetricsRequest = jest.fn().mockImplementation(() => Promise.resolve());
    let apolloProvider;

    beforeEach(() => {
      apolloProvider = createMockApolloProvider({
        flowMetricsRequest,
        doraMetricsRequest,
        vulnerabilityMetricsRequest,
        aiMetricsRequest,
      });
    });

    describe.each([
      {
        group: 'DORA metrics',
        excludeMetrics: SUPPORTED_DORA_METRICS,
        testIds: [deploymentFrequencyTestId, changeFailureRateTestId],
        apiRequest: doraMetricsRequest,
      },
      {
        group: 'Flow metrics',
        excludeMetrics: SUPPORTED_FLOW_METRICS,
        testIds: [cycleTimeTestId, leadTimeTestId],
        apiRequest: flowMetricsRequest,
      },
      {
        group: 'Vulnerability metrics',
        excludeMetrics: SUPPORTED_VULNERABILITY_METRICS,
        testIds: [vulnerabilityCriticalTestId],
        apiRequest: vulnerabilityMetricsRequest,
      },
      {
        group: 'AI metrics',
        excludeMetrics: SUPPORTED_AI_METRICS,
        testIds: [codeSuggestionsUsageRateTestId],
        apiRequest: aiMetricsRequest,
      },
    ])('for $group', ({ excludeMetrics, testIds, apiRequest }) => {
      describe('when all metrics excluded', () => {
        beforeEach(() => {
          return createWrapper({ apolloProvider, props: { excludeMetrics } });
        });

        it.each(testIds)('does not render `%s`', (id) => {
          expect(findTableRow(id).exists()).toBe(false);
        });

        it('does not send a request', () => {
          expect(apiRequest).not.toHaveBeenCalled();
        });
      });

      describe('when almost all metrics excluded', () => {
        beforeEach(() => {
          return createWrapper({