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

grouped_test_reports_app_spec.js « grouped_test_report « reports « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c60c1f7b63c5225a667f79af1280d5c6317f9cbf (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import { mount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import Api from '~/api';
import GroupedTestReportsApp from '~/reports/grouped_test_report/grouped_test_reports_app.vue';
import { getStoreConfig } from '~/reports/grouped_test_report/store';

import { failedReport } from '../mock_data/mock_data';
import mixedResultsTestReports from '../mock_data/new_and_fixed_failures_report.json';
import newErrorsTestReports from '../mock_data/new_errors_report.json';
import newFailedTestReports from '../mock_data/new_failures_report.json';
import successTestReports from '../mock_data/no_failures_report.json';
import recentFailuresTestReports from '../mock_data/recent_failures_report.json';
import resolvedFailures from '../mock_data/resolved_failures.json';

jest.mock('~/api.js');

const localVue = createLocalVue();
localVue.use(Vuex);

describe('Grouped test reports app', () => {
  const endpoint = 'endpoint.json';
  const headBlobPath = '/blob/path';
  const pipelinePath = '/path/to/pipeline';
  let wrapper;
  let mockStore;

  const mountComponent = ({ props = { pipelinePath } } = {}) => {
    wrapper = mount(GroupedTestReportsApp, {
      store: mockStore,
      localVue,
      propsData: {
        endpoint,
        headBlobPath,
        pipelinePath,
        ...props,
      },
    });
  };

  const setReports = (reports) => {
    mockStore.state.status = reports.status;
    mockStore.state.summary = reports.summary;
    mockStore.state.reports = reports.suites;
  };

  const findHeader = () => wrapper.find('[data-testid="report-section-code-text"]');
  const findExpandButton = () => wrapper.find('[data-testid="report-section-expand-button"]');
  const findFullTestReportLink = () => wrapper.find('[data-testid="group-test-reports-full-link"]');
  const findSummaryDescription = () => wrapper.find('[data-testid="summary-row-description"]');
  const findIssueListUnresolvedHeading = () => wrapper.find('[data-testid="unresolvedHeading"]');
  const findIssueListResolvedHeading = () => wrapper.find('[data-testid="resolvedHeading"]');
  const findIssueDescription = () => wrapper.find('[data-testid="test-issue-body-description"]');
  const findIssueRecentFailures = () =>
    wrapper.find('[data-testid="test-issue-body-recent-failures"]');
  const findAllIssueDescriptions = () =>
    wrapper.findAll('[data-testid="test-issue-body-description"]');

  beforeEach(() => {
    mockStore = new Vuex.Store({
      ...getStoreConfig(),
      actions: {
        fetchReports: () => {},
        setPaths: () => {},
      },
    });
    mountComponent();
  });

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

  describe('with success result', () => {
    beforeEach(() => {
      setReports(successTestReports);
      mountComponent();
    });

    it('renders success summary text', () => {
      expect(findHeader().text()).toBe(
        'Test summary contained no changed test results out of 11 total tests',
      );
    });
  });

  describe('`View full report` button', () => {
    it('should render the full test report link', () => {
      const fullTestReportLink = findFullTestReportLink();

      expect(fullTestReportLink.exists()).toBe(true);
      expect(pipelinePath).not.toBe('');
      expect(fullTestReportLink.attributes('href')).toBe(`${pipelinePath}/test_report`);
    });

    describe('Without a pipelinePath', () => {
      beforeEach(() => {
        mountComponent({
          props: { pipelinePath: '' },
        });
      });

      it('should not render the full test report link', () => {
        expect(findFullTestReportLink().exists()).toBe(false);
      });
    });
  });

  describe('`Expand` button', () => {
    beforeEach(() => {
      setReports(newFailedTestReports);
    });

    it('tracks service ping metric', () => {
      mountComponent();
      findExpandButton().trigger('click');

      expect(Api.trackRedisHllUserEvent).toHaveBeenCalledTimes(1);
      expect(Api.trackRedisHllUserEvent).toHaveBeenCalledWith(wrapper.vm.$options.expandEvent);
    });

    it('only tracks the first expansion', () => {
      mountComponent();
      const expandButton = findExpandButton();
      expandButton.trigger('click');
      expandButton.trigger('click');
      expandButton.trigger('click');

      expect(Api.trackRedisHllUserEvent).toHaveBeenCalledTimes(1);
    });
  });

  describe('with new failed result', () => {
    beforeEach(() => {
      setReports(newFailedTestReports);
      mountComponent();
    });

    it('renders New heading', () => {
      expect(findIssueListUnresolvedHeading().text()).toBe('New');
    });

    it('renders failed summary text', () => {
      expect(findHeader().text()).toBe('Test summary contained 2 failed out of 11 total tests');
    });

    it('renders failed test suite', () => {
      expect(findSummaryDescription().text()).toContain(
        'rspec:pg found 2 failed out of 8 total tests',
      );
    });

    it('renders failed issue in list', () => {
      expect(findIssueDescription().text()).toContain(
        'Test#sum when a is 1 and b is 2 returns summary',
      );
    });
  });

  describe('with new error result', () => {
    beforeEach(() => {
      setReports(newErrorsTestReports);
      mountComponent();
    });

    it('renders New heading', () => {
      expect(findIssueListUnresolvedHeading().text()).toBe('New');
    });

    it('renders error summary text', () => {
      expect(findHeader().text()).toBe('Test summary contained 2 errors out of 11 total tests');
    });

    it('renders error test suite', () => {
      expect(findSummaryDescription().text()).toContain(
        'karma found 2 errors out of 3 total tests',
      );
    });

    it('renders error issue in list', () => {
      expect(findIssueDescription().text()).toContain(
        'Test#sum when a is 1 and b is 2 returns summary',
      );
    });
  });

  describe('with mixed results', () => {
    beforeEach(() => {
      setReports(mixedResultsTestReports);
      mountComponent();
    });

    it('renders New and Fixed headings', () => {
      expect(findIssueListUnresolvedHeading().text()).toBe('New');
      expect(findIssueListResolvedHeading().text()).toBe('Fixed');
    });

    it('renders summary text', () => {
      expect(findHeader().text()).toBe(
        'Test summary contained 2 failed and 2 fixed test results out of 11 total tests',
      );
    });

    it('renders failed test suite', () => {
      expect(findSummaryDescription().text()).toContain(
        'rspec:pg found 1 failed and 2 fixed test results out of 8 total tests',
      );
    });

    it('renders failed issue in list', () => {
      expect(findIssueDescription().text()).toContain(
        'Test#subtract when a is 2 and b is 1 returns correct result',
      );
    });
  });

  describe('with resolved failures and resolved errors', () => {
    beforeEach(() => {
      setReports(resolvedFailures);
      mountComponent();
    });

    it('renders Fixed heading', () => {
      expect(findIssueListResolvedHeading().text()).toBe('Fixed');
    });

    it('renders summary text', () => {
      expect(findHeader().text()).toBe(
        'Test summary contained 4 fixed test results out of 11 total tests',
      );
    });

    it('renders resolved test suite', () => {
      expect(findSummaryDescription().text()).toContain(
        'rspec:pg found 4 fixed test results out of 8 total tests',
      );
    });

    it('renders resolved failures', () => {
      expect(findIssueDescription().text()).toContain(
        resolvedFailures.suites[0].resolved_failures[0].name,
      );
    });

    it('renders resolved errors', () => {
      expect(findAllIssueDescriptions().at(2).text()).toContain(
        resolvedFailures.suites[0].resolved_errors[0].name,
      );
    });
  });

  describe('recent failures counts', () => {
    describe('with recent failures counts', () => {
      beforeEach(() => {
        setReports(recentFailuresTestReports);
        mountComponent();
      });

      it('renders the recently failed tests summary', () => {
        expect(findHeader().text()).toContain(
          '2 out of 3 failed tests have failed more than once in the last 14 days',
        );
      });

      it('renders the recently failed count on the test suite', () => {
        expect(findSummaryDescription().text()).toContain(
          '1 out of 2 failed tests has failed more than once in the last 14 days',
        );
      });

      it('renders the recent failures count on the test case', () => {
        expect(findIssueRecentFailures().text()).toBe('Failed 8 times in main in the last 14 days');
      });
    });

    describe('without recent failures counts', () => {
      beforeEach(() => {
        setReports(mixedResultsTestReports);
        mountComponent();
      });

      it('does not render the recently failed tests summary', () => {
        expect(findHeader().text()).not.toContain('failed more than once in the last 14 days');
      });

      it('does not render the recently failed count on the test suite', () => {
        expect(findSummaryDescription().text()).not.toContain(
          'failed more than once in the last 14 days',
        );
      });

      it('does not render the recent failures count on the test case', () => {
        expect(findIssueDescription().text()).not.toContain('in the last 14 days');
      });
    });
  });

  describe('with a report that failed to load', () => {
    beforeEach(() => {
      setReports(failedReport);
      mountComponent();
    });

    it('renders an error status for the report', () => {
      const { name } = failedReport.suites[0];

      expect(findSummaryDescription().text()).toContain(
        `An error occurred while loading ${name} result`,
      );
    });
  });

  describe('with a report parsing errors', () => {
    beforeEach(() => {
      const reports = failedReport;
      reports.suites[0].suite_errors = {
        head: 'JUnit XML parsing failed: 2:24: FATAL: attributes construct error',
        base: 'JUnit data parsing failed: string not matched',
      };
      setReports(reports);
      mountComponent();
    });

    it('renders the error messages', () => {
      expect(findSummaryDescription().text()).toContain(
        'JUnit XML parsing failed: 2:24: FATAL: attributes construct error',
      );
      expect(findSummaryDescription().text()).toContain(
        'JUnit data parsing failed: string not matched',
      );
    });
  });

  describe('with error', () => {
    beforeEach(() => {
      mockStore.state.isLoading = false;
      mockStore.state.hasError = true;
      mountComponent();
    });

    it('renders loading state', () => {
      expect(findHeader().text()).toBe('Test summary failed loading results');
    });
  });

  describe('while loading', () => {
    beforeEach(() => {
      mockStore.state.isLoading = true;
      mountComponent();
    });

    it('renders loading state', () => {
      expect(findHeader().text()).toBe('Test summary results are being parsed');
    });
  });
});