Commit f5a42a3b authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch 'afontaine/fix-milestones-releases' into 'master'

Ensure Milestones Are Displayed With Few Results

See merge request gitlab-org/gitlab!69507
parents aacec5de 146c481d
...@@ -38,7 +38,7 @@ export default { ...@@ -38,7 +38,7 @@ export default {
[types.RECEIVE_PROJECT_MILESTONES_SUCCESS](state, response) { [types.RECEIVE_PROJECT_MILESTONES_SUCCESS](state, response) {
state.matches.projectMilestones = { state.matches.projectMilestones = {
list: response.data.map(({ title }) => ({ title })), list: response.data.map(({ title }) => ({ title })),
totalCount: parseInt(response.headers['x-total'], 10), totalCount: parseInt(response.headers['x-total'], 10) || response.data.length,
error: null, error: null,
}; };
}, },
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
[types.RECEIVE_GROUP_MILESTONES_SUCCESS](state, response) { [types.RECEIVE_GROUP_MILESTONES_SUCCESS](state, response) {
state.matches.groupMilestones = { state.matches.groupMilestones = {
list: response.data.map(({ title }) => ({ title })), list: response.data.map(({ title }) => ({ title })),
totalCount: parseInt(response.headers['x-total'], 10), totalCount: parseInt(response.headers['x-total'], 10) || response.data.length,
error: null, error: null,
}; };
}, },
......
...@@ -174,6 +174,35 @@ describe('Milestones combobox Vuex store mutations', () => { ...@@ -174,6 +174,35 @@ describe('Milestones combobox Vuex store mutations', () => {
}); });
}); });
it('falls back to the length of list if pagination headers are missing', () => {
const response = {
data: [
{
title: 'v0.1',
},
{
title: 'v0.2',
},
],
headers: {},
};
mutations[types.RECEIVE_PROJECT_MILESTONES_SUCCESS](state, response);
expect(state.matches.projectMilestones).toEqual({
list: [
{
title: 'v0.1',
},
{
title: 'v0.2',
},
],
error: null,
totalCount: 2,
});
});
describe(`${types.RECEIVE_PROJECT_MILESTONES_ERROR}`, () => { describe(`${types.RECEIVE_PROJECT_MILESTONES_ERROR}`, () => {
it('updates state.matches.projectMilestones to an empty state with the error object', () => { it('updates state.matches.projectMilestones to an empty state with the error object', () => {
const error = new Error('Something went wrong!'); const error = new Error('Something went wrong!');
...@@ -227,6 +256,35 @@ describe('Milestones combobox Vuex store mutations', () => { ...@@ -227,6 +256,35 @@ describe('Milestones combobox Vuex store mutations', () => {
}); });
}); });
it('falls back to the length of data received if pagination headers are missing', () => {
const response = {
data: [
{
title: 'group-0.1',
},
{
title: 'group-0.2',
},
],
headers: {},
};
mutations[types.RECEIVE_GROUP_MILESTONES_SUCCESS](state, response);
expect(state.matches.groupMilestones).toEqual({
list: [
{
title: 'group-0.1',
},
{
title: 'group-0.2',
},
],
error: null,
totalCount: 2,
});
});
describe(`${types.RECEIVE_GROUP_MILESTONES_ERROR}`, () => { describe(`${types.RECEIVE_GROUP_MILESTONES_ERROR}`, () => {
it('updates state.matches.groupMilestones to an empty state with the error object', () => { it('updates state.matches.groupMilestones to an empty state with the error object', () => {
const error = new Error('Something went wrong!'); const error = new Error('Something went wrong!');
......
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