2019-12-26 22:10:19 +05:30
|
|
|
import Vuex from 'vuex';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { getJSONFixture } from 'helpers/fixtures';
|
|
|
|
import TestReports from '~/pipelines/components/test_reports/test_reports.vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
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);
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe('Test reports app', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
const testReports = getJSONFixture('pipelines/test_report.json');
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const loadingSpinner = () => wrapper.find('.js-loading-spinner');
|
|
|
|
const testsDetail = () => wrapper.find('.js-tests-detail');
|
|
|
|
const noTestsToShow = () => wrapper.find('.js-no-tests-to-show');
|
2020-07-28 23:09:34 +05:30
|
|
|
const testSummary = () => wrapper.find(TestSummary);
|
|
|
|
const testSummaryTable = () => wrapper.find(TestSummaryTable);
|
|
|
|
|
|
|
|
const actionSpies = {
|
2020-10-24 23:57:45 +05:30
|
|
|
fetchTestSuite: jest.fn(),
|
2020-07-28 23:09:34 +05:30
|
|
|
fetchSummary: jest.fn(),
|
|
|
|
setSelectedSuiteIndex: jest.fn(),
|
|
|
|
removeSelectedSuiteIndex: jest.fn(),
|
|
|
|
};
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
const createComponent = (state = {}) => {
|
|
|
|
store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
isLoading: false,
|
2020-07-28 23:09:34 +05:30
|
|
|
selectedSuiteIndex: null,
|
2019-12-26 22:10:19 +05:30
|
|
|
testReports,
|
|
|
|
...state,
|
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
actions: actionSpies,
|
|
|
|
getters,
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = shallowMount(TestReports, {
|
|
|
|
store,
|
2020-07-28 23:09:34 +05:30
|
|
|
localVue,
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe('when component is created', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call fetchSummary', () => {
|
|
|
|
expect(actionSpies.fetchSummary).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe('when a suite is clicked', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ hasFullReport: true });
|
|
|
|
testSummaryTable().vm.$emit('row-click', 0);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('should call setSelectedSuiteIndex and fetchTestSuite', () => {
|
|
|
|
expect(actionSpies.setSelectedSuiteIndex).toHaveBeenCalled();
|
|
|
|
expect(actionSpies.fetchTestSuite).toHaveBeenCalled();
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when clicking back to summary', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ selectedSuiteIndex: 0 });
|
|
|
|
testSummary().vm.$emit('on-back-click');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call removeSelectedSuiteIndex', () => {
|
|
|
|
expect(actionSpies.removeSelectedSuiteIndex).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|