debian-mirror-gitlab/spec/frontend/pipelines/test_reports/test_reports_spec.js

120 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2020-07-28 23:09:34 +05:30
import { shallowMount, createLocalVue } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2020-01-01 13:55:28 +05:30
import { getJSONFixture } from 'helpers/fixtures';
2021-06-08 01:23:25 +05:30
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import EmptyState from '~/pipelines/components/test_reports/empty_state.vue';
2020-01-01 13:55:28 +05:30
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');
2021-06-08 01:23:25 +05:30
const loadingSpinner = () => wrapper.findComponent(GlLoadingIcon);
const testsDetail = () => wrapper.findByTestId('tests-detail');
const emptyState = () => wrapper.findComponent(EmptyState);
const testSummary = () => wrapper.findComponent(TestSummary);
const testSummaryTable = () => wrapper.findComponent(TestSummaryTable);
2020-07-28 23:09:34 +05:30
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
2021-06-08 01:23:25 +05:30
const createComponent = ({ state = {} } = {}) => {
2019-12-26 22:10:19 +05:30
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
});
2021-06-08 01:23:25 +05:30
wrapper = extendedWrapper(
shallowMount(TestReports, {
store,
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', () => {
2021-06-08 01:23:25 +05:30
it('should call fetchSummary when pipeline has test report', () => {
2020-07-28 23:09:34 +05:30
createComponent();
expect(actionSpies.fetchSummary).toHaveBeenCalled();
});
});
2019-12-26 22:10:19 +05:30
describe('when loading', () => {
2021-06-08 01:23:25 +05:30
beforeEach(() => createComponent({ state: { isLoading: true } }));
2019-12-26 22:10:19 +05:30
it('shows the loading spinner', () => {
2021-06-08 01:23:25 +05:30
expect(emptyState().exists()).toBe(false);
2019-12-26 22:10:19 +05:30
expect(testsDetail().exists()).toBe(false);
expect(loadingSpinner().exists()).toBe(true);
});
});
describe('when the api returns no data', () => {
2021-06-08 01:23:25 +05:30
it('displays empty state component', () => {
createComponent({ state: { testReports: {} } });
2019-12-26 22:10:19 +05:30
2021-06-08 01:23:25 +05:30
expect(emptyState().exists()).toBe(true);
2019-12-26 22:10:19 +05:30
});
});
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-11-24 15:15:51 +05:30
it('shows tests details', () => {
expect(testsDetail().exists()).toBe(true);
});
2019-12-26 22:10:19 +05:30
});
2020-07-28 23:09:34 +05:30
describe('when a suite is clicked', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
2021-06-08 01:23:25 +05:30
createComponent({ state: { hasFullReport: true } });
2020-10-24 23:57:45 +05:30
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(() => {
2021-06-08 01:23:25 +05:30
createComponent({ state: { selectedSuiteIndex: 0 } });
2020-07-28 23:09:34 +05:30
testSummary().vm.$emit('on-back-click');
});
it('should call removeSelectedSuiteIndex', () => {
expect(actionSpies.removeSelectedSuiteIndex).toHaveBeenCalled();
});
});
2019-12-26 22:10:19 +05:30
});