Welcome to mirror list, hosted at ThFree Co, Russian Federation.

performance_insights_modal_spec.js « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c802be77184e210e79e6a51a2ce7aef2211bed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { GlAlert, GlLink, GlModal } from '@gitlab/ui';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import waitForPromises from 'helpers/wait_for_promises';
import PerformanceInsightsModal from '~/pipelines/components/performance_insights_modal.vue';
import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { trimText } from 'helpers/text_helper';
import getPerformanceInsights from '~/pipelines/graphql/queries/get_performance_insights.query.graphql';
import {
  mockPerformanceInsightsResponse,
  mockPerformanceInsightsNextPageResponse,
} from './graph/mock_data';

Vue.use(VueApollo);

describe('Performance insights modal', () => {
  let wrapper;

  const findModal = () => wrapper.findComponent(GlModal);
  const findAlert = () => wrapper.findComponent(GlAlert);
  const findLink = () => wrapper.findComponent(GlLink);
  const findLimitText = () => wrapper.findByTestId('limit-alert-text');
  const findQueuedCardData = () => wrapper.findByTestId('insights-queued-card-data');
  const findQueuedCardLink = () => wrapper.findByTestId('insights-queued-card-link');
  const findExecutedCardData = () => wrapper.findByTestId('insights-executed-card-data');
  const findExecutedCardLink = () => wrapper.findByTestId('insights-executed-card-link');
  const findSlowJobsStage = (index) => wrapper.findAllByTestId('insights-slow-job-stage').at(index);
  const findSlowJobsLink = (index) => wrapper.findAllByTestId('insights-slow-job-link').at(index);

  const getPerformanceInsightsHandler = jest
    .fn()
    .mockResolvedValue(mockPerformanceInsightsResponse);

  const getPerformanceInsightsNextPageHandler = jest
    .fn()
    .mockResolvedValue(mockPerformanceInsightsNextPageResponse);

  const requestHandlers = [[getPerformanceInsights, getPerformanceInsightsHandler]];

  const createComponent = (handlers = requestHandlers) => {
    wrapper = shallowMountExtended(PerformanceInsightsModal, {
      provide: {
        pipelineIid: '1',
        pipelineProjectPath: 'root/ci-project',
      },
      apolloProvider: createMockApollo(handlers),
    });
  };

  afterEach(() => {
    wrapper.destroy();
  });

  describe('without next page', () => {
    beforeEach(async () => {
      createComponent();

      await waitForPromises();
    });

    it('displays modal', () => {
      expect(findModal().exists()).toBe(true);
    });

    it('displays alert', () => {
      expect(findAlert().exists()).toBe(true);
    });

    it('displays feedback issue link', () => {
      expect(findLink().text()).toBe('Feedback issue');
      expect(findLink().attributes('href')).toBe(
        'https://gitlab.com/gitlab-org/gitlab/-/issues/365902',
      );
    });

    it('does not display limit text', () => {
      expect(findLimitText().exists()).toBe(false);
    });

    describe('queued duration card', () => {
      it('displays card data', () => {
        expect(trimText(findQueuedCardData().text())).toBe('4.9 days');
      });
      it('displays card link', () => {
        expect(findQueuedCardLink().attributes('href')).toBe(
          '/root/lots-of-jobs-project/-/pipelines/98',
        );
      });
    });

    describe('executed duration card', () => {
      it('displays card data', () => {
        expect(trimText(findExecutedCardData().text())).toBe('trigger_job');
      });
      it('displays card link', () => {
        expect(findExecutedCardLink().attributes('href')).toBe(
          '/root/lots-of-jobs-project/-/pipelines/98',
        );
      });
    });

    describe('slow jobs', () => {
      it.each`
        index | expectedStage | expectedName                | expectedLink
        ${0}  | ${'build'}    | ${'wait_job'}               | ${'/root/ci-project/-/jobs/2493'}
        ${1}  | ${'deploy'}   | ${'artifact_job'}           | ${'/root/ci-project/-/jobs/2501'}
        ${2}  | ${'test'}     | ${'allow_failure_test_job'} | ${'/root/ci-project/-/jobs/2497'}
        ${3}  | ${'build'}    | ${'large_log_output'}       | ${'/root/ci-project/-/jobs/2495'}
        ${4}  | ${'build'}    | ${'build_job'}              | ${'/root/ci-project/-/jobs/2494'}
      `(
        'should display slow job correctly',
        ({ index, expectedStage, expectedName, expectedLink }) => {
          expect(findSlowJobsStage(index).text()).toBe(expectedStage);
          expect(findSlowJobsLink(index).text()).toBe(expectedName);
          expect(findSlowJobsLink(index).attributes('href')).toBe(expectedLink);
        },
      );
    });
  });

  describe('with next page', () => {
    it('displays limit text when there is a next page', async () => {
      createComponent([[getPerformanceInsights, getPerformanceInsightsNextPageHandler]]);

      await waitForPromises();

      expect(findLimitText().exists()).toBe(true);
    });
  });
});