Commit 2ba2ca16 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'mw-productivity-analytics-reset-mr-table-page-on-chart-click' into 'master'

Productivity Analytics: Reset MR table page on main chart click

See merge request gitlab-org/gitlab!17136
parents 5d7b1892 39c1be47
...@@ -73,6 +73,9 @@ export default { ...@@ -73,6 +73,9 @@ export default {
showMergeRequestTable() { showMergeRequestTable() {
return !this.isLoadingTable && this.mergeRequests.length; return !this.isLoadingTable && this.mergeRequests.length;
}, },
showMergeRequestTableNoData() {
return !this.isLoadingTable && !this.mergeRequests.length;
},
showSecondaryCharts() { showSecondaryCharts() {
return !this.chartLoading(chartKeys.main) && this.chartHasData(chartKeys.main); return !this.chartLoading(chartKeys.main) && this.chartHasData(chartKeys.main);
}, },
...@@ -93,6 +96,8 @@ export default { ...@@ -93,6 +96,8 @@ export default {
onMainChartItemClicked({ params }) { onMainChartItemClicked({ params }) {
const itemValue = params.data.value[0]; const itemValue = params.data.value[0];
this.chartItemClicked({ chartKey: this.chartKeys.main, item: itemValue }); this.chartItemClicked({ chartKey: this.chartKeys.main, item: itemValue });
// let's reset the page on the MR table
this.setMergeRequestsPage(0);
}, },
getColumnChartOption(chartKey) { getColumnChartOption(chartKey) {
return { return {
...@@ -344,7 +349,7 @@ export default { ...@@ -344,7 +349,7 @@ export default {
@columnMetricChange="setColumnMetric" @columnMetricChange="setColumnMetric"
@pageChange="setMergeRequestsPage" @pageChange="setMergeRequestsPage"
/> />
<div v-else class="bs-callout bs-callout-info"> <div v-if="showMergeRequestTableNoData" class="js-no-data bs-callout bs-callout-info">
{{ __('There is no data available. Please change your selection.') }} {{ __('There is no data available. Please change your selection.') }}
</div> </div>
</div> </div>
......
...@@ -23,14 +23,13 @@ describe('ProductivityApp component', () => { ...@@ -23,14 +23,13 @@ describe('ProductivityApp component', () => {
const actionSpies = { const actionSpies = {
setMetricType: jest.fn(), setMetricType: jest.fn(),
chartItemClicked: jest.fn(),
setSortField: jest.fn(), setSortField: jest.fn(),
setMergeRequestsPage: jest.fn(), setMergeRequestsPage: jest.fn(),
toggleSortOrder: jest.fn(), toggleSortOrder: jest.fn(),
setColumnMetric: jest.fn(), setColumnMetric: jest.fn(),
}; };
const onMainChartItemClickedMock = jest.fn();
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(localVue.extend(ProductivityApp), { wrapper = shallowMount(localVue.extend(ProductivityApp), {
localVue, localVue,
...@@ -38,10 +37,11 @@ describe('ProductivityApp component', () => { ...@@ -38,10 +37,11 @@ describe('ProductivityApp component', () => {
sync: false, sync: false,
propsData, propsData,
methods: { methods: {
onMainChartItemClicked: onMainChartItemClickedMock,
...actionSpies, ...actionSpies,
}, },
}); });
jest.spyOn(store, 'dispatch').mockImplementation();
}); });
afterEach(() => { afterEach(() => {
...@@ -128,7 +128,8 @@ describe('ProductivityApp component', () => { ...@@ -128,7 +128,8 @@ describe('ProductivityApp component', () => {
).toBe(true); ).toBe(true);
}); });
it('calls onMainChartItemClicked when chartItemClicked is emitted on the column chart ', () => { describe('when an item on the chart is clicked', () => {
beforeEach(() => {
const data = { const data = {
chart: null, chart: null,
params: { params: {
...@@ -141,8 +142,18 @@ describe('ProductivityApp component', () => { ...@@ -141,8 +142,18 @@ describe('ProductivityApp component', () => {
findTimeToMergeSection() findTimeToMergeSection()
.find(GlColumnChart) .find(GlColumnChart)
.vm.$emit('chartItemClicked', data); .vm.$emit('chartItemClicked', data);
});
expect(onMainChartItemClickedMock).toHaveBeenCalledWith(data); it('dispatches chartItemClicked action', () => {
expect(actionSpies.chartItemClicked).toHaveBeenCalledWith({
chartKey: chartKeys.main,
item: 0,
});
});
it('dispatches setMergeRequestsPage action', () => {
expect(actionSpies.setMergeRequestsPage).toHaveBeenCalledWith(0);
});
}); });
}); });
...@@ -312,7 +323,7 @@ describe('ProductivityApp component', () => { ...@@ -312,7 +323,7 @@ describe('ProductivityApp component', () => {
store.state.charts.charts[chartKeys.main].data = { 1: 2, 2: 3 }; store.state.charts.charts[chartKeys.main].data = { 1: 2, 2: 3 };
}); });
describe('when isLoadingTable is true', () => { describe('when table is loading', () => {
beforeEach(() => { beforeEach(() => {
store.state.table.isLoadingTable = true; store.state.table.isLoadingTable = true;
}); });
...@@ -326,9 +337,13 @@ describe('ProductivityApp component', () => { ...@@ -326,9 +337,13 @@ describe('ProductivityApp component', () => {
}); });
}); });
describe('when isLoadingTable is false', () => { describe('when table finished loading', () => {
beforeEach(() => { beforeEach(() => {
store.state.table.isLoadingTable = false; store.state.table.isLoadingTable = false;
});
describe('and the table has data', () => {
beforeEach(() => {
store.state.table.mergeRequests = [{ id: 1, title: 'This is a test MR' }]; store.state.table.mergeRequests = [{ id: 1, title: 'This is a test MR' }];
}); });
...@@ -336,6 +351,14 @@ describe('ProductivityApp component', () => { ...@@ -336,6 +351,14 @@ describe('ProductivityApp component', () => {
expect(findMrTable().exists()).toBe(true); expect(findMrTable().exists()).toBe(true);
}); });
it('doesn’t render a "no data" message', () => {
expect(
findMrTableSection()
.find('.js-no-data')
.exists(),
).toBe(false);
});
it('should change the column metric', () => { it('should change the column metric', () => {
findMrTable().vm.$emit('columnMetricChange', 'time_to_first_comment'); findMrTable().vm.$emit('columnMetricChange', 'time_to_first_comment');
expect(actionSpies.setColumnMetric).toHaveBeenCalledWith('time_to_first_comment'); expect(actionSpies.setColumnMetric).toHaveBeenCalledWith('time_to_first_comment');
...@@ -374,6 +397,30 @@ describe('ProductivityApp component', () => { ...@@ -374,6 +397,30 @@ describe('ProductivityApp component', () => {
}); });
}); });
}); });
describe("and the table doesn't have any data", () => {
beforeEach(() => {
store.state.table.mergeRequests = [];
});
it('renders a "no data" message', () => {
expect(
findMrTableSection()
.find('.js-no-data')
.exists(),
).toBe(true);
});
it('doesn`t render the MR table', () => {
expect(findMrTable().exists()).not.toBe(true);
});
it('doesn`t render the sort dropdown and button', () => {
expect(findSortFieldDropdown().exists()).not.toBe(true);
expect(findSortOrderToggle().exists()).not.toBe(true);
});
});
});
}); });
}); });
}); });
......
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