Commit c39a4091 authored by Scott Hampton's avatar Scott Hampton

Move fetchFullReport to vue app

Instead of fetching the full report from the
select suite index action, we should do it
in the tests_reports app. This will make the
function more clean, and ensure the app
is in charge of all actions being called.
parent 15e74547
...@@ -14,7 +14,7 @@ export default { ...@@ -14,7 +14,7 @@ export default {
TestSummaryTable, TestSummaryTable,
}, },
computed: { computed: {
...mapState(['isLoading', 'selectedSuiteIndex', 'testReports']), ...mapState(['hasFullReport', 'isLoading', 'selectedSuiteIndex', 'testReports']),
...mapGetters(['getSelectedSuite']), ...mapGetters(['getSelectedSuite']),
showSuite() { showSuite() {
return this.selectedSuiteIndex !== null; return this.selectedSuiteIndex !== null;
...@@ -28,12 +28,22 @@ export default { ...@@ -28,12 +28,22 @@ export default {
this.fetchSummary(); this.fetchSummary();
}, },
methods: { methods: {
...mapActions(['fetchSummary', 'setSelectedSuiteIndex', 'removeSelectedSuiteIndex']), ...mapActions([
'fetchFullReport',
'fetchSummary',
'setSelectedSuiteIndex',
'removeSelectedSuiteIndex',
]),
summaryBackClick() { summaryBackClick() {
this.removeSelectedSuiteIndex(); this.removeSelectedSuiteIndex();
}, },
summaryTableRowClick(index) { summaryTableRowClick(index) {
this.setSelectedSuiteIndex(index); this.setSelectedSuiteIndex(index);
// Fetch the full report when the user clicks to see more details
if (!this.hasFullReport) {
this.fetchFullReport();
}
}, },
beforeEnterTransition() { beforeEnterTransition() {
document.documentElement.style.overflowX = 'hidden'; document.documentElement.style.overflowX = 'hidden';
......
...@@ -20,9 +20,7 @@ export const fetchSummary = ({ state, commit, dispatch }) => { ...@@ -20,9 +20,7 @@ export const fetchSummary = ({ state, commit, dispatch }) => {
// Set the tab counter badge to total_count // Set the tab counter badge to total_count
// This is temporary until we can server-side render that count number // This is temporary until we can server-side render that count number
// (see https://gitlab.com/gitlab-org/gitlab/-/issues/223134) // (see https://gitlab.com/gitlab-org/gitlab/-/issues/223134)
if (data.total_count !== undefined) { document.querySelector('.js-test-report-badge-counter').innerHTML = data.total_count || 0;
document.querySelector('.js-test-report-badge-counter').innerHTML = data.total_count;
}
} }
}) })
.catch(() => { .catch(() => {
...@@ -49,15 +47,8 @@ export const fetchFullReport = ({ state, commit, dispatch }) => { ...@@ -49,15 +47,8 @@ export const fetchFullReport = ({ state, commit, dispatch }) => {
}); });
}; };
export const setSelectedSuiteIndex = ({ state, commit, dispatch }, data) => { export const setSelectedSuiteIndex = ({ commit }, data) =>
commit(types.SET_SELECTED_SUITE_INDEX, data); commit(types.SET_SELECTED_SUITE_INDEX, data);
// Fetch the full report when the user clicks to see more details
if (!state.hasFullReport) {
dispatch('fetchFullReport');
}
};
export const removeSelectedSuiteIndex = ({ commit }) => export const removeSelectedSuiteIndex = ({ commit }) =>
commit(types.SET_SELECTED_SUITE_INDEX, null); commit(types.SET_SELECTED_SUITE_INDEX, null);
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_LOADING); export const toggleLoading = ({ commit }) => commit(types.TOGGLE_LOADING);
......
...@@ -134,23 +134,9 @@ describe('Actions TestReports Store', () => { ...@@ -134,23 +134,9 @@ describe('Actions TestReports Store', () => {
}); });
describe('set selected suite index', () => { describe('set selected suite index', () => {
const selectedSuiteIndex = 0;
describe('when state does not have full report', () => {
it('sets selectedSuiteIndex', done => { it('sets selectedSuiteIndex', done => {
testAction( const selectedSuiteIndex = 0;
actions.setSelectedSuiteIndex,
selectedSuiteIndex,
state,
[{ type: types.SET_SELECTED_SUITE_INDEX, payload: selectedSuiteIndex }],
[{ type: 'fetchFullReport' }],
done,
);
});
});
describe('when state has full report', () => {
it('sets selectedSuiteIndex', done => {
testAction( testAction(
actions.setSelectedSuiteIndex, actions.setSelectedSuiteIndex,
selectedSuiteIndex, selectedSuiteIndex,
...@@ -161,7 +147,6 @@ describe('Actions TestReports Store', () => { ...@@ -161,7 +147,6 @@ describe('Actions TestReports Store', () => {
); );
}); });
}); });
});
describe('remove selected suite index', () => { describe('remove selected suite index', () => {
it('sets selectedSuiteIndex to null', done => { it('sets selectedSuiteIndex to null', done => {
......
...@@ -2,7 +2,8 @@ import Vuex from 'vuex'; ...@@ -2,7 +2,8 @@ import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { getJSONFixture } from 'helpers/fixtures'; import { getJSONFixture } from 'helpers/fixtures';
import TestReports from '~/pipelines/components/test_reports/test_reports.vue'; 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'; import * as getters from '~/pipelines/stores/test_reports/getters';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -17,19 +18,25 @@ describe('Test reports app', () => { ...@@ -17,19 +18,25 @@ describe('Test reports app', () => {
const loadingSpinner = () => wrapper.find('.js-loading-spinner'); const loadingSpinner = () => wrapper.find('.js-loading-spinner');
const testsDetail = () => wrapper.find('.js-tests-detail'); const testsDetail = () => wrapper.find('.js-tests-detail');
const noTestsToShow = () => wrapper.find('.js-no-tests-to-show'); 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 = {}) => { const createComponent = (state = {}) => {
store = new Vuex.Store({ store = new Vuex.Store({
state: { state: {
isLoading: false, isLoading: false,
selectedSuite: {}, selectedSuiteIndex: null,
testReports, testReports,
...state, ...state,
}, },
actions: { actions: actionSpies,
...actions,
fetchSummary: () => {},
},
getters, getters,
}); });
...@@ -43,6 +50,16 @@ describe('Test reports app', () => { ...@@ -43,6 +50,16 @@ describe('Test reports app', () => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('when component is created', () => {
beforeEach(() => {
createComponent();
});
it('should call fetchSummary', () => {
expect(actionSpies.fetchSummary).toHaveBeenCalled();
});
});
describe('when loading', () => { describe('when loading', () => {
beforeEach(() => createComponent({ isLoading: true })); beforeEach(() => createComponent({ isLoading: true }));
...@@ -72,4 +89,41 @@ describe('Test reports app', () => { ...@@ -72,4 +89,41 @@ describe('Test reports app', () => {
expect(wrapper.vm.showTests).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();
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment