summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/test_reports/test_reports_spec.js
blob: ef0bcffabe3047a498750f7291e4f82cc6023ac9 (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
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { getJSONFixture } from 'helpers/fixtures';
import TestReports from '~/pipelines/components/test_reports/test_reports.vue';
import TestSummary from '~/pipelines/components/test_reports/test_summary.vue';
import TestSummaryTable 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 app', () => {
  let wrapper;
  let store;

  const testReports = getJSONFixture('pipelines/test_report.json');

  const loadingSpinner = () => wrapper.find('.js-loading-spinner');
  const testsDetail = () => wrapper.find('.js-tests-detail');
  const noTestsToShow = () => wrapper.find('.js-no-tests-to-show');
  const testSummary = () => wrapper.find(TestSummary);
  const testSummaryTable = () => wrapper.find(TestSummaryTable);

  const actionSpies = {
    fetchFullReport: jest.fn(),
    fetchSummary: jest.fn(),
    setSelectedSuiteIndex: jest.fn(),
    removeSelectedSuiteIndex: jest.fn(),
  };

  const createComponent = (state = {}) => {
    store = new Vuex.Store({
      state: {
        isLoading: false,
        selectedSuiteIndex: null,
        testReports,
        ...state,
      },
      actions: actionSpies,
      getters,
    });

    wrapper = shallowMount(TestReports, {
      store,
      localVue,
    });
  };

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

  describe('when component is created', () => {
    beforeEach(() => {
      createComponent();
    });

    it('should call fetchSummary', () => {
      expect(actionSpies.fetchSummary).toHaveBeenCalled();
    });
  });

  describe('when loading', () => {
    beforeEach(() => createComponent({ isLoading: true }));

    it('shows the loading spinner', () => {
      expect(noTestsToShow().exists()).toBe(false);
      expect(testsDetail().exists()).toBe(false);
      expect(loadingSpinner().exists()).toBe(true);
    });
  });

  describe('when the api returns no data', () => {
    beforeEach(() => createComponent({ testReports: {} }));

    it('displays that there are no tests to show', () => {
      const noTests = noTestsToShow();

      expect(noTests.exists()).toBe(true);
      expect(noTests.text()).toBe('There are no tests to show.');
    });
  });

  describe('when the api returns data', () => {
    beforeEach(() => createComponent());

    it('sets testReports and shows tests', () => {
      expect(wrapper.vm.testReports).toBeTruthy();
      expect(wrapper.vm.showTests).toBeTruthy();
    });
  });

  describe('when a suite is clicked', () => {
    describe('when the full test report has already been received', () => {
      beforeEach(() => {
        createComponent({ hasFullReport: true });
        testSummaryTable().vm.$emit('row-click', 0);
      });

      it('should only call setSelectedSuiteIndex', () => {
        expect(actionSpies.setSelectedSuiteIndex).toHaveBeenCalled();
        expect(actionSpies.fetchFullReport).not.toHaveBeenCalled();
      });
    });

    describe('when the full test report has not been received', () => {
      beforeEach(() => {
        createComponent({ hasFullReport: false });
        testSummaryTable().vm.$emit('row-click', 0);
      });

      it('should call setSelectedSuiteIndex and fetchFullReport', () => {
        expect(actionSpies.setSelectedSuiteIndex).toHaveBeenCalled();
        expect(actionSpies.fetchFullReport).toHaveBeenCalled();
      });
    });
  });

  describe('when clicking back to summary', () => {
    beforeEach(() => {
      createComponent({ selectedSuiteIndex: 0 });
      testSummary().vm.$emit('on-back-click');
    });

    it('should call removeSelectedSuiteIndex', () => {
      expect(actionSpies.removeSelectedSuiteIndex).toHaveBeenCalled();
    });
  });
});