summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/test_reports/test_suite_table_spec.js
blob: 793bad6b82aaca66dc26a9febc22066bda527f7f (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
import { GlButton, GlFriendlyWrap, GlLink, GlPagination } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import testReports from 'test_fixtures/pipelines/test_report.json';
import SuiteTable from '~/pipelines/components/test_reports/test_suite_table.vue';
import { TestStatus } from '~/pipelines/constants';
import * as getters from '~/pipelines/stores/test_reports/getters';
import { formatFilePath } from '~/pipelines/stores/test_reports/utils';
import skippedTestCases from './mock_data';

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

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

  const {
    test_suites: [testSuite],
  } = testReports;

  testSuite.test_cases = [...testSuite.test_cases, ...skippedTestCases];
  const testCases = testSuite.test_cases;
  const blobPath = '/test/blob/path';

  const noCasesMessage = () => wrapper.find('.js-no-test-cases');
  const allCaseRows = () => wrapper.findAll('.js-case-row');
  const findCaseRowAtIndex = (index) => wrapper.findAll('.js-case-row').at(index);
  const findLinkForRow = (row) => row.find(GlLink);
  const findIconForRow = (row, status) => row.find(`.ci-status-icon-${status}`);

  const createComponent = (suite = testSuite, perPage = 20) => {
    store = new Vuex.Store({
      state: {
        blobPath,
        testReports: {
          test_suites: [suite],
        },
        selectedSuiteIndex: 0,
        pageInfo: {
          page: 1,
          perPage,
        },
      },
      getters,
    });

    wrapper = shallowMount(SuiteTable, {
      store,
      localVue,
      stubs: { GlFriendlyWrap },
    });
  };

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

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

    it('a table when there are no test cases', () => {
      expect(noCasesMessage().exists()).toBe(true);
    });
  });

  describe('when a test suite is supplied', () => {
    beforeEach(() => createComponent());

    it('renders the correct number of rows', () => {
      expect(allCaseRows()).toHaveLength(testCases.length);
    });

    it.each([
      TestStatus.ERROR,
      TestStatus.FAILED,
      TestStatus.SKIPPED,
      TestStatus.SUCCESS,
      'unknown',
    ])('renders the correct icon for test case with %s status', (status) => {
      const test = testCases.findIndex((x) => x.status === status);
      const row = findCaseRowAtIndex(test);

      expect(findIconForRow(row, status).exists()).toBe(true);
    });

    it('renders the file name for the test with a copy button', () => {
      const { file } = testCases[0];
      const relativeFile = formatFilePath(file);
      const filePath = `${blobPath}/${relativeFile}`;
      const row = findCaseRowAtIndex(0);
      const fileLink = findLinkForRow(row);
      const button = row.find(GlButton);

      expect(fileLink.attributes('href')).toBe(filePath);
      expect(row.text()).toContain(file);
      expect(button.exists()).toBe(true);
      expect(button.attributes('data-clipboard-text')).toBe(file);
    });
  });

  describe('when a test suite has more test cases than the pagination size', () => {
    const perPage = 2;

    beforeEach(() => {
      createComponent(testSuite, perPage);
    });

    it('renders one page of test cases', () => {
      expect(allCaseRows().length).toBe(perPage);
    });

    it('renders a pagination component', () => {
      expect(wrapper.find(GlPagination).exists()).toBe(true);
    });
  });

  describe('when a test case classname property is null', () => {
    it('still renders all test cases', () => {
      createComponent({
        ...testSuite,
        test_cases: testSuite.test_cases.map((testCase) => ({
          ...testCase,
          classname: null,
        })),
      });

      expect(allCaseRows()).toHaveLength(testCases.length);
    });
  });

  describe('when a test case name property is null', () => {
    it('still renders all test cases', () => {
      createComponent({
        ...testSuite,
        test_cases: testSuite.test_cases.map((testCase) => ({
          ...testCase,
          name: null,
        })),
      });

      expect(allCaseRows()).toHaveLength(testCases.length);
    });
  });
});