diff options
Diffstat (limited to 'spec/frontend/pipelines/test_reports/test_reports_spec.js')
-rw-r--r-- | spec/frontend/pipelines/test_reports/test_reports_spec.js | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/spec/frontend/pipelines/test_reports/test_reports_spec.js b/spec/frontend/pipelines/test_reports/test_reports_spec.js index cc86ba6d46d..ef0bcffabe3 100644 --- a/spec/frontend/pipelines/test_reports/test_reports_spec.js +++ b/spec/frontend/pipelines/test_reports/test_reports_spec.js @@ -1,8 +1,13 @@ import Vuex from 'vuex'; -import { shallowMount } from '@vue/test-utils'; +import { shallowMount, createLocalVue } from '@vue/test-utils'; import { getJSONFixture } from 'helpers/fixtures'; import TestReports from '~/pipelines/components/test_reports/test_reports.vue'; -import * as actions from '~/pipelines/stores/test_reports/actions'; +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; @@ -13,20 +18,31 @@ describe('Test reports app', () => { 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, - selectedSuite: {}, + selectedSuiteIndex: null, testReports, ...state, }, - actions, + actions: actionSpies, + getters, }); wrapper = shallowMount(TestReports, { store, + localVue, }); }; @@ -34,6 +50,16 @@ describe('Test reports app', () => { wrapper.destroy(); }); + describe('when component is created', () => { + beforeEach(() => { + createComponent(); + }); + + it('should call fetchSummary', () => { + expect(actionSpies.fetchSummary).toHaveBeenCalled(); + }); + }); + describe('when loading', () => { beforeEach(() => createComponent({ isLoading: true })); @@ -63,4 +89,41 @@ describe('Test reports app', () => { 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(); + }); + }); }); |