Commit 5f145324 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '32359-fix-epics-tree-items-ordering' into 'master'

Fix sort ordering logic for Epics Tree

Closes #32359

See merge request gitlab-org/gitlab!17340
parents d2c1eb44 4f828ac4
...@@ -43,17 +43,17 @@ export default { ...@@ -43,17 +43,17 @@ export default {
(!isEpic && newIndex > currentItemIssuesBeginAtIndex) (!isEpic && newIndex > currentItemIssuesBeginAtIndex)
) { ) {
// We set `adjacentReferenceId` to the item ID that's _above_ the target items new position. // We set `adjacentReferenceId` to the item ID that's _above_ the target items new position.
// And since adjacent item is above, we set `relativePosition` to `above`. // And since adjacent item is above, we set `relativePosition` to `Before`.
adjacentReferenceId = children[newIndex - 1][idPropVal]; adjacentReferenceId = children[newIndex - 1][idPropVal];
relativePosition = relativePositions.After; relativePosition = relativePositions.Before;
} else { } else {
// We set `adjacentReferenceId` to the item ID that's on top of the list (either Epics or Issues) // We set `adjacentReferenceId` to the item ID that's on top of the list (either Epics or Issues)
// And since adjacent item is below, we set `relativePosition` to `below`. // And since adjacent item is below, we set `relativePosition` to `After`.
adjacentReferenceId = adjacentReferenceId =
children[isEpic ? currentItemEpicsBeginAtIndex : currentItemIssuesBeginAtIndex][ children[isEpic ? currentItemEpicsBeginAtIndex : currentItemIssuesBeginAtIndex][
idPropVal idPropVal
]; ];
relativePosition = relativePositions.Before; relativePosition = relativePositions.After;
} }
return { return {
......
...@@ -14,7 +14,7 @@ export const gqClient = createGqClient(); ...@@ -14,7 +14,7 @@ export const gqClient = createGqClient();
* @param {cbject} childA * @param {cbject} childA
* @param {object} childB * @param {object} childB
*/ */
export const sortChildren = (childA, childB) => childB.relativePosition - childA.relativePosition; export const sortChildren = (childA, childB) => childA.relativePosition - childB.relativePosition;
/** /**
* Returns formatted child item to include additional * Returns formatted child item to include additional
......
...@@ -12,6 +12,37 @@ jest.mock('~/lib/graphql', () => jest.fn()); ...@@ -12,6 +12,37 @@ jest.mock('~/lib/graphql', () => jest.fn());
describe('RelatedItemsTree', () => { describe('RelatedItemsTree', () => {
describe('epicUtils', () => { describe('epicUtils', () => {
describe('sortChildren', () => {
const paramA = {};
const paramB = {};
beforeEach(() => {
paramA.relativePosition = -1;
paramB.relativePosition = -1;
});
it('returns non-zero positive integer when paramA.relativePosition is greater than paramB.relativePosition', () => {
paramA.relativePosition = 10;
paramB.relativePosition = 5;
expect(epicUtils.sortChildren(paramA, paramB) > -1).toBe(true);
});
it('returns non-zero negative integer when paramA.relativePosition is smaller than paramB.relativePosition', () => {
paramA.relativePosition = 5;
paramB.relativePosition = 10;
expect(epicUtils.sortChildren(paramA, paramB) < 0).toBe(true);
});
it('returns zero when paramA.relativePosition is same as paramB.relativePosition', () => {
paramA.relativePosition = 5;
paramB.relativePosition = 5;
expect(epicUtils.sortChildren(paramA, paramB)).toBe(0);
});
});
describe('formatChildItem', () => { describe('formatChildItem', () => {
it('returns new object from provided item object with pathIdSeparator assigned', () => { it('returns new object from provided item object with pathIdSeparator assigned', () => {
const item = { const item = {
......
...@@ -109,7 +109,7 @@ describe('RelatedItemsTree', () => { ...@@ -109,7 +109,7 @@ describe('RelatedItemsTree', () => {
jasmine.objectContaining({ jasmine.objectContaining({
id: targetItem.id, id: targetItem.id,
adjacentReferenceId: mockEpic1.id, adjacentReferenceId: mockEpic1.id,
relativePosition: 'before', relativePosition: 'after',
}), }),
); );
}); });
...@@ -127,7 +127,7 @@ describe('RelatedItemsTree', () => { ...@@ -127,7 +127,7 @@ describe('RelatedItemsTree', () => {
jasmine.objectContaining({ jasmine.objectContaining({
id: targetItem.id, id: targetItem.id,
adjacentReferenceId: mockEpic1.id, adjacentReferenceId: mockEpic1.id,
relativePosition: 'after', relativePosition: 'before',
}), }),
); );
}); });
...@@ -145,7 +145,7 @@ describe('RelatedItemsTree', () => { ...@@ -145,7 +145,7 @@ describe('RelatedItemsTree', () => {
jasmine.objectContaining({ jasmine.objectContaining({
id: targetItem.epicIssueId, id: targetItem.epicIssueId,
adjacentReferenceId: mockIssue1.epicIssueId, adjacentReferenceId: mockIssue1.epicIssueId,
relativePosition: 'before', relativePosition: 'after',
}), }),
); );
}); });
...@@ -163,7 +163,7 @@ describe('RelatedItemsTree', () => { ...@@ -163,7 +163,7 @@ describe('RelatedItemsTree', () => {
jasmine.objectContaining({ jasmine.objectContaining({
id: targetItem.epicIssueId, id: targetItem.epicIssueId,
adjacentReferenceId: mockIssue1.epicIssueId, adjacentReferenceId: mockIssue1.epicIssueId,
relativePosition: 'after', relativePosition: 'before',
}), }),
); );
}); });
......
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