Mirror of https://github.com/roostorg/coop github.com/roostorg/coop
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 557ff54b2b435e5f1e789c6a8a4e1bebf2d7deb6 57 lines 2.2 kB view raw
1import { filterNullOrUndefined, moveArrayElement } from './collections.js'; 2 3describe('Collections utils functions', () => { 4 describe('Filter null and undefined', () => { 5 test('should leave array without nulls and undefineds unchanged', () => { 6 const array = [1, 2, 3, 4]; 7 expect(filterNullOrUndefined(array)).toEqual(array); 8 }); 9 test('should filter null', () => { 10 const array = [1, 2, null, 3, 4]; 11 expect(filterNullOrUndefined(array)).toEqual([1, 2, 3, 4]); 12 }); 13 test('should filter undefined', () => { 14 const array = [1, 2, undefined, 3, 4]; 15 expect(filterNullOrUndefined(array)).toEqual([1, 2, 3, 4]); 16 }); 17 test('should filter null and undefined', () => { 18 const array = [1, 2, null, 3, undefined, 4]; 19 expect(filterNullOrUndefined(array)).toEqual([1, 2, 3, 4]); 20 }); 21 }); 22 23 describe('Move array element', () => { 24 test('Do nothing if fromIndex equals toIndex', () => { 25 const array = [1, 2, 3, 4]; 26 expect(moveArrayElement(array, 1, 1)).toEqual(array); 27 }); 28 test('Do nothing if fromIndex < 0', () => { 29 const array = [1, 2, 3, 4]; 30 expect(moveArrayElement(array, -1, 1)).toEqual(array); 31 }); 32 test('Do nothing if toIndex < 0>', () => { 33 const array = [1, 2, 3, 4]; 34 expect(moveArrayElement(array, 1, -1)).toEqual(array); 35 }); 36 test('Do nothing if fromIndex is out of bounds', () => { 37 const array = [1, 2, 3, 4]; 38 expect(moveArrayElement(array, 10, 1)).toEqual(array); 39 }); 40 test('Do nothing if toIndex is out of bounds', () => { 41 const array = [1, 2, 3, 4]; 42 expect(moveArrayElement(array, 1, 10)).toEqual(array); 43 }); 44 test('Move element from index 0 to index 1', () => { 45 const array = [1, 2, 3, 4]; 46 expect(moveArrayElement(array, 0, 1)).toEqual([2, 1, 3, 4]); 47 }); 48 test('Move element from index 2 to index 1', () => { 49 const array = [1, 2, 3, 4]; 50 expect(moveArrayElement(array, 2, 1)).toEqual([1, 3, 2, 4]); 51 }); 52 test('Move element from index 2 to beginning of the array', () => { 53 const array = [1, 2, 3, 4]; 54 expect(moveArrayElement(array, 2, 0)).toEqual([3, 1, 2, 4]); 55 }); 56 }); 57});