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

test_summary_spec.js « test_reports « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc5af7b160cd0d85a22e32f22da6e104bd4d2f39 (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
import { mount } from '@vue/test-utils';
import { getJSONFixture } from 'helpers/fixtures';
import Summary from '~/pipelines/components/test_reports/test_summary.vue';
import { formattedTime } from '~/pipelines/stores/test_reports/utils';

describe('Test reports summary', () => {
  let wrapper;

  const {
    test_suites: [testSuite],
  } = getJSONFixture('pipelines/test_report.json');

  const backButton = () => wrapper.find('.js-back-button');
  const totalTests = () => wrapper.find('.js-total-tests');
  const failedTests = () => wrapper.find('.js-failed-tests');
  const erroredTests = () => wrapper.find('.js-errored-tests');
  const successRate = () => wrapper.find('.js-success-rate');
  const duration = () => wrapper.find('.js-duration');

  const defaultProps = {
    report: testSuite,
    showBack: false,
  };

  const createComponent = props => {
    wrapper = mount(Summary, {
      propsData: {
        ...defaultProps,
        ...props,
      },
    });
  };

  describe('should not render', () => {
    beforeEach(() => {
      createComponent();
    });

    it('a back button by default', () => {
      expect(backButton().exists()).toBe(false);
    });
  });

  describe('should render', () => {
    beforeEach(() => {
      createComponent();
    });

    it('a back button and emit on-back-click event', () => {
      createComponent({
        showBack: true,
      });

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

  describe('when a report is supplied', () => {
    beforeEach(() => {
      createComponent();
    });

    it('displays the correct total', () => {
      expect(totalTests().text()).toBe('4 tests');
    });

    it('displays the correct failure count', () => {
      expect(failedTests().text()).toBe('2 failures');
    });

    it('displays the correct error count', () => {
      expect(erroredTests().text()).toBe('0 errors');
    });

    it('calculates and displays percentages correctly', () => {
      expect(successRate().text()).toBe('50% success rate');
    });

    it('displays the correctly formatted duration', () => {
      expect(duration().text()).toBe(formattedTime(testSuite.total_time));
    });
  });

  describe('success percentage calculation', () => {
    it.each`
      name                                     | successCount | totalCount | skippedCount | result
      ${'displays 0 when there are no tests'}  | ${0}         | ${0}       | ${0}         | ${'0'}
      ${'displays whole number when possible'} | ${10}        | ${50}      | ${0}         | ${'20'}
      ${'excludes skipped tests from total'}   | ${10}        | ${50}      | ${5}         | ${'22.22'}
      ${'rounds to 0.01'}                      | ${1}         | ${16604}   | ${0}         | ${'0.01'}
      ${'correctly rounds to 50'}              | ${8302}      | ${16604}   | ${0}         | ${'50'}
      ${'rounds down for large close numbers'} | ${16603}     | ${16604}   | ${0}         | ${'99.99'}
      ${'correctly displays 100'}              | ${16604}     | ${16604}   | ${0}         | ${'100'}
    `('$name', ({ successCount, totalCount, skippedCount, result }) => {
      createComponent({
        report: {
          success_count: successCount,
          skipped_count: skippedCount,
          total_count: totalCount,
        },
      });

      expect(successRate().text()).toBe(`${result}% success rate`);
    });
  });
});