Commit ea151df8 authored by Kushal Pandya's avatar Kushal Pandya

Fix rendering logic to correctly find Epic parents

Fixes a bug where Epics are not included in the list when
their parents are not present in the list (which is a valid
usecase).
parent c60bc50c
...@@ -66,21 +66,10 @@ export default { ...@@ -66,21 +66,10 @@ export default {
left: `${this.offsetLeft}px`, left: `${this.offsetLeft}px`,
}; };
}, },
findEpicsMatchingFilter() { epicsWithAssociatedParents() {
return this.epics.reduce((acc, epic) => { return this.epics.filter(
if (!epic.hasParent || (epic.hasParent && this.epicIds.indexOf(epic.parent.id) < 0)) { epic => !epic.hasParent || (epic.hasParent && this.epicIds.indexOf(epic.parent.id) < 0),
acc.push(epic); );
}
return acc;
}, []);
},
findParentEpics() {
return this.epics.reduce((acc, epic) => {
if (!epic.hasParent) {
acc.push(epic);
}
return acc;
}, []);
}, },
displayedEpics() { displayedEpics() {
// If roadmap is accessed from epic, return all epics // If roadmap is accessed from epic, return all epics
...@@ -88,8 +77,8 @@ export default { ...@@ -88,8 +77,8 @@ export default {
return this.epics; return this.epics;
} }
// If a search is being performed, add child as parent if parent doesn't match the search // Return epics with correct parent associations.
return this.hasFiltersApplied ? this.findEpicsMatchingFilter : this.findParentEpics; return this.epicsWithAssociatedParents;
}, },
}, },
mounted() { mounted() {
......
...@@ -15,6 +15,7 @@ import { ...@@ -15,6 +15,7 @@ import {
mockTimeframeInitialDate, mockTimeframeInitialDate,
mockGroupId, mockGroupId,
rawEpics, rawEpics,
mockEpicsWithParents,
mockSortedBy, mockSortedBy,
basePath, basePath,
epicsPath, epicsPath,
...@@ -119,20 +120,25 @@ describe('EpicsListSectionComponent', () => { ...@@ -119,20 +120,25 @@ describe('EpicsListSectionComponent', () => {
}); });
}); });
describe('epicsWithAssociatedParents', () => {
it('should return epics which contain parent associations', () => {
wrapper = createComponent({
epics: mockEpicsWithParents,
});
expect(wrapper.vm.epicsWithAssociatedParents).toEqual(mockEpicsWithParents);
wrapper.destroy();
});
});
describe('displayedEpics', () => { describe('displayedEpics', () => {
beforeAll(() => { beforeAll(() => {
store.state.epicIds = ['1', '2', '3']; store.state.epicIds = ['1', '2', '3'];
}); });
it('returns findParentEpics method by default', () => { it('returns findParentEpics method by default', () => {
expect(wrapper.vm.displayedEpics).toEqual(wrapper.vm.findParentEpics); expect(wrapper.vm.displayedEpics).toEqual(wrapper.vm.epicsWithAssociatedParents);
});
it('returns findEpicsMatchingFilter method if filtered is applied', () => {
wrapper.setProps({
hasFiltersApplied: true,
});
expect(wrapper.vm.displayedEpics).toEqual(wrapper.vm.findEpicsMatchingFilter);
}); });
it('returns all epics if epicIid is specified', () => { it('returns all epics if epicIid is specified', () => {
......
...@@ -621,3 +621,34 @@ export const mockGroupMilestonesQueryResponse = { ...@@ -621,3 +621,34 @@ export const mockGroupMilestonesQueryResponse = {
}, },
}, },
}; };
export const mockEpicsWithParents = [
{
id: 'gid://gitlab-org/subgroup/Epic/1',
hasParent: true,
parent: {
id: 'gid://gitlab-org/Epic/1',
},
},
{
id: 'gid://gitlab-org/subgroup/Epic/2',
hasParent: true,
parent: {
id: 'gid://gitlab-org/subgroup/Epic/1',
},
},
{
id: 'gid://gitlab-org/subgroup/Epic/3',
hasParent: true,
parent: {
id: 'gid://gitlab-org/subgroup/Epic/1',
},
},
{
id: 'gid://gitlab-org/subgroup/Epic/4',
hasParent: true,
parent: {
id: 'gid://gitlab-org/subgroup/Epic/1',
},
},
];
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