refactor: order is single source of truth

This commit is contained in:
Carlos Valente
2025-05-26 21:59:03 +02:00
committed by Carlos Valente
parent e7cfb7d9d9
commit 2793aadea0
4 changed files with 60 additions and 52 deletions
+7 -1
View File
@@ -88,12 +88,18 @@ describe('deleteAtIndex', () => {
});
describe('reorderArray', () => {
it('should reorder an item in the array', () => {
it('should reorder an item in the array (up)', () => {
const array = ['a', 'b', 'c', 'd'];
const result = reorderArray(array, 1, 3);
expect(result).toEqual(['a', 'c', 'd', 'b']);
});
it('should reorder an item in the array (down)', () => {
const array = ['a', 'b', 'c', 'd'];
const result = reorderArray(array, 3, 1);
expect(result).toEqual(['a', 'd', 'b', 'c']);
});
it('should return the original array if fromIndex and toIndex are the same', () => {
const array = ['a', 'b', 'c'];
const result = reorderArray(array, 1, 1);