summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/test_reports/test_summary_table_spec.js
blob: 0813739d72f7d5e24e61f69e26e9f89db165914b (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
import { mount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import testReports from 'test_fixtures/pipelines/test_report.json';
import SummaryTable from '~/pipelines/components/test_reports/test_summary_table.vue';
import * as getters from '~/pipelines/stores/test_reports/getters';

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

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

  const allSuitesRows = () => wrapper.findAll('.js-suite-row');
  const noSuitesToShow = () => wrapper.find('.js-no-tests-suites');

  const defaultProps = {
    testReports,
  };

  const createComponent = (reports = null) => {
    store = new Vuex.Store({
      state: {
        testReports: reports || testReports,
      },
      getters,
    });

    wrapper = mount(SummaryTable, {
      propsData: defaultProps,
      store,
      localVue,
    });
  };

  describe('when test reports are supplied', () => {
    beforeEach(() => createComponent());
    const findErrorIcon = () => wrapper.find({ ref: 'suiteErrorIcon' });

    it('renders the correct number of rows', () => {
      expect(noSuitesToShow().exists()).toBe(false);
      expect(allSuitesRows().length).toBe(testReports.test_suites.length);
    });

    describe('when there is a suite error', () => {
      beforeEach(() => {
        createComponent({
          test_suites: [
            {
              ...testReports.test_suites[0],
              suite_error: 'Suite Error',
            },
          ],
        });
      });

      it('renders error icon', () => {
        expect(findErrorIcon().exists()).toBe(true);
        expect(findErrorIcon().attributes('title')).toEqual('Suite Error');
      });
    });

    describe('when there is not a suite error', () => {
      beforeEach(() => {
        createComponent({
          test_suites: [
            {
              ...testReports.test_suites[0],
              suite_error: null,
            },
          ],
        });
      });

      it('does not render error icon', () => {
        expect(findErrorIcon().exists()).toBe(false);
      });
    });
  });

  describe('when there are no test suites', () => {
    beforeEach(() => {
      createComponent({ test_suites: [] });
    });

    it('displays the no suites to show message', () => {
      expect(noSuitesToShow().exists()).toBe(true);
    });
  });
});